2013-11-21 113 views
3

動畫從點a移動到b,在動作中,動畫需要循環播放。例如,一個子彈移動到一個點,這個子彈是一個應該循環播放的動畫。cocos2d-x動畫在循環中播放

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

但是CCRepeatForever不能成爲動作序列的成員。 那麼該怎麼做呢?我使用的序列,因爲有其他行動排隊(上面省略)

+0

將兩個動作分開,一個用於移動另一個用於動畫,或者如果動畫只在移動後播放,則對另一個創建重複動畫的spawn進行排序 – LearnCocos2D

回答

5

你不需要使用ccspawn這個..也不是ccsequence只是在對象上分別運行兩個動作。

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));