雪碧框架animationCocos2d 3.0

我一直在尝试做一个animation精灵,他们是很多教程,但他们都是为Cocos2d 2.x. 我的精灵表名为flappbird.png,.plist名为flappbird.plist

我有这个代码,但每次我开始它只是崩溃的场景,这是在我的init方法

// ----------------------------------------------------------------------- _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.0中的spritesheetanimationsprite

确保在代码的开头添加#import "CCAnimation.h"

在self.userInteractionEnabled = YES后添加精灵表单。 在初始化

 [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"your.plist"]; 

不要将所有这些添加到精灵的位置

 //The sprite animation NSMutableArray *walkAnimFrames = [NSMutableArray array]; for(int i = 1; i <= 7; ++i) { [walkAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: [NSString stringWithFormat:@"monster%d.png", i]]]; } CCAnimation *walkAnim = [CCAnimation animationWithSpriteFrames:walkAnimFrames delay:0.1f]; //Speed in which the frames will go at //Adding png to sprite monstertest = [CCSprite spriteWithImageNamed:@"monster1.png"]; //Positioning the sprite monstertest.position = ccp(self.contentSize.width/2,self.contentSize.height/2); //Repeating the sprite animation CCActionAnimate *animationAction = [CCActionAnimate actionWithAnimation:walkAnim]; CCActionRepeatForever *repeatingAnimation = [CCActionRepeatForever actionWithAction:animationAction]; //Animation continuously repeating [monstertest runAction:repeatingAnimation]; //Adding the Sprite to the Scene [self addChild:monstertest]; 

希望这有助于某人:D干杯