Created
October 4, 2016 19:30
-
-
Save pixelhijack/b95ecd8c4dd8a45ad1b2867e24f63ecd to your computer and use it in GitHub Desktop.
[Phaser.js] Extended / custom sprites which listens to events
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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