Animated 2D Sprites with ParticleEmitter

Hello,
I find really easy to use ParticleEmitter for 2D sprite animation. The only thing missing is the ability to control the Particle.imageIndex for supporting sprite sheets containing more than one animation in the same image.
Currently the behaviour is that Particle.imageIndex is running from 0 to X*Y assuming the sprite sheet contains one animation.

So I thought of extending ParticleEmitter and overriding:
protected void updateParticle(Particle p, float tpf, Vector3f min, Vector3f max)

to control the Particle.imageIndex strategy.
What do you think - is that a good path to go?

Thanks,
Adi

So… you are using a particle emitter not to emit particles but just to hack to do 2D sprite animation?

My recommendation is that you either write an actual 2D sprite animation control or look around for the few that have already been posted here. I think some were even advanced enough to support batching, etc…

1 Like

Hello,
There is a good piece of text on this topic in the “cook book”:
[https://www.packtpub.com/game-development/jmonkeyengine-30-cookbook]
It explains the use of ParticleEmitter, ParticleInfluencer and something called BirdAnimationControl (or similar name). The example shows you how to control a flock of birds which are flapping in the sky above.

So, basically what you’d do for your case (more than one animation for particles):
a) - extend any of the 3 classes above and use all 3 of them in conjunction with your particle system
b)* - it should contain a memory (collection or array) or some kind of modulo operation
->
The memory or modulo (b) will be needed to save the state of the animation (which particle is currently doing which animation).

Happy coding! :slight_smile:

EDIT: for animated 2D sprites (not particles with more than one animation) - do what pspeed said…

1 Like

Thank you guys. What is considered as the best (most comprehensive) 2D Animation package for JME3?