0

Cocos2dエンジンを使用していますが、奇妙な問題に直面しました。

スプライトがあります。また、そのスプライト用に2つのアニメーションがあります。そして、アプリが読み込まれたときに1つのアニメーションを再生し、ccToucheventが呼び出された後に2番目のアニメーションを再生したいと思います。

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

クラッシュは[CCAnimateactionWithAnimation:]にあります

+(id) actionWithAnimation: (CCAnimation*)anim
{    
    return [[[self alloc] initWithAnimation:anim restoreOriginalFrame:YES] autorelease];
}

ありがとう!

別のメソッドからアクションを起動するには、アクションを保持する必要があります
。例:[action hold];

4

1 に答える 1

0

別のメソッドからアクションを起動するには、アクションを保持する必要があります
。例:[action hold]; そしてそれを解放することを忘れないでください

-(void)create{
    for( int q=1;q<12;q++){
        [playerWalkAnim addFrameWithFilename: [NSString stringWithFormat:@"walkforward_%.2d.png", q]];
    }
    playerAction = [CCAnimate actionWithAnimation:playerWalkAnim];
    playerAction.duration = 2;

    [playerAction retain];
}

-(void)launch{
    [player1 runAction:playerAction];
}
于 2011-03-31T09:43:15.527 に答える