我正在使用 texturepacker 生成不同的动画图像。
我在代码中使用 .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];
最佳答案
您的文件扩展名肯定有问题。似乎它们都添加了一个无关的 -hd
后缀。
文件名应该是:
- sheetPng
- sheetPng-高清
- sheetPng-ipadhd
关于ios - CCSpriteFrameCache 在 cocos2d 中加载黑色图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21062488/