Fixed the Button frame issue and Down states now work properly

This commit is contained in:
Richard Davey 2013-09-09 10:30:01 +01:00
parent 9b6c819e0e
commit 13d6ab512b
3 changed files with 53 additions and 44 deletions

View file

@ -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);
}

View file

@ -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;
}

View file

@ -8,8 +8,8 @@ Phaser.Input = function (game) {
this.game = game;
this.inputObjects = [];
this.totalTrackedObjects = 0;
// this.inputObjects = [];
// this.totalTrackedObjects = 0;
};