From 98c8ddfa9b658032bd81e9639a2d7273a91e8dd8 Mon Sep 17 00:00:00 2001 From: Yuval Peress Date: Tue, 28 Mar 2017 14:43:02 -0400 Subject: [PATCH] Add ability to add a custom initializer. This is needed in cases where a particle system's initializer needs to be updated on the fly (such as from a sensor listener). Prior to this a new ParticleSystem would have to be created or extra initializers would have to be added. Since the extra initializers simply override the previous initialization, they bloat memory. Fixes #75 --- .../java/com/plattysoft/leonids/ParticleSystem.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/LeonidsLib/src/main/java/com/plattysoft/leonids/ParticleSystem.java b/LeonidsLib/src/main/java/com/plattysoft/leonids/ParticleSystem.java index 0e15b8d..992d5c3 100644 --- a/LeonidsLib/src/main/java/com/plattysoft/leonids/ParticleSystem.java +++ b/LeonidsLib/src/main/java/com/plattysoft/leonids/ParticleSystem.java @@ -363,6 +363,19 @@ public ParticleSystem setAccelerationModuleAndAndAngleRange(float minAcceleratio return this; } + /** + * Adds a custom initializer for emitted particles. The most common use case is the ability to + * update the initializer in real-time instead of adding new ones ontop of the existing one. + * @param initializer The non-null initializer to add. + * @return This. + */ + public ParticleSystem addInitializer(ParticleInitializer initializer) { + if (initializer != null) { + mInitializers.add(initializer); + } + return this; + } + /** * Initializes the acceleration for emitted particles with the given angle. Acceleration is * measured in pixels per square millisecond. The angle is measured in degrees with 0°