Home » Various » Inheritance with phaser.js

Inheritance with phaser.js

Today’s short one to celebrate moving from dev.kofun to main domain – only code snippet, no further explanations.
How to make subclass for pharser.js class?

Let’s make subclass of Sprite, and call it Ghost.

function Ghost(game, args){
	Phaser.Sprite.call(this, game, args);

// Add Sprite object prototype as Ghost prototype
Ghost.prototype = Object.create(Phaser.Sprite.prototype);
Ghost.prototype.constructor = Ghost;

And we use it like:

var tmpGhost = new Ghost(game);

// and add it to game like this:
Posted in Various and tagged as , ,

Comments are closed.