GameCorder.net

このエントリーをはてなブックマークに追加

Do multiplex animation simultaneously in cocos2dx

Do multiplex animation simultaneously,We use Spawn class for animation.
Below example a trump animate simultaneously scale and move.
Let's see example.


// move to trumps position
Vec2 movePosition = Vec2(positionX,positionY);
MoveTo* moveTo = MoveTo::create(0.6, movePosition);
ScaleTo* scaleTo = ScaleTo::create(0.6,0.5);
// run two action
Spawn* spawn = Spawn::createWithTwoActions(moveTo,scaleTo);
// callback
auto callback = CallFunc::create(CC_CALLBACK_0(yourFunction,this));
// do sequence
Sequence* sequence = Sequence::create(spawn,callback,nullptr);
// run action in this case trump is Sprite class
trump->runAction(sequence);
	

Spawn class

In this example use createWithTowActions().
If want to many actions simultaneously
use simply create() function.


// move to trumps position
MoveTo* moveTo = MoveTo::create(MOVE_TRUMP_DELAY, movePosition);
ScaleTo* scaleTo = ScaleTo::create(MOVE_TRUMP_DELAY,1);
RotateTo* rotateTo = RotateTo::create(MOVE_TRUMP_DELAY,30);
// run with many animation
Spawn* spawn = Spawn::create(moveTo,scaleTo,rotateTo, NULL);
	

Lets' see the base code


Spawn* Spawn::create(FiniteTimeAction *action1, ...)
{
    va_list params;
    va_start(params, action1);

    Spawn *ret = Spawn::createWithVariableList(action1, params);

    va_end(params);
    
    return ret;
}

Spawn* Spawn::createWithVariableList(FiniteTimeAction *action1, va_list args)
{
    FiniteTimeAction *now;
    FiniteTimeAction *prev = action1;
    bool oneAction = true;

    while (action1)
    {
        now = va_arg(args, FiniteTimeAction*);
        if (now)
        {
            prev = createWithTwoActions(prev, now);
            oneAction = false;
        }
        else
        {
            // If only one action is added to Spawn, make up a Spawn by adding a simplest finite time action.
            if (oneAction)
            {
                prev = createWithTwoActions(prev, ExtraAction::create());
            }
            break;
        }
    }

    return ((Spawn*)prev);
}
	

I confirm version 3.15.1.