![]()
我有这个代码,但每次我启动它只是崩溃,这是在我的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中使用Spritesheet动画精灵 确保在代码的开头添加#import“CCAnimation.h”
另外在self.userInteractionEnabled = YES之后添加精灵表;在init中
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithfile:@"your.pList"];
没有添加精灵所在的所有这些
//The sprite animationNSMutableArray *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 spritemonstertest = [CCSprite spriteWithImagenamed:@"monster1.png"];//positioning the spritemonstertest.position = ccp(self.contentSize.wIDth/2,self.contentSize.height/2);//Repeating the sprite animationCCActionAnimate *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干杯
总结以上是内存溢出为你收集整理的ios – Sprite Frame Animation Cocos2d 3.0全部内容,希望文章能够帮你解决ios – Sprite Frame Animation Cocos2d 3.0所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)