CCSprite:批处理精灵应该使用与批处理节点相同的纹理? [英] CCSprite: Batched sprites should use the same texture as the batchnode?

查看:275
本文介绍了CCSprite:批处理精灵应该使用与批处理节点相同的纹理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不断得到一个崩溃,说: ***由于未捕获异常NSInternalInconsistencyException终止应用程序,原因:CCSprite:批处理精灵应该使用与批次节点相同的纹理

I keep getting a crash that says: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'CCSprite: Batched sprites should use the same texture as the batchnode'

我不太清楚这是什么意思。我googled崩溃,但没有结果。这也只有当我从我的游戏中的第二个场景回来后回到我的第一个场景。

I am not quite sure what this means. I googled the crash but got no results. Also this only happens when I go back to my first scene after coming back from the second scene in my game.

我双重检查我的代码,我确保所有的图像在我的sprite工作表中作为子节点添加到批处理节点。我还确保我的应用程序中不在我的sprite工作表中的图像作为一个孩子添加到我的图层而不是批处理节点。

I double checked my code and I make sure all the images in my sprite sheets are added as children to the batch node. I also make sure the images in my app that aren't in my sprite sheet are added as a child to my layer and not the batch node.

无论什么原因崩溃,我该如何解决?

Anyway what causes this crash and how can I fix it?

谢谢!

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

Edit1: It seems to be happening on this line in my app:

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

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

I NSLog imageName and it returns: MyImage.png , then I look in my plist and pvr.ccz that I load and MyImage.png is definitely in there. So I don't know why it is crashing when everything looks right. Also I make sure that I do not use spriteWithFile anywhere where I load an image thats in my sprite sheet.

推荐答案

它说:当你创建CCSpriteBatchNode对象与纹理,稍后当你添加精灵到CCSpriteBatchNode,你添加到CCSpriteBatchNode的所有精灵必须来自同一个纹理。例如:

It simply means what it says : when you create the CCSpriteBatchNode object object with a texture, later when you add sprites to the CCSpriteBatchNode, all the sprites you add to the CCSpriteBatchNode MUST be from the same texture. For example:

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.

这篇关于CCSprite:批处理精灵应该使用与批处理节点相同的纹理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆