2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2019-01-15 16:20:22 +00:00
|
|
|
* @copyright 2019 Photon Storm Ltd.
|
2019-05-10 15:15:04 +00:00
|
|
|
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
2018-02-12 16:01:20 +00:00
|
|
|
*/
|
|
|
|
|
2018-11-26 13:11:24 +00:00
|
|
|
var Angle = require('../math/angle/Between');
|
2017-07-13 16:21:37 +00:00
|
|
|
var Class = require('../utils/Class');
|
2018-09-12 00:03:56 +00:00
|
|
|
var Distance = require('../math/distance/DistanceBetween');
|
2018-11-23 19:06:59 +00:00
|
|
|
var FuzzyEqual = require('../math/fuzzy/Equal');
|
2018-07-11 11:34:00 +00:00
|
|
|
var SmoothStepInterpolation = require('../math/interpolation/SmoothStepInterpolation');
|
2017-11-23 01:44:58 +00:00
|
|
|
var Vector2 = require('../math/Vector2');
|
2017-07-13 16:21:37 +00:00
|
|
|
|
2018-02-07 15:27:21 +00:00
|
|
|
/**
|
|
|
|
* @classdesc
|
2018-06-04 14:19:11 +00:00
|
|
|
* A Pointer object encapsulates both mouse and touch input within Phaser.
|
|
|
|
*
|
|
|
|
* By default, Phaser will create 2 pointers for your game to use. If you require more, i.e. for a multi-touch
|
|
|
|
* game, then use the `InputPlugin.addPointer` method to do so, rather than instantiating this class directly,
|
|
|
|
* otherwise it won't be managed by the input system.
|
|
|
|
*
|
|
|
|
* You can reference the current active pointer via `InputPlugin.activePointer`. You can also use the properties
|
|
|
|
* `InputPlugin.pointer1` through to `pointer10`, for each pointer you have enabled in your game.
|
|
|
|
*
|
|
|
|
* The properties of this object are set by the Input Plugin during processing. This object is then sent in all
|
|
|
|
* input related events that the Input Plugin emits, so you can reference properties from it directly in your
|
|
|
|
* callbacks.
|
2018-02-07 15:27:21 +00:00
|
|
|
*
|
|
|
|
* @class Pointer
|
2018-10-10 09:49:13 +00:00
|
|
|
* @memberof Phaser.Input
|
2018-02-07 15:27:21 +00:00
|
|
|
* @constructor
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-04 14:19:11 +00:00
|
|
|
* @param {Phaser.Input.InputManager} manager - A reference to the Input Manager.
|
|
|
|
* @param {integer} id - The internal ID of this Pointer.
|
2018-02-07 15:27:21 +00:00
|
|
|
*/
|
2017-07-13 16:21:37 +00:00
|
|
|
var Pointer = new Class({
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
2017-07-21 02:39:55 +00:00
|
|
|
function Pointer (manager, id)
|
2017-07-13 16:21:37 +00:00
|
|
|
{
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
2018-06-04 14:19:11 +00:00
|
|
|
* A reference to the Input Manager.
|
2018-01-26 12:43:34 +00:00
|
|
|
*
|
2018-02-13 01:13:12 +00:00
|
|
|
* @name Phaser.Input.Pointer#manager
|
|
|
|
* @type {Phaser.Input.InputManager}
|
2018-01-26 12:43:34 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-13 16:21:37 +00:00
|
|
|
this.manager = manager;
|
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
2018-06-04 14:19:11 +00:00
|
|
|
* The internal ID of this Pointer.
|
2018-01-26 12:43:34 +00:00
|
|
|
*
|
2018-02-13 01:13:12 +00:00
|
|
|
* @name Phaser.Input.Pointer#id
|
|
|
|
* @type {integer}
|
2018-10-09 12:40:00 +00:00
|
|
|
* @readonly
|
2018-01-26 12:43:34 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-21 02:39:55 +00:00
|
|
|
this.id = id;
|
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
2018-06-04 14:19:11 +00:00
|
|
|
* The most recent native DOM Event this Pointer has processed.
|
2018-01-26 12:43:34 +00:00
|
|
|
*
|
2018-02-13 01:13:12 +00:00
|
|
|
* @name Phaser.Input.Pointer#event
|
2018-06-04 14:19:11 +00:00
|
|
|
* @type {(TouchEvent|MouseEvent)}
|
2018-01-26 12:43:34 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-18 01:36:45 +00:00
|
|
|
this.event;
|
|
|
|
|
2018-11-29 13:44:18 +00:00
|
|
|
/**
|
|
|
|
* The DOM element the Pointer was pressed down on, taken from the DOM event.
|
2019-05-28 15:57:08 +00:00
|
|
|
* In a default set-up this will be the Canvas that Phaser is rendering to, or the Window element.
|
2018-11-29 13:44:18 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Input.Pointer#downElement
|
|
|
|
* @type {any}
|
|
|
|
* @readonly
|
|
|
|
* @since 3.16.0
|
|
|
|
*/
|
|
|
|
this.downElement;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The DOM element the Pointer was released on, taken from the DOM event.
|
2019-05-28 15:57:08 +00:00
|
|
|
* In a default set-up this will be the Canvas that Phaser is rendering to, or the Window element.
|
2018-11-29 13:44:18 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Input.Pointer#upElement
|
|
|
|
* @type {any}
|
|
|
|
* @readonly
|
|
|
|
* @since 3.16.0
|
|
|
|
*/
|
|
|
|
this.upElement;
|
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
|
|
|
* The camera the Pointer interacted with during its last update.
|
2018-06-04 14:19:11 +00:00
|
|
|
*
|
2018-01-26 12:43:34 +00:00
|
|
|
* A Pointer can only ever interact with one camera at once, which will be the top-most camera
|
|
|
|
* in the list should multiple cameras be positioned on-top of each other.
|
|
|
|
*
|
2018-02-13 01:13:12 +00:00
|
|
|
* @name Phaser.Input.Pointer#camera
|
|
|
|
* @type {Phaser.Cameras.Scene2D.Camera}
|
2018-01-26 12:43:34 +00:00
|
|
|
* @default null
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-29 00:55:17 +00:00
|
|
|
this.camera = null;
|
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
|
|
|
* 0: No button or un-initialized
|
|
|
|
* 1: Left button
|
|
|
|
* 2: Right button
|
|
|
|
* 4: Wheel button or middle button
|
|
|
|
* 8: 4th button (typically the "Browser Back" button)
|
|
|
|
* 16: 5th button (typically the "Browser Forward" button)
|
2018-06-04 14:19:11 +00:00
|
|
|
*
|
|
|
|
* For a mouse configured for left-handed use, the button actions are reversed.
|
|
|
|
* In this case, the values are read from right to left.
|
2018-01-26 12:43:34 +00:00
|
|
|
*
|
2018-02-13 01:13:12 +00:00
|
|
|
* @name Phaser.Input.Pointer#buttons
|
2018-06-04 14:19:11 +00:00
|
|
|
* @type {integer}
|
2018-01-26 12:43:34 +00:00
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-25 11:33:53 +00:00
|
|
|
this.buttons = 0;
|
2017-07-17 22:38:43 +00:00
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
2018-06-04 14:19:11 +00:00
|
|
|
* The position of the Pointer in screen space.
|
2018-01-26 12:43:34 +00:00
|
|
|
*
|
2018-02-13 01:13:12 +00:00
|
|
|
* @name Phaser.Input.Pointer#position
|
|
|
|
* @type {Phaser.Math.Vector2}
|
2018-11-26 11:27:02 +00:00
|
|
|
* @readonly
|
2018-01-26 12:43:34 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-23 01:44:58 +00:00
|
|
|
this.position = new Vector2();
|
2017-07-13 16:21:37 +00:00
|
|
|
|
2018-07-11 11:34:00 +00:00
|
|
|
/**
|
|
|
|
* The previous position of the Pointer in screen space.
|
|
|
|
*
|
|
|
|
* The old x and y values are stored in here during the InputManager.transformPointer call.
|
|
|
|
*
|
2018-11-26 11:27:02 +00:00
|
|
|
* Use the properties `velocity`, `angle` and `distance` to create your own gesture recognition.
|
2018-07-11 11:34:00 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Input.Pointer#prevPosition
|
|
|
|
* @type {Phaser.Math.Vector2}
|
2018-11-26 11:27:02 +00:00
|
|
|
* @readonly
|
2018-07-11 11:34:00 +00:00
|
|
|
* @since 3.11.0
|
2018-11-24 12:47:19 +00:00
|
|
|
*/
|
2018-07-11 11:34:00 +00:00
|
|
|
this.prevPosition = new Vector2();
|
2018-11-24 12:47:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* An internal vector used for calculations of the pointer speed and angle.
|
|
|
|
*
|
|
|
|
* @name Phaser.Input.Pointer#midPoint
|
|
|
|
* @type {Phaser.Math.Vector2}
|
|
|
|
* @private
|
|
|
|
* @since 3.16.0
|
2018-11-23 19:06:59 +00:00
|
|
|
*/
|
2018-11-26 11:27:02 +00:00
|
|
|
this.midPoint = new Vector2(-1, -1);
|
2018-07-11 11:34:00 +00:00
|
|
|
|
2018-11-20 17:03:22 +00:00
|
|
|
/**
|
2018-11-26 11:27:02 +00:00
|
|
|
* The current velocity of the Pointer, based on its current and previous positions.
|
2018-11-20 17:03:22 +00:00
|
|
|
*
|
2018-11-26 11:27:02 +00:00
|
|
|
* This value is smoothed out each frame, according to the `motionFactor` property.
|
2018-11-20 17:03:22 +00:00
|
|
|
*
|
2018-11-26 11:27:02 +00:00
|
|
|
* This property is updated whenever the Pointer moves, regardless of any button states. In other words,
|
|
|
|
* it changes based on movement alone - a button doesn't have to be pressed first.
|
2018-11-20 17:03:22 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Input.Pointer#velocity
|
|
|
|
* @type {Phaser.Math.Vector2}
|
2018-11-26 11:27:02 +00:00
|
|
|
* @readonly
|
2018-11-20 17:03:22 +00:00
|
|
|
* @since 3.16.0
|
|
|
|
*/
|
|
|
|
this.velocity = new Vector2();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The current angle the Pointer is moving, in radians, based on its previous and current position.
|
|
|
|
*
|
2018-11-26 15:42:53 +00:00
|
|
|
* The angle is based on the old position facing to the current position.
|
|
|
|
*
|
2018-11-26 11:27:02 +00:00
|
|
|
* This property is updated whenever the Pointer moves, regardless of any button states. In other words,
|
|
|
|
* it changes based on movement alone - a button doesn't have to be pressed first.
|
2018-11-20 17:03:22 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Input.Pointer#angle
|
|
|
|
* @type {number}
|
2018-11-26 11:27:02 +00:00
|
|
|
* @readonly
|
2018-11-20 17:03:22 +00:00
|
|
|
* @since 3.16.0
|
|
|
|
*/
|
2018-11-26 15:42:53 +00:00
|
|
|
this.angle = 0;
|
2018-11-20 17:03:22 +00:00
|
|
|
|
2018-11-26 11:27:02 +00:00
|
|
|
/**
|
|
|
|
* The distance the Pointer has moved, based on its previous and current position.
|
|
|
|
*
|
|
|
|
* This value is smoothed out each frame, according to the `motionFactor` property.
|
|
|
|
*
|
|
|
|
* This property is updated whenever the Pointer moves, regardless of any button states. In other words,
|
|
|
|
* it changes based on movement alone - a button doesn't have to be pressed first.
|
|
|
|
*
|
|
|
|
* If you need the total distance travelled since the primary buttons was pressed down,
|
|
|
|
* then use the `Pointer.getDistance` method.
|
|
|
|
*
|
|
|
|
* @name Phaser.Input.Pointer#distance
|
|
|
|
* @type {number}
|
|
|
|
* @readonly
|
|
|
|
* @since 3.16.0
|
|
|
|
*/
|
2018-11-24 13:04:14 +00:00
|
|
|
this.distance = 0;
|
|
|
|
|
2018-11-19 15:30:42 +00:00
|
|
|
/**
|
|
|
|
* The smoothing factor to apply to the Pointer position.
|
|
|
|
*
|
|
|
|
* Due to their nature, pointer positions are inherently noisy. While this is fine for lots of games, if you need cleaner positions
|
|
|
|
* then you can set this value to apply an automatic smoothing to the positions as they are recorded.
|
|
|
|
*
|
|
|
|
* The default value of zero means 'no smoothing'.
|
2018-11-26 11:27:02 +00:00
|
|
|
* Set to a small value, such as 0.2, to apply an average level of smoothing between positions. You can do this by changing this
|
|
|
|
* value directly, or by setting the `input.smoothFactor` property in the Game Config.
|
2018-11-19 15:30:42 +00:00
|
|
|
*
|
2018-11-26 11:27:02 +00:00
|
|
|
* Positions are only smoothed when the pointer moves. If the primary button on this Pointer enters an Up or Down state, then the position
|
|
|
|
* is always precise, and not smoothed.
|
2018-11-19 15:30:42 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Input.Pointer#smoothFactor
|
|
|
|
* @type {number}
|
2018-11-24 12:52:20 +00:00
|
|
|
* @default 0
|
2018-11-19 15:30:42 +00:00
|
|
|
* @since 3.16.0
|
|
|
|
*/
|
|
|
|
this.smoothFactor = 0;
|
|
|
|
|
2018-11-24 12:52:20 +00:00
|
|
|
/**
|
|
|
|
* The factor applied to the motion smoothing each frame.
|
|
|
|
*
|
2018-11-26 11:27:02 +00:00
|
|
|
* This value is passed to the Smooth Step Interpolation that is used to calculate the velocity,
|
|
|
|
* angle and distance of the Pointer. It's applied every frame, until the midPoint reaches the current
|
2018-11-24 12:52:20 +00:00
|
|
|
* position of the Pointer. 0.2 provides a good average but can be increased if you need a
|
|
|
|
* quicker update and are working in a high performance environment. Never set this value to
|
|
|
|
* zero.
|
|
|
|
*
|
|
|
|
* @name Phaser.Input.Pointer#motionFactor
|
|
|
|
* @type {number}
|
|
|
|
* @default 0.2
|
|
|
|
* @since 3.16.0
|
|
|
|
*/
|
|
|
|
this.motionFactor = 0.2;
|
|
|
|
|
2018-06-04 12:23:27 +00:00
|
|
|
/**
|
|
|
|
* The x position of this Pointer, translated into the coordinate space of the most recent Camera it interacted with.
|
|
|
|
*
|
|
|
|
* @name Phaser.Input.Pointer#worldX
|
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.10.0
|
|
|
|
*/
|
|
|
|
this.worldX = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The y position of this Pointer, translated into the coordinate space of the most recent Camera it interacted with.
|
|
|
|
*
|
|
|
|
* @name Phaser.Input.Pointer#worldY
|
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.10.0
|
|
|
|
*/
|
|
|
|
this.worldY = 0;
|
|
|
|
|
2018-11-23 19:06:59 +00:00
|
|
|
/**
|
|
|
|
* Time when this Pointer was most recently moved (regardless of the state of its buttons, if any)
|
|
|
|
*
|
|
|
|
* @name Phaser.Input.Pointer#moveTime
|
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
this.moveTime = 0;
|
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
|
|
|
* X coordinate of the Pointer when Button 1 (left button), or Touch, was pressed, used for dragging objects.
|
|
|
|
*
|
2018-02-13 01:13:12 +00:00
|
|
|
* @name Phaser.Input.Pointer#downX
|
|
|
|
* @type {number}
|
2018-01-26 12:43:34 +00:00
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-27 02:40:58 +00:00
|
|
|
this.downX = 0;
|
2018-01-26 12:43:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Y coordinate of the Pointer when Button 1 (left button), or Touch, was pressed, used for dragging objects.
|
|
|
|
*
|
2018-02-13 01:13:12 +00:00
|
|
|
* @name Phaser.Input.Pointer#downY
|
|
|
|
* @type {number}
|
2018-01-26 12:43:34 +00:00
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-27 02:40:58 +00:00
|
|
|
this.downY = 0;
|
2018-01-26 12:43:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Time when Button 1 (left button), or Touch, was pressed, used for dragging objects.
|
|
|
|
*
|
2018-02-13 01:13:12 +00:00
|
|
|
* @name Phaser.Input.Pointer#downTime
|
|
|
|
* @type {number}
|
2018-01-26 12:43:34 +00:00
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-27 02:40:58 +00:00
|
|
|
this.downTime = 0;
|
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
|
|
|
* X coordinate of the Pointer when Button 1 (left button), or Touch, was released, used for dragging objects.
|
|
|
|
*
|
2018-02-13 01:13:12 +00:00
|
|
|
* @name Phaser.Input.Pointer#upX
|
|
|
|
* @type {number}
|
2018-01-26 12:43:34 +00:00
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-27 02:40:58 +00:00
|
|
|
this.upX = 0;
|
2018-01-26 12:43:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Y coordinate of the Pointer when Button 1 (left button), or Touch, was released, used for dragging objects.
|
|
|
|
*
|
2018-02-13 01:13:12 +00:00
|
|
|
* @name Phaser.Input.Pointer#upY
|
|
|
|
* @type {number}
|
2018-01-26 12:43:34 +00:00
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-27 02:40:58 +00:00
|
|
|
this.upY = 0;
|
2018-01-26 12:43:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Time when Button 1 (left button), or Touch, was released, used for dragging objects.
|
|
|
|
*
|
2018-02-13 01:13:12 +00:00
|
|
|
* @name Phaser.Input.Pointer#upTime
|
|
|
|
* @type {number}
|
2018-01-26 12:43:34 +00:00
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-27 02:40:58 +00:00
|
|
|
this.upTime = 0;
|
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
|
|
|
* Is the primary button down? (usually button 0, the left mouse button)
|
|
|
|
*
|
2018-02-13 01:13:12 +00:00
|
|
|
* @name Phaser.Input.Pointer#primaryDown
|
|
|
|
* @type {boolean}
|
2018-01-26 12:43:34 +00:00
|
|
|
* @default false
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-27 02:40:58 +00:00
|
|
|
this.primaryDown = false;
|
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
|
|
|
* Is _any_ button on this pointer considered as being down?
|
|
|
|
*
|
2018-02-13 01:13:12 +00:00
|
|
|
* @name Phaser.Input.Pointer#isDown
|
|
|
|
* @type {boolean}
|
2018-01-26 12:43:34 +00:00
|
|
|
* @default false
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-13 16:21:37 +00:00
|
|
|
this.isDown = false;
|
2017-07-14 00:38:21 +00:00
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
|
|
|
* Did the previous input event come from a Touch input (true) or Mouse? (false)
|
|
|
|
*
|
2018-02-13 01:13:12 +00:00
|
|
|
* @name Phaser.Input.Pointer#wasTouch
|
|
|
|
* @type {boolean}
|
2018-01-26 12:43:34 +00:00
|
|
|
* @default false
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2018-01-08 09:58:17 +00:00
|
|
|
this.wasTouch = false;
|
|
|
|
|
2018-10-16 10:42:54 +00:00
|
|
|
/**
|
2018-10-16 14:23:36 +00:00
|
|
|
* Did this Pointer get canceled by a touchcancel event?
|
|
|
|
*
|
|
|
|
* Note: "canceled" is the American-English spelling of "cancelled". Please don't submit PRs correcting it!
|
2018-10-16 10:42:54 +00:00
|
|
|
*
|
2018-10-16 14:23:36 +00:00
|
|
|
* @name Phaser.Input.Pointer#wasCanceled
|
2018-10-16 10:42:54 +00:00
|
|
|
* @type {boolean}
|
|
|
|
* @default false
|
|
|
|
* @since 3.15.0
|
|
|
|
*/
|
2018-10-16 14:23:36 +00:00
|
|
|
this.wasCanceled = false;
|
2018-10-16 10:42:54 +00:00
|
|
|
|
2017-12-08 23:05:05 +00:00
|
|
|
/**
|
2018-01-26 12:43:34 +00:00
|
|
|
* If the mouse is locked, the horizontal relative movement of the Pointer in pixels since last frame.
|
|
|
|
*
|
2018-02-13 01:13:12 +00:00
|
|
|
* @name Phaser.Input.Pointer#movementX
|
|
|
|
* @type {number}
|
2018-01-26 12:43:34 +00:00
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
2017-12-08 23:05:05 +00:00
|
|
|
*/
|
|
|
|
this.movementX = 0;
|
|
|
|
|
|
|
|
/**
|
2018-01-26 12:43:34 +00:00
|
|
|
* If the mouse is locked, the vertical relative movement of the Pointer in pixels since last frame.
|
|
|
|
*
|
2018-02-13 01:13:12 +00:00
|
|
|
* @name Phaser.Input.Pointer#movementY
|
|
|
|
* @type {number}
|
2018-01-26 12:43:34 +00:00
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
2017-12-08 23:05:05 +00:00
|
|
|
*/
|
|
|
|
this.movementY = 0;
|
2018-05-25 18:28:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The identifier property of the Pointer as set by the DOM event when this Pointer is started.
|
|
|
|
*
|
|
|
|
* @name Phaser.Input.Pointer#identifier
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.10.0
|
|
|
|
*/
|
|
|
|
this.identifier = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The pointerId property of the Pointer as set by the DOM event when this Pointer is started.
|
|
|
|
* The browser can and will recycle this value.
|
|
|
|
*
|
|
|
|
* @name Phaser.Input.Pointer#pointerId
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.10.0
|
|
|
|
*/
|
|
|
|
this.pointerId = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An active Pointer is one that is currently pressed down on the display.
|
|
|
|
* A Mouse is always considered as active.
|
|
|
|
*
|
|
|
|
* @name Phaser.Input.Pointer#active
|
|
|
|
* @type {boolean}
|
|
|
|
* @since 3.10.0
|
|
|
|
*/
|
|
|
|
this.active = (id === 0) ? true : false;
|
2018-11-23 19:06:59 +00:00
|
|
|
|
2018-11-26 13:11:24 +00:00
|
|
|
/**
|
2019-05-23 16:18:49 +00:00
|
|
|
* Time when this Pointer was most recently updated by a DOM Event.
|
2018-11-26 13:11:24 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Input.Pointer#time
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.16.0
|
|
|
|
*/
|
|
|
|
this.time = 0;
|
2017-07-14 00:38:21 +00:00
|
|
|
},
|
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
2018-06-04 14:19:11 +00:00
|
|
|
* Takes a Camera and returns a Vector2 containing the translated position of this Pointer
|
|
|
|
* within that Camera. This can be used to convert this Pointers position into camera space.
|
2018-01-26 12:43:34 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Input.Pointer#positionToCamera
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-04 14:19:11 +00:00
|
|
|
* @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera to use for the translation.
|
|
|
|
* @param {(Phaser.Math.Vector2|object)} [output] - A Vector2-like object in which to store the translated position.
|
2018-01-26 12:43:34 +00:00
|
|
|
*
|
2018-06-04 14:19:11 +00:00
|
|
|
* @return {(Phaser.Math.Vector2|object)} A Vector2 containing the translated coordinates of this Pointer, based on the given camera.
|
2018-01-26 12:43:34 +00:00
|
|
|
*/
|
2017-11-28 11:16:35 +00:00
|
|
|
positionToCamera: function (camera, output)
|
|
|
|
{
|
2018-01-04 15:21:48 +00:00
|
|
|
return camera.getWorldPoint(this.x, this.y, output);
|
2017-11-28 11:16:35 +00:00
|
|
|
},
|
|
|
|
|
2018-11-24 12:47:19 +00:00
|
|
|
/**
|
|
|
|
* Calculates the motion of this Pointer, including its velocity and angle of movement.
|
|
|
|
* This method is called automatically each frame by the Input Manager.
|
|
|
|
*
|
|
|
|
* @method Phaser.Input.Pointer#updateMotion
|
|
|
|
* @private
|
|
|
|
* @since 3.16.0
|
|
|
|
*/
|
|
|
|
updateMotion: function ()
|
2018-11-23 19:06:59 +00:00
|
|
|
{
|
2018-11-24 12:47:19 +00:00
|
|
|
var cx = this.position.x;
|
|
|
|
var cy = this.position.y;
|
2018-11-23 19:06:59 +00:00
|
|
|
|
2018-11-26 11:27:02 +00:00
|
|
|
var mx = this.midPoint.x;
|
|
|
|
var my = this.midPoint.y;
|
|
|
|
|
|
|
|
if (cx === mx && cy === my)
|
|
|
|
{
|
|
|
|
// Nothing to do here
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-24 12:47:19 +00:00
|
|
|
// Moving towards our goal ...
|
2018-11-26 11:27:02 +00:00
|
|
|
var vx = SmoothStepInterpolation(this.motionFactor, mx, cx);
|
|
|
|
var vy = SmoothStepInterpolation(this.motionFactor, my, cy);
|
2018-11-23 19:06:59 +00:00
|
|
|
|
2018-11-24 12:47:19 +00:00
|
|
|
if (FuzzyEqual(vx, cx, 0.1))
|
2018-11-23 19:06:59 +00:00
|
|
|
{
|
2018-11-24 12:47:19 +00:00
|
|
|
vx = cx;
|
2018-11-23 19:06:59 +00:00
|
|
|
}
|
|
|
|
|
2018-11-24 12:47:19 +00:00
|
|
|
if (FuzzyEqual(vy, cy, 0.1))
|
2018-11-23 19:06:59 +00:00
|
|
|
{
|
2018-11-24 12:47:19 +00:00
|
|
|
vy = cy;
|
2018-11-23 19:06:59 +00:00
|
|
|
}
|
|
|
|
|
2018-11-24 12:47:19 +00:00
|
|
|
this.midPoint.set(vx, vy);
|
2018-11-23 19:06:59 +00:00
|
|
|
|
2018-11-24 13:04:14 +00:00
|
|
|
var dx = cx - vx;
|
|
|
|
var dy = cy - vy;
|
|
|
|
|
|
|
|
this.velocity.set(dx, dy);
|
|
|
|
|
2018-11-26 15:42:53 +00:00
|
|
|
this.angle = Angle(vx, vy, cx, cy);
|
2018-11-23 19:06:59 +00:00
|
|
|
|
2018-11-24 13:04:14 +00:00
|
|
|
this.distance = Math.sqrt(dx * dx + dy * dy);
|
2018-11-23 19:06:59 +00:00
|
|
|
},
|
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
2018-06-04 14:19:11 +00:00
|
|
|
* Internal method to handle a Mouse Up Event.
|
2018-01-26 12:43:34 +00:00
|
|
|
*
|
2018-05-29 15:55:52 +00:00
|
|
|
* @method Phaser.Input.Pointer#up
|
2018-06-04 14:19:11 +00:00
|
|
|
* @private
|
2018-01-26 12:43:34 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-04 14:19:11 +00:00
|
|
|
* @param {MouseEvent} event - The Mouse Event to process.
|
2018-01-26 12:43:34 +00:00
|
|
|
*/
|
2019-05-23 16:18:49 +00:00
|
|
|
up: function (event)
|
2017-07-28 02:28:10 +00:00
|
|
|
{
|
2019-01-23 23:00:29 +00:00
|
|
|
if ('buttons' in event)
|
2018-05-29 15:55:52 +00:00
|
|
|
{
|
|
|
|
this.buttons = event.buttons;
|
|
|
|
}
|
|
|
|
|
2017-07-28 02:28:10 +00:00
|
|
|
this.event = event;
|
|
|
|
|
2018-11-29 13:44:18 +00:00
|
|
|
this.upElement = event.target;
|
|
|
|
|
2018-06-04 14:19:11 +00:00
|
|
|
// Sets the local x/y properties
|
2018-11-19 15:30:42 +00:00
|
|
|
this.manager.transformPointer(this, event.pageX, event.pageY, false);
|
2017-07-28 02:28:10 +00:00
|
|
|
|
2018-05-29 15:55:52 +00:00
|
|
|
// 0: Main button pressed, usually the left button or the un-initialized state
|
|
|
|
if (event.button === 0)
|
|
|
|
{
|
|
|
|
this.primaryDown = false;
|
|
|
|
this.upX = this.x;
|
|
|
|
this.upY = this.y;
|
2019-05-28 15:57:08 +00:00
|
|
|
this.upTime = event.timeStamp;
|
2018-05-29 15:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.isDown = false;
|
2017-07-28 02:28:10 +00:00
|
|
|
|
2018-05-29 15:55:52 +00:00
|
|
|
this.wasTouch = false;
|
2017-07-28 02:28:10 +00:00
|
|
|
},
|
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
2018-06-04 14:19:11 +00:00
|
|
|
* Internal method to handle a Mouse Down Event.
|
2018-01-26 12:43:34 +00:00
|
|
|
*
|
2018-05-29 15:55:52 +00:00
|
|
|
* @method Phaser.Input.Pointer#down
|
2018-06-04 14:19:11 +00:00
|
|
|
* @private
|
2018-01-26 12:43:34 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-04 14:19:11 +00:00
|
|
|
* @param {MouseEvent} event - The Mouse Event to process.
|
2018-01-26 12:43:34 +00:00
|
|
|
*/
|
2019-05-23 16:18:49 +00:00
|
|
|
down: function (event)
|
2017-07-13 16:21:37 +00:00
|
|
|
{
|
2019-01-23 23:00:29 +00:00
|
|
|
if ('buttons' in event)
|
2017-07-17 22:38:43 +00:00
|
|
|
{
|
2017-07-25 11:33:53 +00:00
|
|
|
this.buttons = event.buttons;
|
2017-07-17 22:38:43 +00:00
|
|
|
}
|
2017-07-14 00:38:21 +00:00
|
|
|
|
2017-07-18 01:36:45 +00:00
|
|
|
this.event = event;
|
2017-07-14 00:38:21 +00:00
|
|
|
|
2018-11-29 13:44:18 +00:00
|
|
|
this.downElement = event.target;
|
|
|
|
|
2018-06-04 14:19:11 +00:00
|
|
|
// Sets the local x/y properties
|
2018-11-19 15:30:42 +00:00
|
|
|
this.manager.transformPointer(this, event.pageX, event.pageY, false);
|
2017-07-17 22:38:43 +00:00
|
|
|
|
2018-05-29 15:55:52 +00:00
|
|
|
// 0: Main button pressed, usually the left button or the un-initialized state
|
|
|
|
if (event.button === 0)
|
2017-12-08 23:05:05 +00:00
|
|
|
{
|
2018-05-29 15:55:52 +00:00
|
|
|
this.primaryDown = true;
|
|
|
|
this.downX = this.x;
|
|
|
|
this.downY = this.y;
|
2019-05-28 15:57:08 +00:00
|
|
|
this.downTime = event.timeStamp;
|
2017-12-08 23:05:05 +00:00
|
|
|
}
|
|
|
|
|
2018-05-29 15:55:52 +00:00
|
|
|
this.isDown = true;
|
2017-07-18 16:22:14 +00:00
|
|
|
|
2018-01-08 09:58:17 +00:00
|
|
|
this.wasTouch = false;
|
2017-07-14 00:38:21 +00:00
|
|
|
},
|
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
2018-06-04 14:19:11 +00:00
|
|
|
* Internal method to handle a Mouse Move Event.
|
2018-01-26 12:43:34 +00:00
|
|
|
*
|
2018-05-29 15:55:52 +00:00
|
|
|
* @method Phaser.Input.Pointer#move
|
2018-06-04 14:19:11 +00:00
|
|
|
* @private
|
2018-01-26 12:43:34 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-04 14:19:11 +00:00
|
|
|
* @param {MouseEvent} event - The Mouse Event to process.
|
2018-01-26 12:43:34 +00:00
|
|
|
*/
|
2019-05-23 16:18:49 +00:00
|
|
|
move: function (event)
|
2017-07-14 00:38:21 +00:00
|
|
|
{
|
2019-01-23 23:17:52 +00:00
|
|
|
if ('buttons' in event)
|
2017-07-18 01:36:45 +00:00
|
|
|
{
|
2017-07-25 11:33:53 +00:00
|
|
|
this.buttons = event.buttons;
|
2017-07-18 01:36:45 +00:00
|
|
|
}
|
2017-07-14 00:38:21 +00:00
|
|
|
|
2017-07-18 01:36:45 +00:00
|
|
|
this.event = event;
|
|
|
|
|
2018-06-04 14:19:11 +00:00
|
|
|
// Sets the local x/y properties
|
2018-11-19 15:30:42 +00:00
|
|
|
this.manager.transformPointer(this, event.pageX, event.pageY, true);
|
2017-07-18 01:36:45 +00:00
|
|
|
|
2018-05-29 15:55:52 +00:00
|
|
|
if (this.manager.mouse.locked)
|
2017-07-27 02:40:58 +00:00
|
|
|
{
|
2019-05-28 15:57:08 +00:00
|
|
|
// Multiple DOM events may occur within one frame, but only one Phaser event will fire
|
2018-05-29 15:55:52 +00:00
|
|
|
this.movementX += event.movementX || event.mozMovementX || event.webkitMovementX || 0;
|
|
|
|
this.movementY += event.movementY || event.mozMovementY || event.webkitMovementY || 0;
|
2017-07-27 02:40:58 +00:00
|
|
|
}
|
|
|
|
|
2019-05-28 15:57:08 +00:00
|
|
|
this.moveTime = event.timeStamp;
|
2018-01-08 09:58:17 +00:00
|
|
|
|
|
|
|
this.wasTouch = false;
|
2017-07-14 00:38:21 +00:00
|
|
|
},
|
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
2018-06-04 14:19:11 +00:00
|
|
|
* Internal method to handle a Touch Start Event.
|
2018-01-26 12:43:34 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Input.Pointer#touchstart
|
2018-06-04 14:19:11 +00:00
|
|
|
* @private
|
2018-01-26 12:43:34 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2019-06-04 14:46:16 +00:00
|
|
|
* @param {Touch} touch - The Changed Touch from the Touch Event.
|
|
|
|
* @param {TouchEvent} event - The full Touch Event.
|
2018-01-26 12:43:34 +00:00
|
|
|
*/
|
2019-06-04 14:46:16 +00:00
|
|
|
touchstart: function (touch, event)
|
2017-07-28 02:28:10 +00:00
|
|
|
{
|
2019-06-04 14:46:16 +00:00
|
|
|
if (touch['pointerId'])
|
2018-05-25 18:28:02 +00:00
|
|
|
{
|
2019-06-04 14:46:16 +00:00
|
|
|
this.pointerId = touch.pointerId;
|
2018-05-25 18:28:02 +00:00
|
|
|
}
|
|
|
|
|
2019-06-04 14:46:16 +00:00
|
|
|
this.identifier = touch.identifier;
|
|
|
|
this.target = touch.target;
|
2018-05-25 18:28:02 +00:00
|
|
|
this.active = true;
|
|
|
|
|
2017-07-28 02:28:10 +00:00
|
|
|
this.buttons = 1;
|
|
|
|
|
|
|
|
this.event = event;
|
|
|
|
|
2019-06-04 14:46:16 +00:00
|
|
|
this.downElement = touch.target;
|
2018-11-29 13:44:18 +00:00
|
|
|
|
2018-06-04 14:19:11 +00:00
|
|
|
// Sets the local x/y properties
|
2019-06-04 14:46:16 +00:00
|
|
|
this.manager.transformPointer(this, touch.pageX, touch.pageY, false);
|
2017-07-28 02:28:10 +00:00
|
|
|
|
|
|
|
this.primaryDown = true;
|
|
|
|
this.downX = this.x;
|
|
|
|
this.downY = this.y;
|
2019-06-04 14:46:16 +00:00
|
|
|
this.downTime = touch.timeStamp;
|
2017-07-28 02:28:10 +00:00
|
|
|
|
|
|
|
this.isDown = true;
|
|
|
|
|
2018-01-08 09:58:17 +00:00
|
|
|
this.wasTouch = true;
|
2018-10-16 14:23:36 +00:00
|
|
|
this.wasCanceled = false;
|
2017-07-28 02:28:10 +00:00
|
|
|
},
|
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
2018-06-04 14:19:11 +00:00
|
|
|
* Internal method to handle a Touch Move Event.
|
2018-01-26 12:43:34 +00:00
|
|
|
*
|
2018-05-29 15:55:52 +00:00
|
|
|
* @method Phaser.Input.Pointer#touchmove
|
2018-06-04 14:19:11 +00:00
|
|
|
* @private
|
2018-01-26 12:43:34 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2019-06-04 14:46:16 +00:00
|
|
|
* @param {Touch} touch - The Changed Touch from the Touch Event.
|
|
|
|
* @param {TouchEvent} event - The full Touch Event.
|
2018-01-26 12:43:34 +00:00
|
|
|
*/
|
2019-06-04 14:46:16 +00:00
|
|
|
touchmove: function (touch, event)
|
2017-07-14 00:38:21 +00:00
|
|
|
{
|
2017-07-18 01:36:45 +00:00
|
|
|
this.event = event;
|
|
|
|
|
2018-06-04 14:19:11 +00:00
|
|
|
// Sets the local x/y properties
|
2019-06-04 14:46:16 +00:00
|
|
|
this.manager.transformPointer(this, touch.pageX, touch.pageY, true);
|
2017-07-14 00:38:21 +00:00
|
|
|
|
2019-06-04 14:46:16 +00:00
|
|
|
this.moveTime = touch.timeStamp;
|
2018-01-08 09:58:17 +00:00
|
|
|
|
2018-05-29 15:55:52 +00:00
|
|
|
this.wasTouch = true;
|
2017-07-25 11:33:53 +00:00
|
|
|
},
|
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
2018-06-04 14:19:11 +00:00
|
|
|
* Internal method to handle a Touch End Event.
|
2018-01-26 12:43:34 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Input.Pointer#touchend
|
2018-06-04 14:19:11 +00:00
|
|
|
* @private
|
2018-01-26 12:43:34 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2019-06-04 14:46:16 +00:00
|
|
|
* @param {Touch} touch - The Changed Touch from the Touch Event.
|
|
|
|
* @param {TouchEvent} event - The full Touch Event.
|
2018-01-26 12:43:34 +00:00
|
|
|
*/
|
2019-06-04 14:46:16 +00:00
|
|
|
touchend: function (touch, event)
|
2017-07-28 02:28:10 +00:00
|
|
|
{
|
|
|
|
this.buttons = 0;
|
|
|
|
|
|
|
|
this.event = event;
|
|
|
|
|
2019-06-04 14:46:16 +00:00
|
|
|
this.upElement = touch.target;
|
2018-11-29 13:44:18 +00:00
|
|
|
|
2018-06-04 14:19:11 +00:00
|
|
|
// Sets the local x/y properties
|
2019-06-04 14:46:16 +00:00
|
|
|
this.manager.transformPointer(this, touch.pageX, touch.pageY, false);
|
2017-07-28 02:28:10 +00:00
|
|
|
|
|
|
|
this.primaryDown = false;
|
|
|
|
this.upX = this.x;
|
|
|
|
this.upY = this.y;
|
2019-06-04 14:46:16 +00:00
|
|
|
this.upTime = touch.timeStamp;
|
2017-07-28 02:28:10 +00:00
|
|
|
|
|
|
|
this.isDown = false;
|
|
|
|
|
2018-01-08 09:58:17 +00:00
|
|
|
this.wasTouch = true;
|
2018-10-16 14:23:36 +00:00
|
|
|
this.wasCanceled = false;
|
2018-10-16 10:42:54 +00:00
|
|
|
|
|
|
|
this.active = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal method to handle a Touch Cancel Event.
|
|
|
|
*
|
|
|
|
* @method Phaser.Input.Pointer#touchcancel
|
|
|
|
* @private
|
|
|
|
* @since 3.15.0
|
|
|
|
*
|
2019-06-04 14:46:16 +00:00
|
|
|
* @param {Touch} touch - The Changed Touch from the Touch Event.
|
|
|
|
* @param {TouchEvent} event - The full Touch Event.
|
2018-10-16 10:42:54 +00:00
|
|
|
*/
|
2019-06-04 14:46:16 +00:00
|
|
|
touchcancel: function (touch, event)
|
2018-10-16 10:42:54 +00:00
|
|
|
{
|
|
|
|
this.buttons = 0;
|
|
|
|
|
|
|
|
this.event = event;
|
|
|
|
|
2019-06-04 14:46:16 +00:00
|
|
|
this.upElement = touch.target;
|
|
|
|
|
|
|
|
// Sets the local x/y properties
|
|
|
|
this.manager.transformPointer(this, touch.pageX, touch.pageY, false);
|
|
|
|
|
2018-10-16 10:42:54 +00:00
|
|
|
this.primaryDown = false;
|
2019-06-04 14:46:16 +00:00
|
|
|
this.upX = this.x;
|
|
|
|
this.upY = this.y;
|
|
|
|
this.upTime = touch.timeStamp;
|
2018-10-16 10:42:54 +00:00
|
|
|
|
|
|
|
this.isDown = false;
|
|
|
|
|
|
|
|
this.wasTouch = true;
|
2018-10-16 14:23:36 +00:00
|
|
|
this.wasCanceled = true;
|
2018-05-25 18:28:02 +00:00
|
|
|
|
|
|
|
this.active = false;
|
2017-07-28 02:28:10 +00:00
|
|
|
},
|
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
2018-06-04 14:19:11 +00:00
|
|
|
* Checks to see if any buttons are being held down on this Pointer.
|
2018-01-26 12:43:34 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Input.Pointer#noButtonDown
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-04 14:19:11 +00:00
|
|
|
* @return {boolean} `true` if no buttons are being held down.
|
2018-01-26 12:43:34 +00:00
|
|
|
*/
|
2017-07-25 11:33:53 +00:00
|
|
|
noButtonDown: function ()
|
|
|
|
{
|
|
|
|
return (this.buttons === 0);
|
|
|
|
},
|
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
2018-06-04 14:19:11 +00:00
|
|
|
* Checks to see if the left button is being held down on this Pointer.
|
2018-01-26 12:43:34 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Input.Pointer#leftButtonDown
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-04 14:19:11 +00:00
|
|
|
* @return {boolean} `true` if the left button is being held down.
|
2018-01-26 12:43:34 +00:00
|
|
|
*/
|
2017-07-25 11:33:53 +00:00
|
|
|
leftButtonDown: function ()
|
|
|
|
{
|
2019-01-23 23:00:29 +00:00
|
|
|
return (this.buttons & 1) ? true : false;
|
2017-07-25 11:33:53 +00:00
|
|
|
},
|
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
2018-06-04 14:19:11 +00:00
|
|
|
* Checks to see if the right button is being held down on this Pointer.
|
2018-01-26 12:43:34 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Input.Pointer#rightButtonDown
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-04 14:19:11 +00:00
|
|
|
* @return {boolean} `true` if the right button is being held down.
|
2018-01-26 12:43:34 +00:00
|
|
|
*/
|
2017-07-25 11:33:53 +00:00
|
|
|
rightButtonDown: function ()
|
|
|
|
{
|
2019-01-23 23:00:29 +00:00
|
|
|
return (this.buttons & 2) ? true : false;
|
2017-07-25 11:33:53 +00:00
|
|
|
},
|
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
2018-06-04 14:19:11 +00:00
|
|
|
* Checks to see if the middle button is being held down on this Pointer.
|
2018-01-26 12:43:34 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Input.Pointer#middleButtonDown
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-04 14:19:11 +00:00
|
|
|
* @return {boolean} `true` if the middle button is being held down.
|
2018-01-26 12:43:34 +00:00
|
|
|
*/
|
2017-07-25 11:33:53 +00:00
|
|
|
middleButtonDown: function ()
|
|
|
|
{
|
2019-01-23 23:00:29 +00:00
|
|
|
return (this.buttons & 4) ? true : false;
|
2017-07-25 11:33:53 +00:00
|
|
|
},
|
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
2018-06-04 14:19:11 +00:00
|
|
|
* Checks to see if the back button is being held down on this Pointer.
|
2018-01-26 12:43:34 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Input.Pointer#backButtonDown
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-04 14:19:11 +00:00
|
|
|
* @return {boolean} `true` if the back button is being held down.
|
2018-01-26 12:43:34 +00:00
|
|
|
*/
|
2017-07-25 11:33:53 +00:00
|
|
|
backButtonDown: function ()
|
|
|
|
{
|
2019-01-23 23:00:29 +00:00
|
|
|
return (this.buttons & 8) ? true : false;
|
2017-07-25 11:33:53 +00:00
|
|
|
},
|
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
2018-06-04 14:19:11 +00:00
|
|
|
* Checks to see if the forward button is being held down on this Pointer.
|
2018-01-26 12:43:34 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Input.Pointer#forwardButtonDown
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-04 14:19:11 +00:00
|
|
|
* @return {boolean} `true` if the forward button is being held down.
|
2018-01-26 12:43:34 +00:00
|
|
|
*/
|
2017-07-25 11:33:53 +00:00
|
|
|
forwardButtonDown: function ()
|
|
|
|
{
|
2019-01-23 23:00:29 +00:00
|
|
|
return (this.buttons & 16) ? true : false;
|
2018-01-31 03:38:10 +00:00
|
|
|
},
|
|
|
|
|
2018-09-12 00:03:56 +00:00
|
|
|
/**
|
2018-11-26 13:11:24 +00:00
|
|
|
* If the Pointer has a button pressed down at the time this method is called, it will return the
|
|
|
|
* distance between the Pointer's `downX` and `downY` values and the current position.
|
|
|
|
*
|
|
|
|
* If no button is held down, it will return the last recorded distance, based on where
|
|
|
|
* the Pointer was when the button was released.
|
|
|
|
*
|
|
|
|
* If you wish to get the distance being travelled currently, based on the velocity of the Pointer,
|
|
|
|
* then see the `Pointer.distance` property.
|
2018-09-12 00:03:56 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Input.Pointer#getDistance
|
|
|
|
* @since 3.13.0
|
|
|
|
*
|
2018-11-26 13:11:24 +00:00
|
|
|
* @return {number} The distance the Pointer moved.
|
2018-09-12 00:03:56 +00:00
|
|
|
*/
|
|
|
|
getDistance: function ()
|
|
|
|
{
|
2018-11-26 13:11:24 +00:00
|
|
|
if (this.isDown)
|
|
|
|
{
|
|
|
|
return Distance(this.downX, this.downY, this.x, this.y);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return Distance(this.downX, this.downY, this.upX, this.upY);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-11-26 15:35:18 +00:00
|
|
|
/**
|
|
|
|
* If the Pointer has a button pressed down at the time this method is called, it will return the
|
|
|
|
* horizontal distance between the Pointer's `downX` and `downY` values and the current position.
|
|
|
|
*
|
|
|
|
* If no button is held down, it will return the last recorded horizontal distance, based on where
|
|
|
|
* the Pointer was when the button was released.
|
|
|
|
*
|
|
|
|
* @method Phaser.Input.Pointer#getDistanceX
|
|
|
|
* @since 3.16.0
|
|
|
|
*
|
|
|
|
* @return {number} The horizontal distance the Pointer moved.
|
|
|
|
*/
|
|
|
|
getDistanceX: function ()
|
|
|
|
{
|
|
|
|
if (this.isDown)
|
|
|
|
{
|
|
|
|
return Math.abs(this.downX - this.x);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return Math.abs(this.downX - this.upX);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If the Pointer has a button pressed down at the time this method is called, it will return the
|
|
|
|
* vertical distance between the Pointer's `downX` and `downY` values and the current position.
|
|
|
|
*
|
|
|
|
* If no button is held down, it will return the last recorded vertical distance, based on where
|
|
|
|
* the Pointer was when the button was released.
|
|
|
|
*
|
|
|
|
* @method Phaser.Input.Pointer#getDistanceY
|
|
|
|
* @since 3.16.0
|
|
|
|
*
|
|
|
|
* @return {number} The vertical distance the Pointer moved.
|
|
|
|
*/
|
|
|
|
getDistanceY: function ()
|
|
|
|
{
|
|
|
|
if (this.isDown)
|
|
|
|
{
|
|
|
|
return Math.abs(this.downY - this.y);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return Math.abs(this.downY - this.upY);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-11-26 13:11:24 +00:00
|
|
|
/**
|
|
|
|
* If the Pointer has a button pressed down at the time this method is called, it will return the
|
2019-04-24 09:08:56 +00:00
|
|
|
* duration since the button was pressed down.
|
2018-11-26 13:11:24 +00:00
|
|
|
*
|
|
|
|
* If no button is held down, it will return the last recorded duration, based on the time
|
|
|
|
* the Pointer button was released.
|
|
|
|
*
|
|
|
|
* @method Phaser.Input.Pointer#getDuration
|
|
|
|
* @since 3.16.0
|
|
|
|
*
|
|
|
|
* @return {number} The duration the Pointer was held down for in milliseconds.
|
|
|
|
*/
|
|
|
|
getDuration: function ()
|
|
|
|
{
|
|
|
|
if (this.isDown)
|
|
|
|
{
|
|
|
|
return (this.time - this.downTime);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return (this.upTime - this.downTime);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If the Pointer has a button pressed down at the time this method is called, it will return the
|
|
|
|
* angle between the Pointer's `downX` and `downY` values and the current position.
|
|
|
|
*
|
|
|
|
* If no button is held down, it will return the last recorded angle, based on where
|
|
|
|
* the Pointer was when the button was released.
|
|
|
|
*
|
2018-11-26 15:42:53 +00:00
|
|
|
* The angle is based on the old position facing to the current position.
|
|
|
|
*
|
2018-11-26 13:11:24 +00:00
|
|
|
* If you wish to get the current angle, based on the velocity of the Pointer, then
|
|
|
|
* see the `Pointer.angle` property.
|
|
|
|
*
|
|
|
|
* @method Phaser.Input.Pointer#getAngle
|
|
|
|
* @since 3.16.0
|
|
|
|
*
|
2018-11-26 15:35:18 +00:00
|
|
|
* @return {number} The angle between the Pointer's coordinates in radians.
|
2018-11-26 13:11:24 +00:00
|
|
|
*/
|
|
|
|
getAngle: function ()
|
|
|
|
{
|
|
|
|
if (this.isDown)
|
|
|
|
{
|
2018-11-26 15:42:53 +00:00
|
|
|
return Angle(this.downX, this.downY, this.x, this.y);
|
2018-11-26 13:11:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-11-26 15:42:53 +00:00
|
|
|
return Angle(this.downX, this.downY, this.upX, this.upY);
|
2018-11-26 13:11:24 +00:00
|
|
|
}
|
2018-09-12 00:03:56 +00:00
|
|
|
},
|
|
|
|
|
2018-07-11 11:34:00 +00:00
|
|
|
/**
|
|
|
|
* Takes the previous and current Pointer positions and then generates an array of interpolated values between
|
|
|
|
* the two. The array will be populated up to the size of the `steps` argument.
|
|
|
|
*
|
|
|
|
* ```javaScript
|
|
|
|
* var points = pointer.getInterpolatedPosition(4);
|
|
|
|
*
|
|
|
|
* // points[0] = { x: 0, y: 0 }
|
|
|
|
* // points[1] = { x: 2, y: 1 }
|
|
|
|
* // points[2] = { x: 3, y: 2 }
|
|
|
|
* // points[3] = { x: 6, y: 3 }
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* Use this if you need to get smoothed values between the previous and current pointer positions. DOM pointer
|
|
|
|
* events can often fire faster than the main browser loop, and this will help you avoid janky movement
|
|
|
|
* especially if you have an object following a Pointer.
|
|
|
|
*
|
|
|
|
* Note that if you provide an output array it will only be populated up to the number of steps provided.
|
|
|
|
* It will not clear any previous data that may have existed beyond the range of the steps count.
|
|
|
|
*
|
|
|
|
* Internally it uses the Smooth Step interpolation calculation.
|
|
|
|
*
|
|
|
|
* @method Phaser.Input.Pointer#getInterpolatedPosition
|
|
|
|
* @since 3.11.0
|
|
|
|
*
|
|
|
|
* @param {integer} [steps=10] - The number of interpolation steps to use.
|
|
|
|
* @param {array} [out] - An array to store the results in. If not provided a new one will be created.
|
|
|
|
*
|
|
|
|
* @return {array} An array of interpolated values.
|
|
|
|
*/
|
|
|
|
getInterpolatedPosition: function (steps, out)
|
|
|
|
{
|
|
|
|
if (steps === undefined) { steps = 10; }
|
|
|
|
if (out === undefined) { out = []; }
|
|
|
|
|
|
|
|
var prevX = this.prevPosition.x;
|
|
|
|
var prevY = this.prevPosition.y;
|
|
|
|
|
|
|
|
var curX = this.position.x;
|
|
|
|
var curY = this.position.y;
|
|
|
|
|
|
|
|
for (var i = 0; i < steps; i++)
|
|
|
|
{
|
|
|
|
var t = (1 / steps) * i;
|
|
|
|
|
|
|
|
out[i] = { x: SmoothStepInterpolation(t, prevX, curX), y: SmoothStepInterpolation(t, prevY, curY) };
|
|
|
|
}
|
|
|
|
|
|
|
|
return out;
|
|
|
|
},
|
|
|
|
|
2018-01-31 03:38:10 +00:00
|
|
|
/**
|
2018-06-04 14:19:11 +00:00
|
|
|
* Destroys this Pointer instance and resets its external references.
|
2018-01-31 03:38:10 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.Input.Pointer#destroy
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
destroy: function ()
|
|
|
|
{
|
|
|
|
this.camera = null;
|
|
|
|
this.manager = null;
|
|
|
|
this.position = null;
|
2018-05-25 18:28:02 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-06-04 14:19:11 +00:00
|
|
|
* The x position of this Pointer.
|
|
|
|
* The value is in screen space.
|
|
|
|
* See `worldX` to get a camera converted position.
|
2018-05-25 18:28:02 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Input.Pointer#x
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
x: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.position.x;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
this.position.x = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-06-04 14:19:11 +00:00
|
|
|
* The y position of this Pointer.
|
|
|
|
* The value is in screen space.
|
|
|
|
* See `worldY` to get a camera converted position.
|
2018-05-25 18:28:02 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.Input.Pointer#y
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
y: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.position.y;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
this.position.y = value;
|
|
|
|
}
|
|
|
|
|
2017-07-13 16:21:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = Pointer;
|