Skip to content

Instantly share code, notes, and snippets.

@pixelhijack
Created October 4, 2016 19:30
Show Gist options
  • Save pixelhijack/b95ecd8c4dd8a45ad1b2867e24f63ecd to your computer and use it in GitHub Desktop.
Save pixelhijack/b95ecd8c4dd8a45ad1b2867e24f63ecd to your computer and use it in GitHub Desktop.
[Phaser.js] Extended / custom sprites which listens to events
function Lizardman(game, x, y, sprite){
this.game = game;
Phaser.Sprite.call(this, game, x, y, sprite);
this.game.add.existing(this);
this.game.physics.enable(this, Phaser.Physics.ARCADE);
this.anchor.setTo(0.5, 0.5);
}
Lizardman.prototype = Object.create(Phaser.Sprite.prototype);
Lizardman.prototype.constructor = Lizardman;
Lizardman.prototype.update = function(eventSource, callback){
// will be called in every gamestate.update phase
};
Lizardman.prototype.listen = function(eventSource, callback){
// as Phaser's Signal.add has so weird signature for me this is a convenience method
eventSource.add(callback, this);
};
Lizardman.prototype.onEventHappenz = function(event){
console.log('do something', event);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment