Describe the bug
I've noticed that all particules were draw under anything that had a zIndex set.
To Reproduce
- Create a Rectangle with zIndex = 1000 that fills the screen
- Create a Particules Emitter (I tried Rain & Smoke, same behavior)
- Start the emitter
- 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.
Describe the bug
I've noticed that all particules were draw under anything that had a zIndex set.
To Reproduce
Expected behavior
Particules need to be displayed at a desired zIndex.
Additional context / possible fixes
The Bug is caused by this strategy:
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.