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);
    }
  • 相关阅读:
    Class constructor FileManager cannot be invoked without 'new' in undefined (line undefined, column undefined)
    vscode插件
    面试题
    使用NPOI读取word表格里面的图片
    Postgresql安装过程记录
    .net Core 新增Area的步骤
    kendo grid上的模版示例
    unicode与string之间的转换
    使用yarn安装puppeteer失败的解决方案
    abp第一篇《框架的下载与mysql数据库的切换》
  • 原文地址:https://www.cnblogs.com/newlist/p/3204032.html
Copyright © 2011-2022 走看看