我正在使用 Cocos2d 引擎,但遇到了一个奇怪的问题。
我有一个精灵。此外,我有 2 个该精灵的动画。我想在应用加载时播放一个动画,然后在调用 ccTouchevent 之后播放第二个动画。
walkAnim = [CCAnimation animation];
dropAnim = [CCAnimation animation];
for( int q=1;q<12;q++){
[walkAnim addFrameWithFilename: [NSString stringWithFormat:@"walkforward_%.2d.png", q]];
[dropAnim addFrameWithFilename: [NSString stringWithFormat:@"drop_%.2d.png", q]];
}
action = [CCAnimate actionWithAnimation:walkAnim];
action.duration = 2;
id act = [CCRepeatForever actionWithAction:action];
[sprite runAction:act];
所以,在这里我们看到了一个动画精灵。
[sprite stopAllActions]; //and here my torture begins
我尝试了许多创建动作的方法:
我尝试添加另一个 AnimateAction,尝试替换当前动画,但一切都导致崩溃。
[action setAnimation:dropAnim];
和
CCAnimate* animat = [[CCAnimate alloc]initWithDuration:30 animation:dropAnim restoreOriginalFrame:YES];
和
id action = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:dropAnim]];
[player1 runAction:action];
崩溃发生在 [CCAnimate actionWithAnimation:]
+(id) actionWithAnimation: (CCAnimation*)anim
{
return [[[self alloc] initWithAnimation:anim restoreOriginalFrame:YES] autorelease];
}
谢谢!
要从另一个方法启动一个动作,你必须保留这个动作
例如:[action retain];