私のレイヤーのinitメソッドでアニメーションをプリロードしようとしています。画面に触れるとアニメーションが呼び出されます。私は画面に触れるとすぐにエラーメッセージが表示されずにアプリケーションがクラッシュし、プリロードされたアニメーションを呼び出すことと思われるようです。私はそれが画面に触れるたびにアニメーションを作成するために高価なようにこのようにしたいと思います - それはうまくいくようです。任意のヒントを大いに感謝します。Cocos2d:プリロードアニメーションがクラッシュする
サンプルコード:私のヘッダーで
:私の実装では
@interface Test : CCLayer {
NSMutableArray *wake;
CCSprite* ani;
CCAnimate *animate;
}
@end
:
-(id) init {
if((self=[super init])) {
// enable touches
self.isTouchEnabled = YES;
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"ani.plist" texture:[[CCTexture2D alloc] initWithImage:[UIImage imageNamed:@"ani.png"]]];
ani = [CCSprite spriteWithSpriteFrameName:@"ani1.png"]; //comes from .plist file
ani.anchorPoint=ccp(0,0);
ani.position = ccp(700,65);
[self addChild:ani z:30];
wake = [NSMutableArray array];
for(int i = 1; i <= 4; i++) {
[wake addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"ani%d.png",i]]];
}
animate = [CCAnimate actionWithAnimation:[CCAnimation animationWithFrames:wake delay:1.0f] restoreOriginalFrame:FALSE];
}
return self;
}
がタッチの取り扱い:Cocos2dで
- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
// run the animation
[ani runAction:animate];
}
だから、毎回アレイをロードする必要がありますか?確かにこれはパフォーマンスヒットになるはずですか? – Chev
ウェイクアレイをキャッシュすることができますが、アニメーションを呼び出す必要があります[CCAnimate actionWithAnimation:[CCAnimation animationWithFrames:wake delay:1.0f] restoreOriginalFrame:FALSE];毎回。 – badgerr