1
 Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'CCSprite is not using the same texture id'
*** First throw call stack:
(0x321d22a3 0x39eef97f 0x321d215d 0x32aa7ab7 0x71afd 0x48b61 0xb41cd 0xb1f7d 0xb1e4f 0xb8913 0x4123f 0x40bf5 0x41661 0x3e27f 0x9cf8f 0x9d917 0x9b331 0x33fed5f1 0x33fda801 0x33fda11b 0x35cf05a3 0x35cf01d3 0x321a7173 0x321a7117 0x321a5f99 0x32118ebd 0x32118d49 0x35cef2eb 0x3402e301 0xb0fa3 0x20e8)
libc++abi.dylib: terminate called throwing an exception
(lldb) 

上面是错误,下面是我的代码。我正在做的是我有两个不同的 plist 和 png 精灵表文件,它们都包含不同的图块,但有船和 ui。这是在我的加载场景层中,基本上在主菜单层中,它会推送一个 int,它是级别编号,然后加载场景层,它会根据级别数量打开精灵表文件。这只在我打开第 1 级然后第 2 级然后返回并打开第 1 级时崩溃,反之亦然。这已经引起了一段时间的头痛,并感谢有关我的问题的任何帮助。

     CGSize winSize = [CCDirector sharedDirector].winSize;
        [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:
         [NSString stringWithFormat:@"clonespritesheet%d.plist", loadlevel]];
        mainship = [Ship spriteWithSpriteFrameName:@"mainship.png"];
        mainship.position = startingshiplocation;
        mainship.speed = 10;
        [self addChild:mainship z:-4];

        joystickright = [Joystick spriteWithSpriteFrameName:@"uifirebutton.png"];
        joystickleft =  [Joystick spriteWithSpriteFrameName:@"uimovementbutton.png"];
        joystickleft.up = [[CCSpriteFrameCache sharedSpriteFrameCache]spriteFrameByName:@"uimovementbutton.png"];
        joystickleft.down = [[CCSpriteFrameCache sharedSpriteFrameCache]spriteFrameByName:@"uimovementbuttonactive.png"];
        joystickright.up = [[CCSpriteFrameCache sharedSpriteFrameCache]spriteFrameByName:@"uifirebutton.png"];
        joystickright.down = [[CCSpriteFrameCache sharedSpriteFrameCache]spriteFrameByName:@"uifirebuttonactive.png"];

        joystickright.position = startingjoystickrightlocation;
        joystickleft.position = startingjoystickleftlocation;
        [self addChild:joystickright z:1];
        [self addChild:joystickleft z:1];
        level1backdrop2.anchorPoint = ccp(0,0);
        level1backdrop1.anchorPoint = ccp(0,0);
        level1backdrop1 = [CCSprite spriteWithSpriteFrameName:@"backdrop.png"];
        level1backdrop1.position = ccp(0,190);
        level1backdrop2 = [CCSprite spriteWithSpriteFrameName:@"backdrop.png"];
        level1backdrop2.position = ccp(level1backdrop1.boundingBox.size.width-1,190);
        [self addChild:level1backdrop1 z: -5];
        [self addChild:level1backdrop2 z: -5];
        if(loadlevel == 1)
        {
        level2backdrop2.anchorPoint = ccp(0,0);
        level2backdrop1.anchorPoint = ccp(0,0);
        level2backdrop1 = [CCSprite spriteWithSpriteFrameName:@"backdrop2.png"];
        level2backdrop1.position = ccp(0,170);
        level2backdrop2 = [CCSprite spriteWithSpriteFrameName:@"backdrop2.png"];
        level2backdrop2.position = ccp(level2backdrop1.boundingBox.size.width-1,170);
        [self addChild:level2backdrop1 z: -5];
        [self addChild:level2backdrop2 z: -5];
        }


        CCSprite *uiscreenbotttom = [CCSprite spriteWithSpriteFrameName:@"uitemplate.png"];
        [self addChild:uiscreenbotttom z:0];
        uiscreenbotttom.position = ccp(winSize.width/2,43);


- (void) loadStartingTiles //16 by 24
{
    [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:
     [NSString stringWithFormat:@"clonespritesheet%d.plist", loadlevel]];
     for(int i = 0; i < amountblockslevel1; i++)
    {
        levelframes[i] =[[CCSpriteFrameCache sharedSpriteFrameCache]spriteFrameByName:
                             [NSString stringWithFormat:@"block%d.png", i]];
    }

    tiles = [CCSpriteBatchNode batchNodeWithFile:[NSString stringWithFormat:@"clonespritesheet%d.png", loadlevel]];
    [self addChild:tiles z:-3];


    CCSprite *tempsprite;
    for(int x = 0; x < 26; x++) //minus 1 for one at the begining
    {
        for(int y = 0; y < 16; y++)
        {
            tempsprite = [CCSprite spriteWithSpriteFrame:levelframes[currentscreen[y][x]]];
            tempsprite.position = ccp(x*20+10,(16-y)*20-10); //+10 for align for tile size
            [tiles addChild:tempsprite];
        }
    }

}
4

1 回答 1

1

在将场景替换为负载级别之前添加以下代码可解决此问题

[[CCSpriteFrameCache sharedSpriteFrameCache] removeSpriteFrames];
 [[CCTextureCache sharedTextureCache] removeAllTextures];

希望它对某人有帮助!

于 2013-03-28T06:44:34.903 回答