Ios 重新启动场景时崩溃
因此,我的场景问题是:我从菜单场景开始,然后进入InGame场景,当角色死亡时,我再次进入菜单场景,所有这些都使用:Ios 重新启动场景时崩溃,ios,cocos2d-iphone,dealloc,sprite-sheet,Ios,Cocos2d Iphone,Dealloc,Sprite Sheet,因此,我的场景问题是:我从菜单场景开始,然后进入InGame场景,当角色死亡时,我再次进入菜单场景,所有这些都使用: [[CCDirector sharedDirector] replaceScene:[MainMenu scene]]; 及 在输掉游戏并试图返回游戏后,我的精灵表崩溃并出现错误: 'CCSprite is not using the same texture id' 以下是我初始化动画的方式: - (void) initSprite:(NSString *)plist an
[[CCDirector sharedDirector] replaceScene:[MainMenu scene]];
及
在输掉游戏并试图返回游戏后,我的精灵表崩溃并出现错误:
'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];
}
我相信问题来自纹理的释放
我不使用ARC。缓存中可能有一个“1.png”,对应于退出重新启动序列之前创建的另一个动画。在重新启动之前,可能需要清除sprite帧缓存(可能还有很多其他东西)
我通过'NNNN.png'完全避免使用“1.png”,因为很可能所有的动画都会使用它们。相反,我使用的是:
walk_classKey_upNNNN.png{向上、向下、左、右、空闲、跳跃……以及我需要的任何其他地图姿态)
fight_classKey_strickenn.png{罢工、受伤、死亡……例如)
classKey是{战士、盗贼……等等……以我拥有的唯一士兵类型为准)
我给我的纹理命名相同
walk_fighter_up-hd.plist(使用纹理打包器,plist嵌入纹理名称)。
fight_rogue_cheapShot-hd.plist(cheapShot是我当前游戏中盗贼的技能之一).在此处使用精灵表是多余的。对于使用initSprite创建的每个精灵,可以为该精灵创建一个精灵批处理节点。使用或不使用批处理节点,每个精灵都会有一个绘制调用。批处理不会加快动画速度,它们会加快使用相同纹理渲染多个精灵的速度,以便您可以显示在一次绘制调用中有10个或数百个相同的精灵。我知道,我用它来绘制角色运行的动画。我有一个包含12个精灵的精灵表(),您认为最好的方法是什么?这是缓存,谢谢。只是添加了
[[CCSpriteFrameCache sharedSpriteFrameCache]removeSpriteFrames]
它可以工作。NNNN.png对应于什么?名为1.png、2.png、3.png…NNN.png的帧。
- (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 addChild:texture];