0

我尝试将一个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

添加CCParticleSystemQuadCCLayer

[self addChild:smokeParticles];

工作得很好。


CCSprite.m: 567 行

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

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

4

2 回答 2

0

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

对于 LHParallaxNode - 这不会将粒子/精灵添加到节点 - 它只是移动它。因此,您还应该将粒子添加到图层

[自我addChild:粒子z:100];

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

Bogdan VladuLevelHelper 的创建者这样说..

于 2013-03-04T22:12:54.670 回答
0

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

于 2012-12-29T23:42:23.777 回答