我一直在嘗試做一個動畫雪碧,他們是很多教程,但他們都是爲Cocos2d 2.x.我的精靈表被命名爲flappbird.png和的.plist名爲flappbird.plist雪碧框架動畫Cocos2d 3.0
我有這樣的代碼,但每次我開始它只是崩潰的情景的時候,這是我初始化方法
// -----------------------------------------------------------------------
_player = [CCSprite spriteWithImageNamed:@"monster1.png"]; // comes from your .plist file
_player.position = ccp(self.contentSize.width/28,self.contentSize.height/2);
_player.physicsBody = [CCPhysicsBody bodyWithRect:(CGRect){CGPointZero, _player.contentSize} cornerRadius:0]; // 1
_player.physicsBody.collisionGroup = @"playerGroup";
_player.physicsBody.type = CCPhysicsBodyTypeStatic;
CCSpriteBatchNode *batchNode = [CCSpriteBatchNode batchNodeWithFile:@"monster1.png"];
[batchNode addChild:_player];
[self addChild:batchNode];
NSMutableArray *animFrames = [NSMutableArray array];
for(int i = 1; i < 5; i++)
{
CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"flapbird%d.png",i]];
[animFrames addObject:frame];
}
CCAnimation *animation = [CCAnimation animationWithSpriteFrames:animFrames delay:0.2f];
[_player runAction:[CCActionRepeatForever actionWithAction:[CCActionAnimate actionWithAnimation:animation]]];
[_physicsWorld addChild:_player];
// -----------------------------------------------------------------------
的可能重複[如何動畫在cocos2d 3.X CCSprite? ](http://stackoverflow.com/questions/21645953/how-to-animate-ccsprite-in-cocos2d-3x) –
看到我試圖執行這個問題的答案分鐘,但它會崩潰,什麼都不會發生 – Crazycriss
當它崩潰時它會告訴你什麼? – connor