Skip to content

Commit 13d6ab5

Browse files
committed
Fixed the Button frame issue and Down states now work properly
1 parent 9b6c819 commit 13d6ab5

3 files changed

Lines changed: 53 additions & 44 deletions

File tree

examples/button1.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function create() {
3737
// The function "clickedIt" will be called when the button is clicked or touched
3838
button = game.add.button(game.world.centerX, 400, 'button', clickedIt, this, 2, 1, 0);
3939

40-
// Just makes the button origin set to the middle, we only do this to center the button on-screen, no other reason
40+
// Just makes the button anchor set to the middle, we only do this to center the button on-screen, no other reason
4141
button.anchor.setTo(0.5, 0.5);
4242

4343
}

src/gameobjects/Button.js

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,9 @@ Phaser.Button = function (game, x, y, key, callback, callbackContext, overFrame,
1818
key = key || null;
1919
callback = callback || null;
2020
callbackContext = callbackContext || this;
21-
overFrame = overFrame || null;
22-
outFrame = outFrame || null;
23-
downFrame = downFrame || null;
2421

2522
Phaser.Sprite.call(this, game, x, y, key, outFrame);
2623

27-
// this.texture = PIXI.TextureCache[key];
28-
2924
this._onOverFrameName = null;
3025
this._onOutFrameName = null;
3126
this._onDownFrameName = null;
@@ -35,43 +30,15 @@ Phaser.Button = function (game, x, y, key, callback, callbackContext, overFrame,
3530
this._onDownFrameID = null;
3631
this._onUpFrameID = null;
3732

38-
if (typeof overFrame == 'string')
39-
{
40-
this._onOverFrameName = overFrame;
41-
}
42-
else
43-
{
44-
this._onOverFrameID = overFrame;
45-
}
46-
47-
if (typeof outFrame == 'string')
48-
{
49-
this._onOutFrameName = outFrame;
50-
this._onUpFrameName = outFrame;
51-
}
52-
else
53-
{
54-
this._onOutFrameID = outFrame;
55-
this._onUpFrameID = outFrame;
56-
}
57-
58-
if (typeof downFrame == 'string')
59-
{
60-
this._onDownFrameName = downFrame;
61-
}
62-
else
63-
{
64-
this._onDownFrameID = downFrame;
65-
}
66-
6733
// These are the signals the game will subscribe to
68-
this.onInputOver = new Phaser.Signal();
69-
this.onInputOut = new Phaser.Signal();
70-
this.onInputDown = new Phaser.Signal();
71-
this.onInputUp = new Phaser.Signal();
34+
this.onInputOver = new Phaser.Signal;
35+
this.onInputOut = new Phaser.Signal;
36+
this.onInputDown = new Phaser.Signal;
37+
this.onInputUp = new Phaser.Signal;
38+
39+
this.setFrames(overFrame, outFrame, downFrame);
7240

73-
// Set a default signal for them
74-
if (callback)
41+
if (callback !== null)
7542
{
7643
this.onInputUp.add(callback, callbackContext);
7744
}
@@ -91,13 +58,55 @@ Phaser.Button.prototype.constructor = Phaser.Button;
9158

9259
// Add our own custom methods
9360

61+
Phaser.Button.prototype.setFrames = function (overFrame, outFrame, downFrame) {
62+
63+
if (overFrame !== null)
64+
{
65+
if (typeof overFrame === 'string')
66+
{
67+
this._onOverFrameName = overFrame;
68+
}
69+
else
70+
{
71+
this._onOverFrameID = overFrame;
72+
}
73+
}
74+
75+
if (outFrame !== null)
76+
{
77+
if (typeof outFrame === 'string')
78+
{
79+
this._onOutFrameName = outFrame;
80+
this._onUpFrameName = outFrame;
81+
}
82+
else
83+
{
84+
this._onOutFrameID = outFrame;
85+
this._onUpFrameID = outFrame;
86+
}
87+
}
88+
89+
if (downFrame !== null)
90+
{
91+
if (typeof downFrame === 'string')
92+
{
93+
this._onDownFrameName = downFrame;
94+
}
95+
else
96+
{
97+
this._onDownFrameID = downFrame;
98+
}
99+
}
100+
101+
};
102+
94103
Phaser.Button.prototype.onInputOverHandler = function (pointer) {
95104

96105
if (this._onOverFrameName != null)
97106
{
98107
this.frameName = this._onOverFrameName;
99108
}
100-
else if(this._onOverFrameID != null)
109+
else if (this._onOverFrameID != null)
101110
{
102111
this.frame = this._onOverFrameID;
103112
}

src/input/Input.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ Phaser.Input = function (game) {
88

99
this.game = game;
1010

11-
this.inputObjects = [];
12-
this.totalTrackedObjects = 0;
11+
// this.inputObjects = [];
12+
// this.totalTrackedObjects = 0;
1313

1414
};
1515

0 commit comments

Comments
 (0)