Skip to content

Commit f3b52e3

Browse files
NexaCore168MaTJ
andauthored
feat: added a particle callback function that will be executed when the particle is removed
--------- Co-authored-by: MaTJ <tengjiao.ma@weimob.com>
1 parent a7a00e3 commit f3b52e3

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

fxgl-entity/src/main/java/com/almasb/fxgl/particle/ParticleEmitter.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,22 @@ public void setParametricEquation(Function<Double, Point2D> parametricEquation)
249249
this.parametricEquation = parametricEquation;
250250
}
251251

252-
private Supplier<Point2D> accelerationFunction = () -> Point2D.ZERO;
252+
private Consumer<Particle> onRemoveFunction = particle -> {};
253253

254+
public Consumer<Particle> getOnRemoveFunction() {
255+
return onRemoveFunction;
256+
}
257+
258+
/**
259+
*
260+
* @param onRemoveFunction this function is executed when the particle is removed
261+
*/
262+
public void setOnRemoveFunction(Consumer<Particle> onRemoveFunction) {
263+
this.onRemoveFunction = onRemoveFunction;
264+
}
265+
266+
private Supplier<Point2D> accelerationFunction = () -> Point2D.ZERO;
267+
254268
/**
255269
*
256270
* @return gravity function

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ open class ParticleComponent(val emitter: ParticleEmitter) : Component() {
4646
val p = iter.next()
4747

4848
if (p.update(tpf)) {
49+
emitter.getOnRemoveFunction().accept(p)
4950
iter.remove()
5051

5152
parent.viewComponent.removeChild(p.view)
@@ -77,4 +78,4 @@ open class ParticleComponent(val emitter: ParticleEmitter) : Component() {
7778
}
7879

7980
override fun isComponentInjectionRequired(): Boolean = false
80-
}
81+
}

0 commit comments

Comments
 (0)