CCSpriteFrameCache在cocos2d中加载黑色图像?

时间:2014-01-11 12:57:20

标签: ios cocos2d-iphone

我正在生成使用texturepacker集成的不同动画图像。

我在我的代码中使用.plist和.png文件,如下所示。有时它工作正常,但有时显示动画图像是黑色的。我也清理/重建我的项目并运行,但有时也会得到黑色的动画图像。

TexturePacker生成.plist和.png,如下所示

enter image description here

代码如下。

    [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"sheetPng-ipadhd-hd.plist"];

    CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"sheetPng-ipadhd-hd.png"];

    [self addChild:spriteSheet];


    /* Gather the list of frames(sprite) */

    NSMutableArray *walkAnimFrames = [NSMutableArray array];
    for (int i=1; i<=3; i++) {
        [walkAnimFrames addObject:
         [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
          [NSString stringWithFormat:@"M0%d.png",i]]];
    }

    CCAnimation *walkAnim = [CCAnimation animationWithSpriteFrames:walkAnimFrames delay:2.0f];

    manSprite=[CCSprite spriteWithSpriteFrameName:@"M01.png"];
    [self resizeSprite:manSprite toWidth:180 toHeight:250];
    manSprite.position=ccp(375, 0);



    id firstRepeat  = [CCRepeat actionWithAction:[CCAnimate actionWithAnimation:walkAnim] times:3];

    [manSprite runAction:firstRepeat];

    [background addChild:manSprite];

    // add the label as a child to this Layer
    [self addChild: background];

1 个答案:

答案 0 :(得分:1)

您的文件扩展名确实存在问题。它们似乎都添加了无关的-hd后缀。

文件名应为:

  • sheetPng
  • sheetPng-HD
  • sheetPng-ipadhd
相关问题