From 13d6ab512b79a0b1cf11c64896f79cb055962adb Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Mon, 9 Sep 2013 10:30:01 +0100 Subject: [PATCH] Fixed the Button frame issue and Down states now work properly --- examples/button1.php | 2 +- src/gameobjects/Button.js | 91 +++++++++++++++++++++------------------ src/input/Input.js | 4 +- 3 files changed, 53 insertions(+), 44 deletions(-) diff --git a/examples/button1.php b/examples/button1.php index 2685e1af..1074da18 100644 --- a/examples/button1.php +++ b/examples/button1.php @@ -37,7 +37,7 @@ // The function "clickedIt" will be called when the button is clicked or touched button = game.add.button(game.world.centerX, 400, 'button', clickedIt, this, 2, 1, 0); - // Just makes the button origin set to the middle, we only do this to center the button on-screen, no other reason + // Just makes the button anchor set to the middle, we only do this to center the button on-screen, no other reason button.anchor.setTo(0.5, 0.5); } diff --git a/src/gameobjects/Button.js b/src/gameobjects/Button.js index d94d6afe..3e903d97 100644 --- a/src/gameobjects/Button.js +++ b/src/gameobjects/Button.js @@ -18,14 +18,9 @@ Phaser.Button = function (game, x, y, key, callback, callbackContext, overFrame, key = key || null; callback = callback || null; callbackContext = callbackContext || this; - overFrame = overFrame || null; - outFrame = outFrame || null; - downFrame = downFrame || null; Phaser.Sprite.call(this, game, x, y, key, outFrame); - // this.texture = PIXI.TextureCache[key]; - this._onOverFrameName = null; this._onOutFrameName = null; this._onDownFrameName = null; @@ -35,43 +30,15 @@ Phaser.Button = function (game, x, y, key, callback, callbackContext, overFrame, this._onDownFrameID = null; this._onUpFrameID = null; - if (typeof overFrame == 'string') - { - this._onOverFrameName = overFrame; - } - else - { - this._onOverFrameID = overFrame; - } - - if (typeof outFrame == 'string') - { - this._onOutFrameName = outFrame; - this._onUpFrameName = outFrame; - } - else - { - this._onOutFrameID = outFrame; - this._onUpFrameID = outFrame; - } - - if (typeof downFrame == 'string') - { - this._onDownFrameName = downFrame; - } - else - { - this._onDownFrameID = downFrame; - } - // These are the signals the game will subscribe to - this.onInputOver = new Phaser.Signal(); - this.onInputOut = new Phaser.Signal(); - this.onInputDown = new Phaser.Signal(); - this.onInputUp = new Phaser.Signal(); + this.onInputOver = new Phaser.Signal; + this.onInputOut = new Phaser.Signal; + this.onInputDown = new Phaser.Signal; + this.onInputUp = new Phaser.Signal; - // Set a default signal for them - if (callback) + this.setFrames(overFrame, outFrame, downFrame); + + if (callback !== null) { this.onInputUp.add(callback, callbackContext); } @@ -91,13 +58,55 @@ Phaser.Button.prototype.constructor = Phaser.Button; // Add our own custom methods +Phaser.Button.prototype.setFrames = function (overFrame, outFrame, downFrame) { + + if (overFrame !== null) + { + if (typeof overFrame === 'string') + { + this._onOverFrameName = overFrame; + } + else + { + this._onOverFrameID = overFrame; + } + } + + if (outFrame !== null) + { + if (typeof outFrame === 'string') + { + this._onOutFrameName = outFrame; + this._onUpFrameName = outFrame; + } + else + { + this._onOutFrameID = outFrame; + this._onUpFrameID = outFrame; + } + } + + if (downFrame !== null) + { + if (typeof downFrame === 'string') + { + this._onDownFrameName = downFrame; + } + else + { + this._onDownFrameID = downFrame; + } + } + +}; + Phaser.Button.prototype.onInputOverHandler = function (pointer) { if (this._onOverFrameName != null) { this.frameName = this._onOverFrameName; } - else if(this._onOverFrameID != null) + else if (this._onOverFrameID != null) { this.frame = this._onOverFrameID; } diff --git a/src/input/Input.js b/src/input/Input.js index 3d9f2cff..45077234 100644 --- a/src/input/Input.js +++ b/src/input/Input.js @@ -8,8 +8,8 @@ Phaser.Input = function (game) { this.game = game; - this.inputObjects = []; - this.totalTrackedObjects = 0; + // this.inputObjects = []; + // this.totalTrackedObjects = 0; };