2013-03-28 27 views
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,反之亦然。這已經引起了一陣頭疼,將是對我的問題的任何援助表示感謝。質地ID沒有使用相同的ID

 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]; 
     } 
    } 

} 

回答

1

添加以下代碼取代了現場的loadlevel修復了這個問題

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

希望它會有人樂於助人之前!

+2

聽起來就像你有兩個紋理地圖一樣(spriteframe)名稱的圖像,這種不確定性可能導致的Cocos2D引用「錯誤」的框架 – LearnCocos2D 2013-03-28 09:19:37