2014-09-04 80 views
0

我得到這個例外日誌將正常CCSprite以CCSpriteBatchNode崩潰

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'CCSprite is not using the same texture id' 

我所試圖做的是增加一個正常的「myfile.png」文件到SpriteBatchNode

**聲明一批節點的

CCSpriteBatchNode *_backgroundLayer = [CCSpriteBatchNode batchNodeWithFile:@"sprites.png"]; 

**使用

這行工作PERF ECT

CCSprite *sprite1 = [CCSprite spriteWithSpriteFrameName:@"PngFileKeptInSpriteSheet.png"]; 
[_backgroundLayer addChild:sprite1]; 

但是,當我使用直接* .png文件添加到一批節點,它崩潰上線

 [_backgroundLayer addChild:sprite2]; 

CCSprite *sprite2 = [CCSprite spriteWithFile:@"myfile.png"]; 

崩潰關於進一步調試我發現, :

斷言失敗在文件中CCSpriteBatchNode.m

內部方法-(void) addChild:(CCSprite*)child z:(NSInteger)z tag:(NSInteger) aTag

在線路NSAssert(child.texture.name == textureAtlas_.texture.name, @"CCSprite is not using the same texture id");

P.S. :通過「正常」我的意思是不採取* .plist文件

+0

什麼版本的cocos2d? – trojanfoe 2014-09-04 06:37:55

+0

COCOS2D_VERSION 0x00010001 – 2014-09-04 06:45:54

+0

那麼是1.1還是你是編譯器? – trojanfoe 2014-09-04 06:48:49

回答

2

首先,我會更新cocos2D。但是,這不是你的問題,無論如何,它可能不是最新版本的「固定」。這不是一個真正的bug

批處理節點要求你打算批量的所有精靈都使用相同的紋理。當你加載精靈表時,它使用一個大的紋理。當您致電spriteWithFile時,cocos2d將從該圖像創建一個紋理。

很少有您希望使用spriteWithFile從精靈創建批處理節點。我能想到的唯一場景是當你想多次繪製相同的圖像。 (而不是來自相同紋理的許多圖像)。

總之,你試圖做的事情是不被支持的,無論如何都沒有多大意義,因爲這兩個精靈不可能被批准。

+0

感謝您的回覆......我只是想避免重新創建一個精靈表添加一個新的按鈕的麻煩。 – 2014-09-04 07:15:07

+0

雖然不滿意......在這裏關閉......將按照正常的方式添加按鈕,而不使用之前的開發者所做的操作。謝謝哥們。 – 2014-09-04 07:19:46

+0

你使用一個程序來製作精靈表單嗎?添加精靈並沒有太多的麻煩。 – 2014-09-04 07:58:32