2013-08-24 36 views
0

因此,这里是我的场景问题:我从菜单场景开始,然后进入InGame场景,当角色死亡时,我再次进入菜单场景,所有这些使用:重新启动场景时发生崩溃

[[CCDirector sharedDirector] replaceScene:[MainMenu scene]]; 

[[CCDirector sharedDirector] replaceScene:[InGame scene]]; 

与错误输掉了比赛,并试图回到比赛,我SpriteSheet崩溃后:

'CCSprite is not using the same texture id' 

这里是我的init动画:

- (void) initSprite:(NSString *)plist andTexture:(NSString *)texture_ { 

[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:plist]; 

spriteSheet = [CCSpriteBatchNode batchNodeWithFile:texture_]; 

NSMutableArray *walkAnimFrames = [NSMutableArray array]; 

for (int i=1; i<=12; i++) { 
    [walkAnimFrames addObject: 
    [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: 
     [NSString stringWithFormat:@"%d.png",i]]]; 
} 

CCAnimation *walkAnim = [CCAnimation animationWithSpriteFrames:walkAnimFrames delay:0.05f]; 

texture = [CCSprite spriteWithSpriteFrameName:@"1.png"]; 
walkAction = [CCRepeatForever actionWithAction: [CCAnimate actionWithAnimation:walkAnim]]; 
[texture runAction:walkAction]; 

texture.position = position; 
texture.tag = HeroType; 
[spriteSheet addChild:texture]; 

[self addChild:spriteSheet]; 
} 

当我纹理添加到spriteSheet发生崩溃:

[spriteSheet addChild:texture]; 

我认为,问题来自于质感的释放..

我不使用ARC。

+2

您在这里使用精灵表是多余的。对于使用initSprite创建的每个精灵,都会为该精灵创建一个精灵批处理节点。无论是否有批处理节点,您最终都会为每个精灵绘制一个绘图调用。批次不会加快动画速度,它们可以加速使用相同纹理渲染多个精灵,从而可以在一次绘制调用中显示10个或数百个相同的精灵。 – LearnCocos2D

+0

我明白了,我正在用它来绘制一个正在运行的角色的动画。我有一个精灵12张精灵图(http://oi42.tinypic.com/2s6oe3n.jpg),你认为最好的方法是什么? – thegameg

回答

1

缓存中可能有一个“1.png”,它对应于在退出重新启动序列之前创建的另一个动画。也许你想在重新启动之前清除精灵帧缓存(可能还有很多其他的东西)。

我完全避免“1.png”到“NNNN.png”,因为很可能所有的动画都会有它们。相反,我用的东西,如:

walk_classKey_upNNNN.png {上,下,左,右,闲置,跳跃......和任何其他地图的立场,我需要) fight_classKey_strikeNNNN.png {击,伤害,死了的例如)

的ClassKey是{战士,盗贼,......等等......无论唯一的战士型我)

和我的名字我的Plist /纹理相同

walk_fighter_up-hd.plist(使用纹理打包器,plist嵌入纹理名称)。 fight_rogue_cheapShot-hd.plist(cheapShot是我当前游戏中的流氓技能之一)。

+0

这是缓存,谢谢。刚刚添加了[[[CCSpriteFrameCache sharedSpriteFrameCache] removeSpriteFrames];'并且它可以工作。 NNNN.png对应什么? – thegameg

+0

框架名为1.png,2.png,3.png ... NNN.png。 – YvesLeBorg