Animated particles in Phaser

In this tutorial, we will create animated particles in phaser. The phaser official site has examples for most of the things that we can do. However it lacks an example on animated particles. So we are going to explore it. It is as simple as creating a custom class for the particle with animation.

Phaser is an excellent html5 game library which is actively developed. It is one of the most cross device compatible engines out there. Earlier I posted a tutorial on creating a concentration game on phaser. It explains extending phaser sprite class, using phaser custom signals etc.

We will be creating this. Tap anywhere to create particles.

Phaser particle emitter is a class which emits particles. We will extend the Phaser particle class and add animations to it.

We are going to use this coin.png spritesheet.


Creating custom Particle class

Create a custom coin particle class like this.

var CoinParticle = (function () {
    var CoinParticle = function (game,x,y) {,game,x,y,'coin');
    CoinParticle.prototype = Object.create(Phaser.Particle.prototype);
    CoinParticle.prototype.constructor = CoinParticle;

    CoinParticle.prototype.onEmit = function () {
        this.animations.getAnimation('rotate').frame = Math.floor(Math.random() * this.animations.getAnimation('rotate').frameTotal);

    return CoinParticle;

There is an onEmit method which will run when an emitter emits this particle. In that method, we play the animation. The last line in that method will jump the animation frame to a random frame, so every particle animation don’t look the same.

Phaser Particle class is extended from the Phaser Sprite class. So everything that works on a Sprite will also work on Particles.

In the scene, we will create particles like this.

var AnimatedParticles = {};
AnimatedParticles.Boot = function (game) {

AnimatedParticles.Boot.prototype = {
    preload: function () {"coin","images/coin.png",16,16,12);

    create: function () {,this);//Create particles on tap position
    createParticle:function (pointer,doubleTap) {
        var emitter =,pointer.y,200);

        emitter.width = 10;

        emitter.particleClass = CoinParticle;
        emitter.gravity = 200;


That’s it and you can tap anywhere and it will create particles there. The above code is not optimized enough to be used on a game. You may need to destroy all the emitters manually. You can check the phaser examples website to learn more. Thanks for reading.

Also Read:   Godot Engine game tutorial for beginners – Create a 2D Racing Game 4
[Total: 3    Average: 1.3/5]