ios - CCSpriteFrameCache 在 cocos2d 中加载黑色图像?

标签 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];

最佳答案

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

文件名应该是:

  • sheetPng
  • sheetPng-高清
  • sheetPng-ipadhd

关于ios - CCSpriteFrameCache 在 cocos2d 中加载黑色图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21062488/

相关文章:

iOS 应用程序因 [UIFeedbackGenerator _autoDeactivate] 而崩溃

objective-c - 使用 Box2D 在 Cocos2D 项目中包含 GameLayer.h 时编译错误

iphone - 如何解决 mPeakPower 问题

ios - 如何仅使用Cocos2d旋转横向

ios - 目前无法购买此商品

ios - Swift:使用按钮导航到新的 ViewController

iphone - Cocos2D iPhone - 消除CCTransition之间的黑屏

objective-c - Cocos2d :Add uilabel in scene

ios - UISlider 每毫秒都不会顺畅地滴答作响

ios - UILocalNotification 操作未显示的操作