-
-
Notifications
You must be signed in to change notification settings - Fork 559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Emit particles at initial Entity zIndex instead of zIndex 0 #1319
Merged
+57
−0
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
fxgl-entity/src/test/kotlin/com/almasb/fxgl/particle/ParticleComponentTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't
particle.parent.zIndex
be 200 here, to matche.zIndex
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The particle inherits the initial Entity zIndex. The second test is to validate that the particle zIndex is then independent which allows mutating particles independently after creation (moving some over, others under).
All particles are under the same parent, this allows full control over their display position after creation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example: You have a Rain Emitter. The emitter is the "source" / "origin" spawning point. You spawn droplets and reduce their independent zIndex to emulate their position in a Parallax, for example. This means that droplets are able to show over a tree, but then it could show under the tree once it's zIndex reached the "behind the tree" value. Or even better, smoke particles generated in the air can get behind objects on the ground gradually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation. I quite like the idea of particles being under / over entities, though not sure we currently support that, given we only have 1 parent and its zIndex is fixed. Something for later discussion perhaps. As far as the issue is concerned, I think it's fixed.