Skip to content

Commit

Permalink
fix: emit particles at initial Entity zIndex instead of zIndex 0, closes
Browse files Browse the repository at this point in the history
  • Loading branch information
DeathPhoenix22 committed Mar 21, 2024
1 parent f4937ff commit 4c740dd
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
Expand Up @@ -36,6 +36,7 @@ open class ParticleComponent(val emitter: ParticleEmitter) : Component() {

override fun onUpdate(tpf: Double) {
if (parent.world == null) {
parent.zIndex = entity.zIndex
entity.world.addEntity(parent)
}

Expand Down
@@ -0,0 +1,56 @@
/*
* FXGL - JavaFX Game Library. The MIT License (MIT).
* Copyright (c) AlmasB (almaslvl@gmail.com).
* See LICENSE for details.
*/
@file:Suppress("JAVA_MODULE_DOES_NOT_DEPEND_ON_MODULE")
package com.almasb.fxgl.particle

import com.almasb.fxgl.entity.Entity
import com.almasb.fxgl.entity.GameWorld
import com.almasb.fxgl.entity.component.ComponentHelper
import org.hamcrest.CoreMatchers.`is`
import org.hamcrest.MatcherAssert.assertThat
import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test

/**
*
* @author Jean-Rene Lavoie (jeanrlavoie@gmail.com)
*/
class ParticleComponentTest {

private lateinit var world: GameWorld
private lateinit var particle: ParticleComponent

@BeforeEach
fun setUp() {
world = GameWorld()
particle = ParticleComponent(ParticleEmitter())
}

@Test
fun `Create ParticleComponent with zIndex`() {
assertNull(particle.entity)
assertNotNull(particle.parent)
assertThat(particle.parent.zIndex, `is`(0))

val e = Entity()
e.zIndex = 100

ComponentHelper.setEntity(particle, e)
world.addEntity(e)
particle.onAdded()
particle.onUpdate(1.0)

assertThat(particle.parent.zIndex, `is`(100))

e.zIndex = 200
particle.onUpdate(1.0)

assertThat(particle.parent.zIndex, `is`(100))
}

}

0 comments on commit 4c740dd

Please sign in to comment.