代码之家  ›  专栏  ›  技术社区  ›  thegameg

重新启动场景时崩溃

  •  0
  • thegameg  · 技术社区  · 11 年前

    所以,这是我的场景问题:我从菜单场景开始,然后进入游戏场景,当角色死亡时,我再次进入菜单场景,所有这些都使用:

    [[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。

    1 回复  |  直到 11 年前
        1
  •  1
  •   YvesLeBorg    11 年前

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

    我完全避免“1.png”到“NNNN.png”,因为很可能你所有的动画都会有它们。相反,我会使用以下内容:

    walk_classKey_upNNNN.png(向上、向下、向左、向右、空闲、跳跃…以及我需要的任何其他地图姿势) fight_classKey_strikeNNN.png(例如,罢工、受伤、死亡…)

    classKey是(战士,无赖,…等等…无论我有什么独特的士兵类型)

    我把我的plists/纹理命名为相同的

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