【问题标题】:CCSpriteFrameCache loading black image in cocos2d?CCSpriteFrameCache 在 cocos2d 中加载黑色图像?
【发布时间】:2014-01-11 22:28:23
【问题描述】:

我正在生成使用纹理打包器集成的不同动画图像。

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

TexturePacker 生成的 .plist 和 .png 如下

代码如下。

    [[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];

【问题讨论】:

    标签: ios cocos2d-iphone


    【解决方案1】:

    您的文件扩展名肯定有问题。似乎他们都添加了一个无关的-hd 后缀。

    文件名应该是:

    • sheetPng
    • sheetPng-hd
    • sheetPng-ipadhd

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-01-21
      • 2020-08-20
      • 1970-01-01
      • 2012-04-19
      • 2014-03-23
      • 1970-01-01
      • 2013-03-31
      相关资源
      最近更新 更多