以下代码似乎无法正常工作,我已经全神贯注地找到了不同的方法,但它们都以同样的方式显示。
+(CCActionAnimate*) initializeAnimation: (NSString*) animationName withNumFrames:(int)frames repeat:(bool)repeat withDelay:(float)delay;
{
CCAnimation *animation;
NSString *fileName = [NSString stringWithFormat: @"%@.plist", animationName];
NSMutableArray *animFrames = [NSMutableArray array];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:fileName];
NSMutableDictionary *framesDict = [[CCSpriteFrameCache sharedSpriteFrameCache]showSpriteFrames];
for(NSString *frameKey in framesDict)
{
NSLog(@"%@", frameKey);
NSLog(@"%@", [[framesDict objectForKey:frameKey] textureFilename]);
}
for(int i =1; i<=frames; i++)
{
CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"%@%d.png",animationName,i]];
NSLog(@"%@", [frame textureFilename]);
[animFrames addObject:frame];
}
if(repeat)
{
for(int i = frames-1; i>=1; i--)
[animFrames addObject:[[CCSprite spriteWithImageNamed:[NSString stringWithFormat:@"%@%d.png",animationName,i]] spriteFrame]];
}
animation = [CCAnimation animationWithSpriteFrames: animFrames delay:delay];
return [CCActionAnimate actionWithAnimation:animation];
}
它似乎找到了正确的.plist文件,但是没有连接到正确的纹理,即使在.plist中目标是正确的。当我尝试运行游戏时,这就是我在NSLog中得到的结果:
2014-07-16 15:19:37.604 Zipper[18602:60b] ZipperFlap4-hd.png
2014-07-16 15:19:37.609 Zipper[18602:60b] ZipperFlap.png
2014-07-16 15:19:37.610 Zipper[18602:60b] ZipperFlap2-hd.png
2014-07-16 15:19:37.615 Zipper[18602:60b] ZipperFlap.png
2014-07-16 15:19:37.617 Zipper[18602:60b] ZipperFlap1-hd.png
2014-07-16 15:19:37.618 Zipper[18602:60b] ZipperFlap.png
2014-07-16 15:19:37.620 Zipper[18602:60b] ZipperFlap3-hd.png
2014-07-16 15:19:37.621 Zipper[18602:60b] ZipperFlap.png
2014-07-16 15:19:37.623 Zipper[18602:60b] (null)
2014-07-16 15:19:37.625 Zipper[18602:60b] *** Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
It does not find the proper ZipperFlap-hd.png texture file even though it is clearly there and as I said it is listed as the .plist's target.
任何帮助将不胜感激,如果需要更多信息,请告诉我!
编辑:我还想说这个工作正常,直到我最近清理了我的版本。现在我的动画都没有用。