我一直在尝试做一个动画雪碧,他们是很多教程,但他们都是为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