私はCCAnimationscocos2Dでの使用に不慣れで、解決するのに苦労した問題に遭遇しました。
私は基本的なプラットフォームゲームを作っていますが、プレイヤースプライトには、プレイヤーの状態に応じて実行する必要のあるさまざまなアニメーションがあります。
レイヤーのinitメソッドに次のコードがあります。
sprite = [CCSprite spriteWithSpriteFrameName:@"stand.png"];
standingSprites = [NSArray arrayWithObjects:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"stand.png"],
nil];
runningSprites = [NSArray arrayWithObjects:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"run1.png"],
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"run2.png"],
nil];
standingAnimation = [CCAnimation animationWithFrames:standingSprites delay:0.2f];
runningAnimation = [CCAnimation animationWithFrames:runningSprites delay:0.2f];
animationAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:standingAnimation]];
[sprite runAction:animationAction];
これは、2つのアニメーションのいずれかで期待どおりに機能します。しかし、standingAnimationプレイヤーが静止しているrunningAnimationときと、プレイヤーが走っているときに走りたいです。私はこれを次のように試みました:
-(void)walk {
if(!isWalking) {
isWalking = true;
[sprite stopAction:animationAction];
animationAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:runningAnimation]];
[sprite runAction:animationAction];
}
}
最後から2番目の行でプログラムがクラッシュし、EXC_BAD_ACCESS(参照時に0x0)が発生します。デバッガーをステップスルーwalkすると、関連するポインターがnullであるようには見えません。
スタックトレースから:
2012-06-03 10:59:59.907 ThirtyMinutes[9876:6403] *** Terminating app
due to uncaught exception 'NSInvalidArgumentException', reason:
'-[NSCTFontDescriptor frames]: unrecognized selector sent to instance
0x7f808d93e9f0'
0x7f808d93e9f0のアドレスですrunningAnimation。
- 私は何が間違っているのですか?
- これを行うためのより良い方法はありますか?
ありがとう!