简体   繁体   English

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

[英]Assertion failure when adding a CCParticleSystemQuad as child to LHSprite

I try to add a CCParticleSystemQuad as child to LHSprite : 我尝试将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];

But I keep getting this error message: 但我不断收到此错误消息:

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

Adding the CCParticleSystemQuad to the CCLayer CCParticleSystemQuad添加到CCLayer

[self addChild:smokeParticles];

works just fine. 效果很好。


CCSprite.m : Line 567 CCSprite.m :第567行

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

Can anyone tell me why this happens? 谁能告诉我为什么会这样?

The reason is given in assert message. 原因在断言消息中给出。 It happens because CCSprite only supports CCSprites as children when using CCSpriteBatchNode. 这是因为CCSprite在使用CCSpriteBatchNode时仅将CCSprites作为子级支持。 If you use CCSpriteBatchNode to draw a sprite, you can only add CCSprites as children to this sprite. 如果使用CCSpriteBatchNode绘制子画面,则只能将CCSprites作为子级添加到该子画面。

Inside LH in the Level Navigator - drag your sprite on top of the MAIN_LAYER - this will remove the sprite from the batch node and make it self rendered - now you will be able to add children to it via code. 在“级别导航器”的LH内-将子画面拖到MAIN_LAYER上-这将从子节点中删除子画面并使其自渲染-现在,您可以通过代码向其添加子级了。 If you use a batch sprite, you can only add children to the sprite that have the same texture as the batch node (that is, uses the same image file) 如果您使用批处理精灵,则只能将具有与批处理节点相同纹理的子代添加到该精灵中(即,使用相同的图像文件)

for the LHParallaxNode - this does not add the particle/sprite to the node - it just moves it. 对于LHParallaxNode-这不会将粒子/精灵添加到节点-只是将其移动。 So you should also add your particle to the layer 因此,您还应该将粒子添加到图层中

[self addChild:particle z:100]; [self addChild:particle z:100];

then add it to the parallax node. 然后将其添加到视差节点。

Bogdan Vladu the creator of LevelHelper says so.. Bogdan Vladu的创建者Bogdan Vladu这样说。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM