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);
    }
  • 相关阅读:
    推荐一个css抖动库
    八佰
    如何将猫猫监控放在博客上
    一个springboot注解不成功的小问题
    vue整理
    springboot整理
    国外服务器:org.xml.sax.SAXParseException
    记一次tomcat运行起来了但是项目没起来的问题
    一个狗血的mysql编码错误
    js中for(var key in o ){};用法小记
  • 原文地址:https://www.cnblogs.com/newlist/p/3204032.html
Copyright © 2011-2022 走看看