• 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);
    }
  • 相关阅读:
    L3-001. 凑零钱(深度优先搜索)
    L2-008. 最长对称子串
    java里面求交集并集补集
    eclipse里面ctrl+T查看继承树,左边的这些绿色红色,F,S,C代表什么意思
    树的遍历(已知前序遍历中序遍历求后序遍历,或者已知后序中序求先序)
    L1-009. N个数求和
    面试题系列之---【MySql事务隔离级别】
    我爱java系列---【待定】
    我爱java系列之---【商城项目微服务鉴权代码实现(二)—JWT在项目中的应用案例】
    我爱java系列之---【JWT实现微服务鉴权(一)】
  • 原文地址:https://www.cnblogs.com/newlist/p/3204032.html
Copyright © 2020-2023  润新知