Cocos2d iphone 将普通CCSprite添加到CCSpriteBatchNode会崩溃
我正在日志中获取此异常Cocos2d iphone 将普通CCSprite添加到CCSpriteBatchNode会崩溃,cocos2d-iphone,ccspritebatchnode,Cocos2d Iphone,Ccspritebatchnode,我正在日志中获取此异常 *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'CCSprite is not using the same texture id' 我试图做的是将一个普通的“myfile.png”文件添加到SpriteBatchNode **批处理节点的声明 CCSpriteBatchNode *_backgroundLayer = [CCSprite
*** 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"];
**用法
这条线很好用
CCSprite *sprite1 = [CCSprite spriteWithSpriteFrameName:@"PngFileKeptInSpriteSheet.png"];
[_backgroundLayer addChild:sprite1];
但是,当我使用direct*.png文件添加到批处理节点时,它崩溃了
CCSprite *sprite2 = [CCSprite spriteWithFile:@"myfile.png"];
在线崩溃
[_backgroundLayer addChild:sprite2];
在进一步调试时,我发现:
断言失败位于文件CCSpriteBatchNode.m
内部方法-(void)addChild:(CCSprite*)子对象z:(NSInteger)z标记:(NSInteger)aTag
在第NSAssert行(child.texture.name==textureAtlas_uuz.texture.name,@“CCSprite未使用相同的纹理id”)代码>
注意:所谓“正常”,我的意思是不从*.plist文件中获取,首先,我要更新cocos2D。但是,这不是您的问题,在最新版本中可能也没有“修复”。这不是一个真正的错误
批处理节点要求要批处理的所有精灵都使用相同的纹理。加载精灵图纸时,它使用一个大纹理。调用spriteWithFile
时,cocos2d将从该图像创建纹理
很少需要使用spriteWithFile
从精灵创建批处理节点。我能想到的唯一情况是,当你想多次绘制同一幅图像时。(而不是来自同一纹理的多个图像)
简言之,您尝试执行的操作不受支持,也没有多大意义,因为这两个精灵不可批处理。cocos2d的哪个版本?cocos2d_版本0x00010001那么这是1.1还是您是编译器?哎呀!很抱歉这是cocos2dv1.0.1这是一个新的应用程序吗?如果我强烈建议移动到v2或v3。感谢您的回复。。。我只是想避免为添加一个新按钮而重新创建一个精灵表的麻烦。虽然不满意。。。在这里关闭它。。。将以正常方式添加按钮,而不使用以前的开发人员所做的操作。谢谢,伙计。你用程序做雪碧床单吗?添加雪碧没有太多麻烦。是的,纹理打包机