0

我在日志中收到此异常

*** 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");

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

4

1 回答 1

2

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

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

您很少需要使用spriteWithFile. 我能想到的唯一场景是当你想多次绘制相同的图像时。(而不是来自相同纹理的许多图像)。

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

于 2014-09-04T07:10:01.427 回答