“Spellfall” HTML5 prototype made with Phaser updated to 2.8.2 and reusing tweens to improve performance

With the update of Phaser CE to 2.8.2, I am updating a 3 years old prototype – Spellfall – to the latest Phaser version, adding more comments to the source code and above all reusing tweens – actually, reusing THE tween – to save memory, CPU and improve performance.

Rather than creating a new tween at every player move, we create only one tween and update its target property according to the tile to be moved.

Also, a new to method is called each time to update tween destination. Finally, to prevent multiple to calls to create “waypoints” before the final tween destination, we have to reset its timeline property to an empty array.

This is very important, as I see people asking how to “reset” a tween destination in various threads and forums.

Well, just set timeline property to an empty array.

Let’s have a look at the result:

Just drag a tile over another tile to swap them. Yes, this is the simplest approach to a “match 3″ game design.

And now, the source code with all required comments:

Using only one tween for the entire prototype is a great improvement as it will save Phaser to manage garbage collection, resulting in an overall performance improvement as well as a good practice.

Next time I will add more animations, meanwhile you can download the source code.