The particle model

Here is the dart code of our particle model:

We pass in a random generator and immediately restarting the particle. In the restart function we define start position and end position in relative screen space. (For the y-values it means 0.0 is top, 1.0 is bottom and 1.2 is 20% below the bottom. For x-values its similar.)

We use these positions to create a tween. I am using MultiTrackTween that tweens multiple properties at once. I want my x-position and y-position to be animated differently and can apply some nice easing effect.

Then we create an AnimationProgress that will supply our tween with the actual progress of our tweened animation. It takes a start time and a duration. To get the proper start time we expect someone passing the current time into our restart function.

For duration and size we can just choose some random values. Nothing special about them.

Last but not least we have a maintainRestart function that is called from outside to check if a particle needs to be restarted. It queries the AnimationProgress by calling it’s progress(time) function. It will return the progress of the animation (a value between 0.0 and 1.0 ) based on the current time, the specified start time and duration.