【问题标题】:Animating a Sprite with a Sprite Sheet gives an uknown error使用 Sprite 表为 Sprite 设置动画会产生未知错误
【发布时间】:2012-03-09 10:05:14
【问题描述】:

我正在尝试让精灵永远为自己设置动画。没有问题,并且构建良好。我越过了菜单,当我单击包含我想要在其上设置动画的精灵的场景时,它崩溃了。我正在为我的动画使用以下代码:

        [[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 有关,但我看不出有什么问题。请帮助,或者给我另一种方式来动画我的精灵。

【问题讨论】:

    标签: animation xcode4 cocos2d-iphone ccsprite sprite-sheet


    【解决方案1】:

    我认为这是 cocos2d.click here 中最好的动画示例。

    我不确定,但我认为问题出在您的精灵图像或图像名称上。检查 plist 文件中的图像名称。确保所有图像的大小与您用于动画的大小相同。

    希望对你有所帮助。

    【讨论】:

    • 好的,我想我的一些图片可能大小不一,我把它们放大一点,看看效果如何。
    猜你喜欢
    • 2020-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-18
    • 1970-01-01
    相关资源
    最近更新 更多