将CCParticleSystemQuad作为子项添加到LHSprite时断言失败

时间:2012-12-29 21:59:12

标签: objective-c ios cocos2d-iphone levelhelper

我尝试将CCParticleSystemQuad作为孩子添加到LHSprite

player = [loader spriteWithUniqueName:@"player"];
NSAssert(player != nil, @"Couldn't find the player!");

// Particles
smokeParticles = [CCParticleSystemQuad particleWithFile:@"smoke.plist"];
smokeParticles.position = ccp(-30.0, 0.0);
[player addChild:smokeParticles];

但我不断收到此错误消息:

2012-12-29 22:51:44.373 MyProject[15396:15203]
*** Assertion failure in -[LHSprite addChild:z:tag:],
/MyPath/MyProject/libs/cocos2d/CCSprite.m:567

CCParticleSystemQuad添加到CCLayer

[self addChild:smokeParticles];

工作正常。


CCSprite.m:第567行

NSAssert([child isKindOfClass:[CCSprite class]],
         @"CCSprite only supports CCSprites as children when using CCSpriteBatchNode");

有谁能告诉我为什么会这样?

2 个答案:

答案 0 :(得分:0)

原因在断言消息中给出。这是因为CCSprite在使用CCSpriteBatchNode时仅支持CCSprites作为子项。如果使用CCSpriteBatchNode绘制精灵,则只能将CCSprites作为子项添加到此精灵中。

答案 1 :(得分:0)

在Level Navigator中的LH内部 - 将你的精灵拖到MAIN_LAYER的顶部 - 这将从批处理节点中删除精灵并使其自动渲染 - 现在你可以通过代码添加子渲染。如果使用批量精灵,则只能将子项添加到与批次节点具有相同纹理的精灵(即,使用相同的图像文件)

对于LHParallaxNode - 这不会将粒子/精灵添加到节点 - 它只是移动它。所以你也应该把你的粒子添加到图层

[self addChild:particle z:100];

然后将其添加到视差节点。

LevelHelper的创建者

Bogdan Vladu这样说..