3
votes

My tilemap has a "torch" tile. I am using a CCParticleSystemQuad emitter to make the fire effect.

The emitter is children of the tilemap (directly above the torch tile).

However, the player can move and the tilemap will move as well (to center the "camera" on the player). When that happens, naturally the emitter will move as well. But here's the problem: such movement gives an effect like.... like if the torch was moving, and not the player (which is actually the case, but this effect isn't good).

Hard to explain. Just make a fire emitter, put as children of tilemap, and move the tilemap to the right. The effect is cool but doesn't make sense.

Any ideas? I though of moving every single existing particle in the emitter, but that doesn't sound good for performance (I got lots of emitters with hundreds/thousands of particles, and the map scrolls almost every single frame)

1

1 Answers

11
votes

The CCParticleSystem has a positionType property with which you can change the position behavior of the emitted particles.

The enum is defined as follows:

typedef enum {
    /** Living particles are attached to the world and are unaffected by emitter repositioning. */
    kCCPositionTypeFree,

    /** 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.
     */
    kCCPositionTypeRelative,

    /** Living particles are attached to the emitter and are translated along with it. */
    kCCPositionTypeGrouped,
}tCCPositionType;

You will want your particles to be positioned either relative or grouped. There's a subtle difference between the two, just try one and then the other to see which fits your use case better.

particleSystem.positionType = kCCPositionTypeRelative;
particleSystem.positionType = kCCPositionTypeGrouped;

Btw, this is one of the few settings that can't be changed in the ParticleDesigner tool.