【发布时间】:2014-05-11 15:10:49
【问题描述】:
我在为我的精灵表设置动画时遇到了一些问题。我之前得到了这个代码并且它有效。我有 2 个帧,我的循环中的变量只允许达到 0 和 1 的值,因为帧名称是stickman0-568.png 和stickman1-568.png。我的帧不太好,所以我制作了一个新的精灵表,里面有 3 个帧,stickman0-568.png、stickman1-568.png 和stickman2-568.png。我的 .list 文件名为ickman-568.plist,.png 精灵表名为stickman-568.png。我改变了循环,所以我只能达到 2(0,1,2) 的值。当我现在运行它时,它崩溃了,尽管它在我只有 2 帧之前工作。任何人都可以就可能出了什么问题给我建议吗?这是我的代码,所以你可以看到我做了什么:
-(id) init
{
if( (self=[super init]) )
{
backGroundDesert = [CCSprite spriteWithFile:@"DesertMap.png"];
backGroundDesert.position = ccp(backGroundDesert.textureRect.size.width/2, backGroundDesert.textureRect.size.height/2);
[self addChild:backGroundDesert];
[backGroundDesert runAction:[CCMoveBy actionWithDuration:100 position:ccp(-1400,0)]];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"stickman-568.plist"];
CCSprite *mainGuy = [CCSprite spriteWithSpriteFrameName:@"stickman0-568.png"];
mainGuy.position = ccp(40,backGroundDesert.textureRect.size.height/2);
CCSpriteBatchNode *batchNode = [CCSpriteBatchNode batchNodeWithFile:@"stickman-568.png"];
[batchNode addChild:mainGuy];
[self addChild:batchNode];
NSMutableArray *animFrames = [NSMutableArray array];
for(int i = 0; i < 3; i++)
{
CCSpriteFrame *frames = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"stickman%02d-568.png", i]];
[animFrames addObject:frames];
}
CCAnimation *cape = [CCAnimation animationWithSpriteFrames:animFrames delay:0.2f];
[mainGuy runAction:[CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:cape restoreOriginalFrame:NO]]];
}
return self;
}
-(void)dealloc
{
[[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];
[super dealloc];
}
【问题讨论】:
标签: ios cocos2d-iphone