Game Development Reference
system = [CCParticleSystemQuad particleWithFile:@"fx-explosion.plist"];
[[SimpleAudioEngine sharedEngine] playEffect:@"explo2.wav"
// Set some parameters that can't be set in Particle Designer
system.positionType = kCCPositionTypeFree;
system.autoRemoveOnFinish = YES;
system.position = self.position;
[[GameLayer sharedGameLayer] addChild:system];
[[SimpleAudioEngine sharedEngine] playEffect:@"hit1.wav"
You have to add the particle effects fx-explosion.plist and fx-explo-
sion2.plist as resources to the Xcode project. The particle system is initialized as
before. Since the particle effect should and must be independent from the enemy that
creates it, a few preparations are necessary. First, set the autoRemoveOnFinish
flag to YES so that the effect automatically removes itself. This works because both ex-
plosions run only for a short time. The effect also needs the current position of the en-
emy so that it's displayed at the correct position.
I add the particle effect to the GameLayer because the enemy itself can't display the
particle effect. To start, it's invisible and so will be any child nodes added to it. It also
might be respawned very soon, which would interfere with the particle effect's posi-
tion. But most importantly, all Enemy objects are added to a CCSpriteBatchNode ,
which does not allow you to add anything but CCSprite objects. If the particle effect
were added to the Enemy object, a runtime exception would be inevitable.