Skip to content

Particules Emitters are Spawning particules at zIndex = 0 #1318

Description

@DeathPhoenix22

Describe the bug
I've noticed that all particules were draw under anything that had a zIndex set.

To Reproduce

  1. Create a Rectangle with zIndex = 1000 that fills the screen
  2. Create a Particules Emitter (I tried Rain & Smoke, same behavior)
  3. Start the emitter
  4. You won't see any particules

Expected behavior
Particules need to be displayed at a desired zIndex.

Additional context / possible fixes
The Bug is caused by this strategy:

open class ParticleComponent(val emitter: ParticleEmitter) : Component() {
    ...
    /**
     * This is the entity whose view is used to render particles.
     * Use of extra entity allows to render particles independently from
     * the entity to which this component is attached. Otherwise, the entire
     * set of emitted particles will be moved based on entity's view.
     */
    val parent = Entity()
    ...

In fact, the ParticuleComponent will create it's own "ghost" entity instead of using the Entity tied to the Component. This ensures that particules stay were they were emitted from (which is a desired behavior, of course). The Particule has an ImageView that will ensure that the particule is spawned at the X & Y desired positions. But, the problem is related to how the zIndex sorting works. An ImageView doesn't have a zIndex strategy, it's handled by the FXGL Scene (re-adding Nodes to the Scene after a zIndex sort).

Solution
Simply assign the zIndex of the real ParticuleComponent entity to the "Ghost" entity by default. Important: The "Ghost" entity zIndex will not be bind to the real ParticuleComponent entity, to prevent Particule relocations.

@AlmasB I'll create a PR soon.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions