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) 

上はエラー、下は私のコードです。私がやっていることは、2 つの異なる 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

adding below code before replacing the scene to the loadlevel fixes this problem

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

Hope it will helpful for someone!

于 2013-03-28T06:44:34.903 に答える