cocos2d-x动画循环播放



动画从A点移动到b点,在移动中,动画需要循环播放。例如,一个项目符号移动到一个点,这个项目符号是一个应该循环播放的动画。

CCSequence::create(
  CCSpawn::createWithTwoActions(
    CCTargetedAction::create(sprite, CCMoveTo::create(3.0f, point_a)), 
    CCTargetedAction::create(sprite, CCRepeatForever::create(CCAnimate::create(animation)))
),0);

但CCRepeatForever不可能是动作序列的一员。那么该怎么做呢?我使用序列是因为还有其他操作要排队(上面省略)

您不需要为此使用ccspawn。。norccsequence只是在对象上分别运行这两个操作。

CCSprite *newSprite=CCSprite::create("imageName");
CCAnimation *animation=CCAnimation::create();
//..some code to add frames to this animation object..
//to repeat for indefinite time you could setLoops to -1 or use CCRepeatForever class    //like this..
//1:
animation->setLoops(-1);
newSprite->runAction(CCAnimate:create(animation));
//or..
//2:
newSprite->runAction(CCRepeatForever:create(CCAnimate:create(animation)));
//now to translate this sprite simultaneously use this.
newSprite->runAction(CCMoveTo::create(3.0,point_a));

最新更新