zoukankan      html  css  js  c++  java
  • action(三)

    CCSize boxSize = CCSizeMake(100.0f, 100.0f);
    
        CCLayerColor *box = CCLayerColor::create(ccc4(255, 255, 0, 255));
        box->setAnchorPoint(ccp(0, 0));
        box->setPosition(ccp(190, 110));
        box->setContentSize(boxSize);
    CCAnimation* animation = CCAnimation::create();
        for( int i=1;i<15;i++)
        {
            char szName[100] = {0};
            sprintf(szName, "Images/grossini_dance_%02d.png", i);
            animation->addSpriteFrameWithFileName(szName);
        }
        // should last 2.8 seconds. And there are 14 frames.
        animation->setDelayPerUnit(2.8f / 14.0f);
        animation->setRestoreOriginalFrame(true);
    
        CCAnimate* action = CCAnimate::create(animation);
        m_grossini->runAction(CCSequence::create(action, action->reverse(), NULL));

    CCFiniteTimeAction:有限次动作执行类,就是按时间顺序执行一系列动作,执行完后动作结束;CCSpeed:调整实体(节点)的执行速度;CCFollow:可以使节点跟随指定的另一个节点移动。下面我们主要来学习CCFiniteTimeAction,这个类在平常的开发中很常见。
    CCFiniteTimeAction又分为CCActionInstanse(瞬时动作的基类)和CCActionInterval(延时动作的基类)。CCActionInstanse:没什么特别,跟CCActionInterval主要区别是没有执行过程,动作瞬间就执行完成了;CCActionInterval:执行需要一定的时间(或者说一个过程)。

    void ActionSequence2::onEnter()
    {
        ActionsDemo::onEnter();
    
        alignSpritesLeft(1);
    
        m_grossini->setVisible(false);
    
        CCFiniteTimeAction*  action = CCSequence::create(
            CCPlace::create(ccp(200,200)),
            CCShow::create(),
            CCMoveBy::create(1, ccp(100,0)),
            CCCallFunc::create(this, callfunc_selector(ActionSequence2::callback1)),
            CCCallFuncN::create(this, callfuncN_selector(ActionSequence2::callback2)),
            CCCallFuncND::create(this, callfuncND_selector(ActionSequence2::callback3), (void*)0xbebabeba),
            NULL);
    
        m_grossini->runAction(action);
    }
    
    void ActionSequence2::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 ActionSequence2::callback2(CCNode* sender)
    {
        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 ActionSequence2::callback3(CCNode* sender, 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);
    }
    void ActionRepeatForever::onEnter()
    {
        ActionsDemo::onEnter();
    
        centerSprites(1);
    
        CCFiniteTimeAction*  action = CCSequence::create(
            CCDelayTime::create(1),
            CCCallFuncN::create( this, callfuncN_selector(ActionRepeatForever::repeatForever) ), 
            NULL);
    
        m_grossini->runAction(action);
    }
    
    void ActionRepeatForever::repeatForever(CCNode* pSender)
    {
        CCRepeatForever *repeat = CCRepeatForever::create( CCRotateBy::create(1.0f, 360) );
    
        pSender->runAction(repeat);
    }
  • 相关阅读:
    [紫书] 八数码问题(BFS)
    [紫书] 移动盒子(Boxes in a Line)
    [洛谷] P1803 凌乱的yyy / 线段覆盖 (贪心)
    [紫书] 破损的键盘(Broken Keyboard)
    bzoj3891
    poj3233
    bzoj1941
    Vijos2034
    poj2985
    Vijos1100
  • 原文地址:https://www.cnblogs.com/newlist/p/3203334.html
Copyright © 2011-2022 走看看