zoukankan      html  css  js  c++  java
  • CCFollow和ActionCallFunc

    CCFollow动作,可以让一个节点跟随另一个节点做位移。
    CCFollow经常用来设置layer跟随sprite,可以实现类似摄像机跟拍的效果
    效果是精灵在地图上移动,地图也会跟着移动,但是精灵仍然是在整个界面的中心位置
    CCSize s = CCDirector::sharedDirector()->getWinSize();
            pSprite->setPosition(ccp(-200, s.height / 2));
            CCActionInterval* move      = CCMoveBy::create(2, ccp(s.width * 3, 0));
            CCActionInterval* move_back = move->reverse();
            CCFiniteTimeAction* seq       = CCSequence::create(move, move_back, NULL);
            CCAction* rep               = CCRepeatForever::create((CCActionInterval*)seq);
    
            pSprite->runAction(rep);
    
            this->runAction(CCFollow::create(pSprite, CCRectMake(0, 0, s.width * 2 - 100, s.height)));

    //三个动作都绑定一个函数,三个动作同时执行,执行完后响应函数

    void ActionCallFunc::onEnter()
    {
        ActionsDemo::onEnter();
    
        centerSprites(3);
    
        CCFiniteTimeAction*  action = CCSequence::create(
            CCMoveBy::create(2, ccp(200,0)),
            CCCallFunc::create(this, callfunc_selector(ActionCallFunc::callback1)), 
            NULL);
    
        CCFiniteTimeAction*  action2 = CCSequence::create(
            CCScaleBy::create(2 ,  2),
            CCFadeOut::create(2),
            CCCallFuncN::create(this, callfuncN_selector(ActionSequence2::callback2)), 
            NULL);
    
        CCFiniteTimeAction*  action3 = CCSequence::create(
            CCRotateBy::create(3 , 360),
            CCFadeOut::create(2),
            CCCallFuncND::create(this, callfuncND_selector(ActionSequence2::callback3), (void*)0xbebabeba), 
            NULL);
    
        m_grossini->runAction(action);
        m_tamara->runAction(action2);
        m_kathia->runAction(action3);
    }
    
    
    void ActionCallFunc::callback1()
    {
        CCSize s = CCDirector::sharedDirector()->getWinSize();
        CCLabelTTF *label = CCLabelTTF::create("callback 1 called", "Marker Felt", 16);
        label->setPosition(ccp( s.width/4*1,s.height/2));
    
        addChild(label);
    }
    
    void ActionCallFunc::callback2(CCNode* pSender)
    {
        CCSize s = CCDirector::sharedDirector()->getWinSize();
        CCLabelTTF *label = CCLabelTTF::create("callback 2 called", "Marker Felt", 16);
        label->setPosition(ccp( s.width/4*2,s.height/2));
    
        addChild(label);
    }
    
    void ActionCallFunc::callback3(CCNode* pTarget, void* data)
    {
        CCSize s = CCDirector::sharedDirector()->getWinSize();
        CCLabelTTF *label = CCLabelTTF::create("callback 3 called", "Marker Felt", 16);
        label->setPosition(ccp( s.width/4*3,s.height/2));
        addChild(label);
    }
  • 相关阅读:
    (BFS 二叉树) leetcode 515. Find Largest Value in Each Tree Row
    (二叉树 BFS) leetcode513. Find Bottom Left Tree Value
    (二叉树 BFS DFS) leetcode 104. Maximum Depth of Binary Tree
    (二叉树 BFS DFS) leetcode 111. Minimum Depth of Binary Tree
    (BFS) leetcode 690. Employee Importance
    (BFS/DFS) leetcode 200. Number of Islands
    (最长回文子串 线性DP) 51nod 1088 最长回文子串
    (链表 importance) leetcode 2. Add Two Numbers
    (链表 set) leetcode 817. Linked List Components
    (链表 双指针) leetcode 142. Linked List Cycle II
  • 原文地址:https://www.cnblogs.com/newlist/p/3204032.html
Copyright © 2011-2022 走看看