CCSpriteBatchNode と CCSprite を使用してアニメーション スプライトを作成しました。plist を使用してフレームを取得します。これがinit()に入れたコードです。
//================== making animating sprite
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile: @"framelist.plist"];
CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode
batchNodeWithFile:@"frames.png"];
[self addChild:spriteSheet];
NSMutableArray *walkAnimFrames = [NSMutableArray array];
for(int i = 1; i <= 2; ++i) {
[walkAnimFrames addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"frame%d.png", i]]];
}
CCAnimation *walkAnim = [CCAnimation
animationWithFrames:walkAnimFrames delay:0.1f];
//_frameSprite is CC Sprite
_frameSprite = [CCSprite spriteWithBatchNode:spriteSheet
rect:CGRectMake(0,0,48,48)];
_frameSprite.position = ccp(winSize.width + 60, winSize.height/2);
_flyAction = [CCRepeatForever actionWithAction:
[CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO]];
[_frameSprite runAction:_flyAction];
[spriteSheet addChild:_frameSprite];
スプライトの準備ができて画面上で実行されると、b2BodyDef を作成し、以下に示すように b2Body (つまり、frameBodyDef、frameBody) スプライトを割り当てます。
b2BodyDef frameBodyDef;
frameBodyDef.type = b2_staticBody;
frameBodyDef.position.Set(160/PTM_RATIO, 200/PTM_RATIO);
frameBodyDef.userData = _frameSprite;
frameBody = _world->CreateBody(&frameBodyDef);
本体を作成した後、ビルドして実行すると、次の行でプログラムがクラッシュします
frameBody = _world->CreateBody(&frameBodyDef);
BAD ACCESSと言っています。
これで私を親切に助けてください、なぜアニメーションスプライトを体に追加できないのですか???
ありがとうございました。