Skip to content

Commit 4c740dd

Browse files
fix: emit particles at initial Entity zIndex instead of zIndex 0, closes #1318
1 parent f4937ff commit 4c740dd

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

fxgl-entity/src/main/kotlin/com/almasb/fxgl/particle/ParticleComponent.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ open class ParticleComponent(val emitter: ParticleEmitter) : Component() {
3636

3737
override fun onUpdate(tpf: Double) {
3838
if (parent.world == null) {
39+
parent.zIndex = entity.zIndex
3940
entity.world.addEntity(parent)
4041
}
4142

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* FXGL - JavaFX Game Library. The MIT License (MIT).
3+
* Copyright (c) AlmasB ([email protected]).
4+
* See LICENSE for details.
5+
*/
6+
@file:Suppress("JAVA_MODULE_DOES_NOT_DEPEND_ON_MODULE")
7+
package com.almasb.fxgl.particle
8+
9+
import com.almasb.fxgl.entity.Entity
10+
import com.almasb.fxgl.entity.GameWorld
11+
import com.almasb.fxgl.entity.component.ComponentHelper
12+
import org.hamcrest.CoreMatchers.`is`
13+
import org.hamcrest.MatcherAssert.assertThat
14+
import org.junit.jupiter.api.Assertions.assertNotNull
15+
import org.junit.jupiter.api.Assertions.assertNull
16+
import org.junit.jupiter.api.BeforeEach
17+
import org.junit.jupiter.api.Test
18+
19+
/**
20+
*
21+
* @author Jean-Rene Lavoie ([email protected])
22+
*/
23+
class ParticleComponentTest {
24+
25+
private lateinit var world: GameWorld
26+
private lateinit var particle: ParticleComponent
27+
28+
@BeforeEach
29+
fun setUp() {
30+
world = GameWorld()
31+
particle = ParticleComponent(ParticleEmitter())
32+
}
33+
34+
@Test
35+
fun `Create ParticleComponent with zIndex`() {
36+
assertNull(particle.entity)
37+
assertNotNull(particle.parent)
38+
assertThat(particle.parent.zIndex, `is`(0))
39+
40+
val e = Entity()
41+
e.zIndex = 100
42+
43+
ComponentHelper.setEntity(particle, e)
44+
world.addEntity(e)
45+
particle.onAdded()
46+
particle.onUpdate(1.0)
47+
48+
assertThat(particle.parent.zIndex, `is`(100))
49+
50+
e.zIndex = 200
51+
particle.onUpdate(1.0)
52+
53+
assertThat(particle.parent.zIndex, `is`(100))
54+
}
55+
56+
}

0 commit comments

Comments
 (0)