From 41d702b4855573c282b14f4865f202b7196b3283 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Sun, 12 Jul 2015 11:56:25 +0100 Subject: [PATCH] Pointer.isUp and isDown are now set in the updateButtons method based on the state of ANY button on the device, jsdocs also updated to reflect this (#1902) --- src/input/MSPointer.js | 3 ++- src/input/Mouse.js | 32 +++++--------------------------- src/input/Pointer.js | 30 +++++++++++++++++++----------- 3 files changed, 26 insertions(+), 39 deletions(-) diff --git a/src/input/MSPointer.js b/src/input/MSPointer.js index 7259a9c49..4d0bc003e 100644 --- a/src/input/MSPointer.js +++ b/src/input/MSPointer.js @@ -10,7 +10,8 @@ * It will work only in Internet Explorer 10 and Windows Store or Windows Phone 8 apps using JavaScript. * http://msdn.microsoft.com/en-us/library/ie/hh673557(v=vs.85).aspx * -* You should not normally access this class directly, but instead use a Phaser.Pointer object which normalises all game input for you. +* You should not normally access this class directly, but instead use a Phaser.Pointer object which +* normalises all game input for you including accurate button handling. * * @class Phaser.MSPointer * @constructor diff --git a/src/input/Mouse.js b/src/input/Mouse.js index dd132dd67..e382963ad 100644 --- a/src/input/Mouse.js +++ b/src/input/Mouse.js @@ -7,10 +7,12 @@ /** * The Mouse class is responsible for handling all aspects of mouse interaction with the browser. * -* It captures and processes mouse events that happen on the game canvas object. It also adds a single `mouseup` listener to `window` which -* is used to capture the mouse being released when not over the game. +* It captures and processes mouse events that happen on the game canvas object. +* It also adds a single `mouseup` listener to `window` which is used to capture the mouse being released +* when not over the game. * -* You should not normally access this class directly, but instead use a Phaser.Pointer object which normalises all game input for you. +* You should not normally access this class directly, but instead use a Phaser.Pointer object +* which normalises all game input for you, including accurate button handling. * * @class Phaser.Mouse * @constructor @@ -149,30 +151,6 @@ Phaser.Mouse = function (game) { }; -/** -* @constant -* @type {number} -*/ -Phaser.Mouse.NO_BUTTON = -1; - -/** -* @constant -* @type {number} -*/ -Phaser.Mouse.LEFT_BUTTON = 0; - -/** -* @constant -* @type {number} -*/ -Phaser.Mouse.MIDDLE_BUTTON = 1; - -/** -* @constant -* @type {number} -*/ -Phaser.Mouse.RIGHT_BUTTON = 2; - /** * @constant * @type {number} diff --git a/src/input/Pointer.js b/src/input/Pointer.js index 278047ad8..d562e7dbe 100644 --- a/src/input/Pointer.js +++ b/src/input/Pointer.js @@ -210,13 +210,13 @@ Phaser.Pointer = function (game, id) { this.isMouse = false; /** - * @property {boolean} isDown - If the Pointer is touching the touchscreen, or the mouse button is held down, isDown is set to true. + * @property {boolean} isDown - If the Pointer is touching the touchscreen, or *any* mouse button is held down, isDown is set to true. * @default */ this.isDown = false; /** - * @property {boolean} isUp - If the Pointer is not touching the touchscreen, or the mouse button is up, isUp is set to true. + * @property {boolean} isUp - If the Pointer is not touching the touchscreen, or *all* mouse buttons are up, isUp is set to true. * @default */ this.isUp = true; @@ -381,6 +381,9 @@ Phaser.Pointer.prototype = { this.forwardButton = false; this.eraserButton = false; + this.isUp = true; + this.isDown = false; + }, /** @@ -416,6 +419,15 @@ Phaser.Pointer.prototype = { this.rightButton = true; } + this.isUp = true; + this.isDown = false; + + if (this.leftButton || this.rightButton || this.middleButton || this.backButton || this.forwardButton || this.eraserButton) + { + this.isUp = false; + this.isDown = true; + } + }, /** @@ -438,8 +450,6 @@ Phaser.Pointer.prototype = { this._history = []; this.active = true; this.withinGame = true; - this.isDown = true; - this.isUp = false; this.dirty = false; this._clickTrampolines = null; this._trampolineTargetObject = null; @@ -791,8 +801,6 @@ Phaser.Pointer.prototype = { } this.withinGame = false; - this.isDown = false; - this.isUp = true; this.pointerId = null; this.identifier = null; @@ -844,7 +852,7 @@ Phaser.Pointer.prototype = { duration = duration || this.game.input.justReleasedRate; - return (this.isUp === true && (this.timeUp + duration) > this.game.time.time); + return (this.isUp && (this.timeUp + duration) > this.game.time.time); }, @@ -936,8 +944,6 @@ Phaser.Pointer.prototype = { this.pointerId = null; this.identifier = null; this.dirty = false; - this.isDown = false; - this.isUp = true; this.totalTouches = 0; this._holdSent = false; this._history.length = 0; @@ -970,9 +976,11 @@ Phaser.Pointer.prototype = { Phaser.Pointer.prototype.constructor = Phaser.Pointer; /** -* How long the Pointer has been depressed on the touchscreen. If not currently down it returns -1. +* How long the Pointer has been depressed on the touchscreen or *any* of the mouse buttons have been held down. +* If not currently down it returns -1. +* * @name Phaser.Pointer#duration -* @property {number} duration - How long the Pointer has been depressed on the touchscreen. If not currently down it returns -1. +* @property {number} duration * @readonly */ Object.defineProperty(Phaser.Pointer.prototype, "duration", {