2014-09-04 78 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