Skip to content

Commit a5c8b25

Browse files
committed
Merge pull request phaserjs#167 from wKLV/dev
Mouse now knows what button is clicked
2 parents c1d60d7 + 8678373 commit a5c8b25

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

src/input/Mouse.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ Phaser.Mouse = function (game) {
4141
* @default
4242
*/
4343
this.mouseUpCallback = null;
44+
/**
45+
* @property {Description} mouseTypeDown - The type of click. -1 for not clicking
46+
* @default
47+
*/
48+
this.mouseTypeDown = -1;
4449

4550
/**
4651
* You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
@@ -58,6 +63,11 @@ Phaser.Mouse = function (game) {
5863

5964
};
6065

66+
/**
67+
* @constant
68+
* @type {number}
69+
*/
70+
Phaser.Mouse.NO_BUTTON = -1;
6171
/**
6272
* @constant
6373
* @type {number}
@@ -76,6 +86,7 @@ Phaser.Mouse.MIDDLE_BUTTON = 1;
7686
*/
7787
Phaser.Mouse.RIGHT_BUTTON = 2;
7888

89+
7990
Phaser.Mouse.prototype = {
8091

8192
/**
@@ -119,6 +130,10 @@ Phaser.Mouse.prototype = {
119130

120131
event.preventDefault();
121132

133+
if (event.which === 1) this.mouseTypeDown = Phaser.Mouse.LEFT_BUTTON;
134+
else if (event.which === 2) this.mouseTypeDown = Phaser.Mouse.MIDDLE_BUTTON;
135+
else if (event.which === 3) this.mouseTypeDown = Phaser.Mouse.RIGHT_BUTTON;
136+
122137
if (this.mouseDownCallback)
123138
{
124139
this.mouseDownCallback.call(this.callbackContext, event);
@@ -169,6 +184,8 @@ Phaser.Mouse.prototype = {
169184

170185
event.preventDefault();
171186

187+
this.mouseTypeDown = Phaser.Mouse.NO_BUTTON;
188+
172189
if (this.mouseUpCallback)
173190
{
174191
this.mouseUpCallback.call(this.callbackContext, event);
@@ -262,4 +279,4 @@ Phaser.Mouse.prototype = {
262279

263280
}
264281

265-
};
282+
};

0 commit comments

Comments
 (0)