0

I try to add a CCParticleSystemQuad as child to 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

[self addChild:smokeParticles];

works just fine.


CCSprite.m: Line 567

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

Can anyone tell me why this happens?

IluTov
  • 6,807
  • 6
  • 41
  • 103
Tom Söderlund
  • 4,743
  • 4
  • 45
  • 67

2 Answers2

0

The reason is given in assert message. It happens because CCSprite only supports CCSprites as children when using CCSpriteBatchNode. If you use CCSpriteBatchNode to draw a sprite, you can only add CCSprites as children to this sprite.

Kreiri
  • 7,840
  • 5
  • 30
  • 36
0

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. 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. So you should also add your particle to the layer

[self addChild:particle z:100];

then add it to the parallax node.

Bogdan Vladu the creator of LevelHelper says so..

user1526474
  • 925
  • 13
  • 26