【发布时间】:2014-03-17 11:14:19
【问题描述】:
我一直在尝试制作动画精灵,它们有很多教程,但它们都是针对 Cocos2d 2.x 的。我的精灵表被命名为 fappbird.png 和 .plist 被命名为 fappbird.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];
// -----------------------------------------------------------------------
【问题讨论】:
-
看到我尝试将那个问题的答案实现到 min 但它会崩溃并且什么都不会发生
-
当它崩溃时它会告诉你什么?
-
2014-02-17 16:13:09.875 Bye Flappy[53793:70b] -[CCFileUtils fullPathForFilename:contentScale:] : cocos2d: Warning: File not found: monster1.png我认为问题在于我的 .plist 没有链接。但我将如何链接它? Monster1.png 是在我的 fappbird.plist @connor 中定义的
标签: ios objective-c cocos2d-iphone sprite-sheet