使用 Sprite Sheet 对 Sprite 进行动画处理会出现未知错误
我正在尝试让精灵永远为自己设置动画。没有任何问题,而且构建得很好。我经过菜单,当我单击包含我想要为其制作动画的精灵的场景时,它崩溃了。我的动画使用以下代码:
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"sprite_fly.plist"];
CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"sprite_fly.png"];
[self addChild:spriteSheet];
NSMutableArray *flapAnimFrames = [NSMutableArray array];
for(int i = 1; i<=6; ++i) {
[flapAnimFrames addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"Fly%d.png"]]];
}
CCAnimation *flapAnim = [CCAnimation animationWithFrames:flapAnimFrames delay:1];
CGSize winSize = [CCDirector sharedDirector].winSize;
fly = [CCSprite spriteWithSpriteFrameName:@"fly1.png"];
fly.position = ccp(winSize.width/2, winSize.height/2);
flapAction = [CCRepeatForever actionWithAction:
[CCAnimate actionWithAnimation:flapAnim restoreOriginalFrame:NO]];
[fly runAction:flapAction];
[spriteSheet addChild:fly];
我认为问题与第一行代码 CCSpriteFrameCache 有关,但我看不出它有什么问题。请帮忙,或者给我另一种方法来动画我的精灵。
I am trying to get a sprite to animate itself forever. There are no problems, and it builds fine. I get past the menus and when I click on the scene that has my sprite that I want to animate on it, it crashes. I am using the following code for my animation:
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"sprite_fly.plist"];
CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"sprite_fly.png"];
[self addChild:spriteSheet];
NSMutableArray *flapAnimFrames = [NSMutableArray array];
for(int i = 1; i<=6; ++i) {
[flapAnimFrames addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"Fly%d.png"]]];
}
CCAnimation *flapAnim = [CCAnimation animationWithFrames:flapAnimFrames delay:1];
CGSize winSize = [CCDirector sharedDirector].winSize;
fly = [CCSprite spriteWithSpriteFrameName:@"fly1.png"];
fly.position = ccp(winSize.width/2, winSize.height/2);
flapAction = [CCRepeatForever actionWithAction:
[CCAnimate actionWithAnimation:flapAnim restoreOriginalFrame:NO]];
[fly runAction:flapAction];
[spriteSheet addChild:fly];
I think that the problem is to do with the first line of code, CCSpriteFrameCache, but I can't see anything wrong with it. Please help, or give me another way to animate my sprite.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这是 cocos2d 中动画的最佳示例。单击此处。
我不确定,但我认为问题出在你的精灵图像或图像名称上。检查 plist 文件中的图像名称。确保所有图像的尺寸与您用于动画的尺寸相同。
希望这会对您有所帮助。
I think this is the best example for animation in cocos2d.click here.
I am not sure but i think the problem is with your sprite images or image name. check your image name in the plist file. Make sure that all images have same size which you are using for your animation.
Hope that will help you.