Search code examples
objective-cioscocos2d-iphoneccparticlesystem

Cocos2d: Emitted particles do not pan correctly with screen


I have setup a particle emitter to show a glowing orb which looks great (added by the code below). The only issue is that when I pan around the level the particles that have already been created pan around too rather than staying local to the emitter location; the emitter itself pans around correctly and emits new particles from the correct location

CCParticleSystem *orb = [CCParticleSystemQuad particleWithFile:@"orb.plist"];
orb.position = ccp((screenSize.width / 2),screenSize.height);
[self addChild: orb];

What do I have to do to ensure that emitted particles also pan around with the screen?


Solution

  • There are three possible behaviors for particles positioning (positionType property of particle system). As stated in cocos2d sources:

    • kCCPositionTypeFree - Living particles are attached to the world and are unaffected by emitter repositioning.
    • kCCPositionTypeRelative - Living particles are attached to the world but will follow the emitter repositioning. Use case: Attach an emitter to an sprite, and you want that the emitter follows the sprite.
    • kCCPositionTypeGrouped - Living particles are attached to the emitter and are translated along with it.

    I'm not properly understanding what is your expected behavior. Try all these modes at first.

    Also, cocos2d has great demo which is distributed with sources. Check ParticleTest example.