所以,这是我的场景问题:我从一个菜单场景开始,然后进入游戏内场景,当角色死亡时,我再次进入菜单场景,所有这些都使用:
[[CCDirector sharedDirector] replaceScene:[MainMenu scene]];
和
[[CCDirector sharedDirector] replaceScene:[InGame scene]];
输掉游戏后,试图回到游戏,我的 SpriteSheet 崩溃并出现错误:
'CCSprite is not using the same texture id'
这是我初始化动画的方式:
- (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。