Phaser.GamepadButton = function (pad, buttonCode){ this.pad = pad; this.game = pad.game; this.isDown = false ; this.isUp = true ; this.timeDown = 0; this.duration = 0; this.timeUp = 0; this.repeats = 0; this.value = 0; this.buttonCode = buttonCode; this.onDown = new Phaser.Signal(); this.onUp = new Phaser.Signal(); this.onFloat = new Phaser.Signal(); } ; Phaser.GamepadButton.prototype = { processButtonDown: function (value){ if (this.isDown) { this.duration = this.game.time.now - this.timeDown; this.repeats++ ; } else { this.isDown = true ; this.isUp = false ; this.timeDown = this.game.time.now; this.duration = 0; this.repeats = 0; this.value = value; this.onDown.dispatch(this, value); } } , processButtonUp: function (value){ if (this.isDown) { this.isDown = false ; this.isUp = true ; this.timeUp = this.game.time.now; this.value = value; this.onUp.dispatch(this, value); } } , processButtonFloat: function (value){ this.value = value; this.onFloat.dispatch(this, value); } , justPressed: function (duration){ if (typeof duration === "undefined") { duration = 250; } return (this.isDown && this.duration < duration); } , justReleased: function (duration){ if (typeof duration === "undefined") { duration = 250; } return (this.isDown === false && (this.game.time.now - this.timeUp < duration)); } , reset: function (){ this.isDown = false ; this.isUp = true ; this.timeDown = this.game.time.now; this.duration = 0; this.repeats = 0; } , destroy: function (){ this.onDown.dispose(); this.onUp.dispose(); this.onFloat.dispose(); this.pad = null ; this.game = null ; } } ; Phaser.GamepadButton.prototype.constructor = Phaser.GamepadButton;