I am trying to add particle effect to my cocos2d iOS game. I had a problem adding particles to my sprites because all my sprites use spritebatch to improve performance. Because of this, it seems to me that I cannot easily use the particle effect on my sprites. Everything works correctly if I just keep all the particle effects on my game layer, but I would prefer each sprite to track its own particle effect. Here is my code which is in my player class:
-(void)loadParticles { shieldParticle = [[CCParticleSystemQuad alloc] initWithFile:@"shieldParticle.plist"]; shieldParticle.position = self.position; [self addChild:shieldParticle]; }
Using this method, I get an error
CCSprite only supports CCSprites as children when using CCSpriteBatchNode
To avoid this, I made a separate class, particleBase.
In the particleBase class, I inherit it from ccsprite and have an iVar to track the particle effect:
When using this technique, I tried this in my class:
-(void)loadParticles { shieldParticle = [[particleBase alloc] init]; [shieldParticle setParticleEffect:@"shieldParticle.plist"]; [shieldParticle turnOnParticles]; [shieldParticle setPosition:self.position]; [self addChild:shieldParticle z:150]; }
However, I do not get an error, but the particle is also not displayed.
Any help would be greatly appreciated.
source share