2

我不断遇到崩溃,上面写着:*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'CCSprite: Batched sprites should use the same texture as the batchnode'

我不太确定这意味着什么。我用谷歌搜索了崩溃,但没有得到任何结果。此外,这只发生在我从游戏中的第二个场景回来后回到我的第一个场景时。

我仔细检查了我的代码,并确保我的精灵表中的所有图像都作为子节点添加到批处理节点。我还确保我的应用程序中不在我的精灵表中的图像作为子元素添加到我的图层而不是批处理节点。

无论如何,是什么导致了这次崩溃,我该如何解决?

谢谢!

Edit1:这似乎发生在我的应用程序的这一行:

[self.spriteLeft setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:imageName]];

我 NSLog imageName 并返回: MyImage.png ,然后我查看我加载的 plist 和 pvr.ccz , MyImage.png肯定在那里。所以我不知道为什么当一切看起来都正确时它会崩溃。此外,我确保在我加载精灵表中的图像的任何地方都不会使用 spriteWithFile。

4

1 回答 1

2

它的意思很简单:当您使用纹理创建 CCSpriteBatchNode 对象对象时,稍后当您将精灵添加到 CCSpriteBatchNode 时,您添加到 CCSpriteBatchNode 的所有精灵必须来自同一个纹理。例如:

NSString *spriteName = @"agility"; // an example, this code comes from a method that returns the batchNode
                                   // for many status types

NSString *plist = [NSString stringWithFormat:@"status_%@.plist",spriteName];
NSString *textureFileName = [NSString stringWithFormat:@"status_%@.pvr.gz",spriteName];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:plist textureFile:textureFileName];
CCSpriteBatchNode *batchNode = [CCSpriteBatchNode batchNodeWithFile:textureFileName];

//  plist has a frame named status_agility_Ok.png

CCSprite *frameStatusOk = [CCSprite spriteWithSpriteFrameName:[NSString stringWithFormat:@"status_%@_Ok.png",spriteName]];  
[batchNode addChild:frameStatusOk]; // this will work, both the sprite and the batch node have the same texture

CCSprite *frameStatusNotOk=[CCSprite spriteWithFile:@"someOtherTextureFile.pvr.gz"];
[batchNode addChild:frameStatusNotOk]; // this will fail an assertion and crash.
于 2012-09-09T11:30:16.087 回答