Phaser.Button = function (game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame){ x = x || 0; y = y || 0; key = key || null ; callback = callback || null ; callbackContext = callbackContext || this; Phaser.Sprite.call(this, game, x, y, key, outFrame); this.type = Phaser.BUTTON; this._onOverFrameName = null ; this._onOutFrameName = null ; this._onDownFrameName = null ; this._onUpFrameName = null ; this._onOverFrameID = null ; this._onOutFrameID = null ; this._onDownFrameID = null ; this._onUpFrameID = null ; this.onInputOver = new Phaser.Signal(); this.onInputOut = new Phaser.Signal(); this.onInputDown = new Phaser.Signal(); this.onInputUp = new Phaser.Signal(); this.setFrames(overFrame, outFrame, downFrame); if (callback !== null ) { this.onInputUp.add(callback, callbackContext); } this.freezeFrames = false ; this.input.start(0, true ); this.events.onInputOver.add(this.onInputOverHandler, this); this.events.onInputOut.add(this.onInputOutHandler, this); this.events.onInputDown.add(this.onInputDownHandler, this); this.events.onInputUp.add(this.onInputUpHandler, this); } ; Phaser.Button.prototype = Phaser.Utils.extend(true , Phaser.Sprite.prototype, PIXI.Sprite.prototype); Phaser.Button.prototype.constructor = Phaser.Button; Phaser.Button.prototype.setFrames = function (overFrame, outFrame, downFrame){ if (overFrame !== null ) { if (typeof overFrame === 'string') { this._onOverFrameName = overFrame; if (this.input.pointerOver()) { this.frameName = overFrame; } } else { this._onOverFrameID = overFrame; if (this.input.pointerOver()) { this.frame = overFrame; } } } if (outFrame !== null ) { if (typeof outFrame === 'string') { this._onOutFrameName = outFrame; this._onUpFrameName = outFrame; if (this.input.pointerOver() == false ) { this.frameName = outFrame; } } else { this._onOutFrameID = outFrame; this._onUpFrameID = outFrame; if (this.input.pointerOver() == false ) { this.frame = outFrame; } } } if (downFrame !== null ) { if (typeof downFrame === 'string') { this._onDownFrameName = downFrame; if (this.input.pointerOver()) { this.frameName = downFrame; } } else { this._onDownFrameID = downFrame; if (this.input.pointerOver()) { this.frame = downFrame; } } } } ; Phaser.Button.prototype.onInputOverHandler = function (pointer){ if (this.freezeFrames == false ) { if (this._onOverFrameName != null ) { this.frameName = this._onOverFrameName; } else if (this._onOverFrameID != null ) { this.frame = this._onOverFrameID; } } if (this.onInputOver) { this.onInputOver.dispatch(this, pointer); } } ; Phaser.Button.prototype.onInputOutHandler = function (pointer){ if (this.freezeFrames == false ) { if (this._onOutFrameName != null ) { this.frameName = this._onOutFrameName; } else if (this._onOutFrameID != null ) { this.frame = this._onOutFrameID; } } if (this.onInputOut) { this.onInputOut.dispatch(this, pointer); } } ; Phaser.Button.prototype.onInputDownHandler = function (pointer){ if (this.freezeFrames == false ) { if (this._onDownFrameName != null ) { this.frameName = this._onDownFrameName; } else if (this._onDownFrameID != null ) { this.frame = this._onDownFrameID; } } if (this.onInputDown) { this.onInputDown.dispatch(this, pointer); } } ; Phaser.Button.prototype.onInputUpHandler = function (pointer){ if (this.freezeFrames == false ) { if (this._onUpFrameName != null ) { this.frameName = this._onUpFrameName; } else if (this._onUpFrameID != null ) { this.frame = this._onUpFrameID; } } if (this.onInputUp) { this.onInputUp.dispatch(this, pointer); } } ;