【问题标题】:adding a normal CCSprite to CCSpriteBatchNode crashes添加一个普通的 CCSprite 到 CCSpriteBatchNode 崩溃
【发布时间】:2014-09-04 15:10:01
【问题描述】:

我在日志中收到此异常

*** 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];

但是,当我使用直接 *.png 文件添加到批处理节点时,它会崩溃

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

在线崩溃

        [_backgroundLayer addChild:sprite2];

经过进一步调试,我发现:

断言失败在文件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");

附: :“正常”是指不是取自 *.plist 文件

【问题讨论】:

  • cocos2d是什么版本的?
  • COCOS2D_VERSION 0x00010001
  • 那是 1.1 还是你是编译器?
  • 哎呀!抱歉……是 cocos2d v1.0.1
  • 这是一个新应用吗?如果我强烈建议迁移到 v2 或 v3。

标签: cocos2d-iphone ccspritebatchnode


【解决方案1】:

首先,我会更新 cocos2D。但是,这不是您的问题,并且可能无论如何都没有在最新版本中“修复”。这不是真正的错误

批处理节点要求您打算批处理的所有精灵都使用相同的纹理。当您加载一个精灵表时,它会使用一个大纹理。当你调用spriteWithFile 时,cocos2d 会根据该图像创建纹理。

您很少需要使用spriteWithFile 从精灵创建批处理节点。我能想到的唯一场景是当你想多次绘制相同的图像时。 (而不是来自同一纹理的许多图像)。

简而言之,您正在尝试做的事情不受支持,并且无论如何都没有多大意义,因为这两个精灵不可批处理。

【讨论】:

  • 感谢您的回复...我只是想避免重新创建精灵表以添加单个新按钮的麻烦。
  • 虽然不满意...在此处关闭...将以正常方式添加按钮,而不是使用以前的开发人员所做的。谢谢朋友。
  • 你使用程序来制作你的精灵表吗?添加精灵没有太多麻烦。
  • 是的,纹理打包器
猜你喜欢
  • 2013-01-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多