Skip to content

Commit 5a23b77

Browse files
committed
Merge pull request phaserjs#1257 from pnstickne/wip-1191
Input "enabled/disabled" API and documentation consistency updates
2 parents 65618a7 + 84363d9 commit 5a23b77

7 files changed

Lines changed: 156 additions & 40 deletions

File tree

src/input/Gamepad.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
*/
66

77
/**
8-
* The Gamepad class handles looking after gamepad input for your game.
9-
* Remember to call gamepad.start(); expecting input!
8+
* The Gamepad class handles gamepad input and dispatches gamepad events.
9+
*
10+
* Remember to call `gamepad.start()`.
1011
*
1112
* HTML5 GAMEPAD API SUPPORT IS AT AN EXPERIMENTAL STAGE!
1213
* At moment of writing this (end of 2013) only Chrome supports parts of it out of the box. Firefox supports it
@@ -44,11 +45,11 @@ Phaser.Gamepad = function (game) {
4445
this._active = false;
4546

4647
/**
47-
* You can disable all Gamepad Input by setting disabled to true. While true all new input related events will be ignored.
48-
* @property {boolean} disabled - The disabled state of the Gamepad.
48+
* Gamepad input will only be processed if enabled.
49+
* @property {boolean} enabled
4950
* @default
5051
*/
51-
this.disabled = false;
52+
this.enabled = true;
5253

5354
/**
5455
* Whether or not gamepads are supported in the current browser. Note that as of Dec. 2013 this check is actually not accurate at all due to poor implementation.
@@ -482,6 +483,24 @@ Phaser.Gamepad.prototype = {
482483

483484
Phaser.Gamepad.prototype.constructor = Phaser.Gamepad;
484485

486+
/**
487+
* If disabled all Gamepad input will be ignored.
488+
* @property {boolean} disabled
489+
* @memberof Phaser.Gamepad
490+
* @default false
491+
* @deprecated Use {@link Phaser.Gamepad#enabled} instead
492+
*/
493+
Object.defineProperty(Phaser.Gamepad.prototype, "disabled", {
494+
495+
get: function () {
496+
return !this.enabled;
497+
},
498+
set: function (value) {
499+
this.enabled = !value;
500+
}
501+
502+
});
503+
485504
/**
486505
* If the gamepad input is active or not - if not active it should not be updated from Input.js
487506
* @name Phaser.Gamepad#active

src/input/Input.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@ Phaser.Input = function (game) {
5353
this.pollRate = 0;
5454

5555
/**
56-
* You can disable all Input by setting Input.disabled = true. While set all new input related events will be ignored.
57-
* If you need to disable just one type of input; for example mouse; use Input.mouse.disabled = true instead
58-
* @property {boolean} disabled
56+
* When enabled, input (eg. Keyboard, Mouse, Touch) will be processed - as long as the individual sources are enabled themselves.
57+
*
58+
* When not enabled, _all_ input sources are ignored. To disable just one type of input; for example, the Mouse, use `input.mouse.enabled = false`.
59+
* @property {boolean} enabled
5960
* @default
6061
*/
61-
this.disabled = false;
62+
this.enabled = true;
6263

6364
/**
6465
* @property {number} multiInputOverride - Controls the expected behaviour when using a mouse and touch together on a multi-input device.
@@ -985,3 +986,22 @@ Object.defineProperty(Phaser.Input.prototype, "worldY", {
985986
}
986987

987988
});
989+
990+
/**
991+
* _All_ input sources (eg. Mouse, Keyboard, Touch) are ignored when Input is disabled.
992+
* To disable just one type of input; for example, the Mouse, use `input.mouse.enabled = false`.
993+
* @property {boolean} disabled
994+
* @memberof Phaser.Input
995+
* @default false
996+
* @deprecated Use {@link Phaser.Input#enabled} instead
997+
*/
998+
Object.defineProperty(Phaser.Input.prototype, "disabled", {
999+
1000+
get: function () {
1001+
return !this.enabled;
1002+
},
1003+
set: function (value) {
1004+
this.enabled = !value;
1005+
}
1006+
1007+
});

src/input/Keyboard.js

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
*/
66

77
/**
8-
* The Keyboard class handles looking after keyboard input for your game.
9-
* It will recognise and respond to key presses and dispatch the required events.
10-
* Please be aware that lots of keyboards are unable to process certain combinations of keys due to hardware
8+
* The Keyboard class monitors keyboard input and dispatches keyboard events.
9+
*
10+
* _Be aware_ that many keyboards are unable to process certain combinations of keys due to hardware
1111
* limitations known as ghosting. Full details here: http://www.html5gamedevs.com/topic/4876-impossible-to-use-more-than-2-keyboard-input-buttons-at-the-same-time/
1212
*
1313
* @class Phaser.Keyboard
@@ -22,11 +22,11 @@ Phaser.Keyboard = function (game) {
2222
this.game = game;
2323

2424
/**
25-
* You can disable all Keyboard Input by setting disabled to true. While true all new input related events will be ignored.
26-
* @property {boolean} disabled - The disabled state of the Keyboard.
25+
* Keyboard input will only be processed if enabled.
26+
* @property {boolean} enabled
2727
* @default
2828
*/
29-
this.disabled = false;
29+
this.enabled = true;
3030

3131
/**
3232
* @property {Object} event - The most recent DOM event from keydown or keyup. This is updated every time a new key is pressed or released.
@@ -342,7 +342,7 @@ Phaser.Keyboard.prototype = {
342342

343343
this.event = event;
344344

345-
if (this.game.input.disabled || this.disabled)
345+
if (!this.game.input.enabled || !this.enabled)
346346
{
347347
return;
348348
}
@@ -380,7 +380,7 @@ Phaser.Keyboard.prototype = {
380380

381381
this.pressEvent = event;
382382

383-
if (this.game.input.disabled || this.disabled)
383+
if (!this.game.input.enabled || !this.enabled)
384384
{
385385
return;
386386
}
@@ -403,7 +403,7 @@ Phaser.Keyboard.prototype = {
403403

404404
this.event = event;
405405

406-
if (this.game.input.disabled || this.disabled)
406+
if (!this.game.input.enabled || !this.enabled)
407407
{
408408
return;
409409
}
@@ -517,6 +517,24 @@ Phaser.Keyboard.prototype = {
517517

518518
};
519519

520+
/**
521+
* If disabled all Keyboard input will be ignored.
522+
* @property {boolean} disabled
523+
* @memberof Phaser.Keyboard
524+
* @default false
525+
* @deprecated Use {@link Phaser.Keyboard#enabled} instead
526+
*/
527+
Object.defineProperty(Phaser.Keyboard.prototype, "disabled", {
528+
529+
get: function () {
530+
return !this.enabled;
531+
},
532+
set: function (value) {
533+
this.enabled = !value;
534+
}
535+
536+
});
537+
520538
/**
521539
* Returns the string value of the most recently pressed key.
522540
* @name Phaser.Keyboard#lastChar

src/input/MSPointer.js

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
*/
66

77
/**
8-
* The MSPointer class handles touch interactions with the game and the resulting Pointer objects.
8+
* The MSPointer class handles Microsoft touch interactions with the game and the resulting Pointer objects.
9+
*
910
* It will work only in Internet Explorer 10 and Windows Store or Windows Phone 8 apps using JavaScript.
1011
* http://msdn.microsoft.com/en-us/library/ie/hh673557(v=vs.85).aspx
1112
*
@@ -26,10 +27,11 @@ Phaser.MSPointer = function (game) {
2627
this.callbackContext = this.game;
2728

2829
/**
29-
* You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
30-
* @property {boolean} disabled
30+
* MSPointer input will only be processed if enabled.
31+
* @property {boolean} enabled
32+
* @default
3133
*/
32-
this.disabled = false;
34+
this.enabled = true;
3335

3436
/**
3537
* @property {function} _onMSPointerDown - Internal function to handle MSPointer events.
@@ -104,7 +106,7 @@ Phaser.MSPointer.prototype = {
104106
*/
105107
onPointerDown: function (event) {
106108

107-
if (this.game.input.disabled || this.disabled)
109+
if (!this.game.input.enabled || !this.enabled)
108110
{
109111
return;
110112
}
@@ -123,7 +125,7 @@ Phaser.MSPointer.prototype = {
123125
*/
124126
onPointerMove: function (event) {
125127

126-
if (this.game.input.disabled || this.disabled)
128+
if (!this.game.input.enabled || !this.enabled)
127129
{
128130
return;
129131
}
@@ -142,7 +144,7 @@ Phaser.MSPointer.prototype = {
142144
*/
143145
onPointerUp: function (event) {
144146

145-
if (this.game.input.disabled || this.disabled)
147+
if (!this.game.input.enabled || !this.enabled)
146148
{
147149
return;
148150
}
@@ -173,3 +175,21 @@ Phaser.MSPointer.prototype = {
173175
};
174176

175177
Phaser.MSPointer.prototype.constructor = Phaser.MSPointer;
178+
179+
/**
180+
* If disabled all MSPointer input will be ignored.
181+
* @property {boolean} disabled
182+
* @memberof Phaser.MSPointer
183+
* @default false
184+
* @deprecated Use {@link Phaser.MSPointer#enabled} instead
185+
*/
186+
Object.defineProperty(Phaser.MSPointer.prototype, "disabled", {
187+
188+
get: function () {
189+
return !this.enabled;
190+
},
191+
set: function (value) {
192+
this.enabled = !value;
193+
}
194+
195+
});

src/input/Mouse.js

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
*/
66

77
/**
8-
* Phaser.Mouse is responsible for handling all aspects of mouse interaction with the browser.
8+
* The Mouse class is responsible for handling all aspects of mouse interaction with the browser.
9+
*
910
* It captures and processes mouse events that happen on the game canvas object. It also adds a single `mouseup` listener to `window` which
1011
* is used to capture the mouse being released when not over the game.
1112
*
@@ -72,10 +73,11 @@ Phaser.Mouse = function (game) {
7273
this.wheelDelta = 0;
7374

7475
/**
75-
* @property {boolean} disabled - You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
76+
* Mouse input will only be processed if enabled.
77+
* @property {boolean} enabled
7678
* @default
7779
*/
78-
this.disabled = false;
80+
this.enabled = true;
7981

8082
/**
8183
* @property {boolean} locked - If the mouse has been Pointer Locked successfully this will be set to true.
@@ -261,7 +263,7 @@ Phaser.Mouse.prototype = {
261263
this.mouseDownCallback.call(this.callbackContext, event);
262264
}
263265

264-
if (this.game.input.disabled || this.disabled)
266+
if (!this.game.input.enabled || !this.enabled)
265267
{
266268
return;
267269
}
@@ -291,7 +293,7 @@ Phaser.Mouse.prototype = {
291293
this.mouseMoveCallback.call(this.callbackContext, event);
292294
}
293295

294-
if (this.game.input.disabled || this.disabled)
296+
if (!this.game.input.enabled || !this.enabled)
295297
{
296298
return;
297299
}
@@ -323,7 +325,7 @@ Phaser.Mouse.prototype = {
323325
this.mouseUpCallback.call(this.callbackContext, event);
324326
}
325327

326-
if (this.game.input.disabled || this.disabled)
328+
if (!this.game.input.enabled || !this.enabled)
327329
{
328330
return;
329331
}
@@ -380,7 +382,7 @@ Phaser.Mouse.prototype = {
380382
this.mouseOutCallback.call(this.callbackContext, event);
381383
}
382384

383-
if (this.game.input.disabled || this.disabled)
385+
if (!this.game.input.enabled || !this.enabled)
384386
{
385387
return;
386388
}
@@ -441,7 +443,7 @@ Phaser.Mouse.prototype = {
441443
this.mouseOverCallback.call(this.callbackContext, event);
442444
}
443445

444-
if (this.game.input.disabled || this.disabled)
446+
if (!this.game.input.enabled || !this.enabled)
445447
{
446448
return;
447449
}
@@ -543,3 +545,21 @@ Phaser.Mouse.prototype = {
543545
};
544546

545547
Phaser.Mouse.prototype.constructor = Phaser.Mouse;
548+
549+
/**
550+
* If disabled all Mouse input will be ignored.
551+
* @property {boolean} disabled
552+
* @memberof Phaser.Mouse
553+
* @default false
554+
* @deprecated Use {@link Phaser.Mouse#enabled} instead
555+
*/
556+
Object.defineProperty(Phaser.Mouse.prototype, "disabled", {
557+
558+
get: function () {
559+
return !this.enabled;
560+
},
561+
set: function (value) {
562+
this.enabled = !value;
563+
}
564+
565+
});

src/input/SinglePad.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ Phaser.SinglePad.prototype = {
168168
*/
169169
pollStatus: function () {
170170

171-
if (!this.connected || this.game.input.disabled || this.game.input.gamepad.disabled || (this._rawPad.timestamp && (this._rawPad.timestamp === this._prevTimestamp)))
171+
if (!this.connected || !this.game.input.enabled || !this.game.input.gamepad.enabled || (this._rawPad.timestamp && (this._rawPad.timestamp === this._prevTimestamp)))
172172
{
173173
return;
174174
}

0 commit comments

Comments
 (0)