2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2018 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2017-07-13 16:21:37 +00:00
|
|
|
var Class = require('../utils/Class');
|
2017-11-23 01:44:58 +00:00
|
|
|
var Vector2 = require('../math/Vector2');
|
2017-07-13 16:21:37 +00:00
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
// DOM event button value:
|
2017-07-27 02:40:58 +00:00
|
|
|
// A number representing a given button:
|
|
|
|
// 0: Main button pressed, usually the left button or the un-initialized state
|
|
|
|
// 1: Auxiliary button pressed, usually the wheel button or the middle button (if present)
|
|
|
|
// 2: Secondary button pressed, usually the right button
|
|
|
|
// 3: Fourth button, typically the Browser Back button
|
|
|
|
// 4: Fifth button, typically the Browser Forward button
|
|
|
|
// 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-02-07 15:27:21 +00:00
|
|
|
/**
|
|
|
|
* @classdesc
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @class Pointer
|
|
|
|
* @memberOf Phaser.Input
|
|
|
|
* @constructor
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {Phaser.Input.InputManager} manager - [description]
|
|
|
|
* @param {integer} id - [description]
|
|
|
|
*/
|
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
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
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
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
2018-02-13 01:13:12 +00:00
|
|
|
* @name Phaser.Input.Pointer#id
|
|
|
|
* @type {integer}
|
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
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
2018-02-13 01:13:12 +00:00
|
|
|
* @name Phaser.Input.Pointer#event
|
|
|
|
* @type {null}
|
2018-01-26 12:43:34 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-18 01:36:45 +00:00
|
|
|
this.event;
|
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
|
|
|
* The camera the Pointer interacted with during its last update.
|
|
|
|
* 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-02-13 01:13:12 +00:00
|
|
|
* @name Phaser.Input.Pointer#buttons
|
|
|
|
* @type {number}
|
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
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
2018-02-13 01:13:12 +00:00
|
|
|
* @name Phaser.Input.Pointer#position
|
|
|
|
* @type {Phaser.Math.Vector2}
|
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-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
|
|
|
|
|
|
|
/**
|
|
|
|
* The Drag State of the Pointer:
|
|
|
|
*
|
|
|
|
* 0 = Not dragging anything
|
|
|
|
* 1 = Being checked if dragging
|
|
|
|
* 2 = Dragging something
|
|
|
|
*
|
2018-02-13 01:13:12 +00:00
|
|
|
* @name Phaser.Input.Pointer#dragState
|
|
|
|
* @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.dragState = 0;
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
2018-02-13 01:13:12 +00:00
|
|
|
* @name Phaser.Input.Pointer#dirty
|
|
|
|
* @type {boolean}
|
2018-01-26 12:43:34 +00:00
|
|
|
* @default false
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-14 00:38:21 +00:00
|
|
|
this.dirty = false;
|
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
2018-02-13 01:13:12 +00:00
|
|
|
* @name Phaser.Input.Pointer#justDown
|
|
|
|
* @type {boolean}
|
2018-01-26 12:43:34 +00:00
|
|
|
* @default false
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-14 00:38:21 +00:00
|
|
|
this.justDown = false;
|
2018-01-26 12:43:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
2018-02-13 01:13:12 +00:00
|
|
|
* @name Phaser.Input.Pointer#justUp
|
|
|
|
* @type {boolean}
|
2018-01-26 12:43:34 +00:00
|
|
|
* @default false
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-14 00:38:21 +00:00
|
|
|
this.justUp = false;
|
2018-01-26 12:43:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
2018-02-13 01:13:12 +00:00
|
|
|
* @name Phaser.Input.Pointer#justMoved
|
|
|
|
* @type {boolean}
|
2018-01-26 12:43:34 +00:00
|
|
|
* @default false
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-14 00:38:21 +00:00
|
|
|
this.justMoved = false;
|
2017-12-08 23:05:05 +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;
|
|
|
|
|
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;
|
2017-07-14 00:38:21 +00:00
|
|
|
},
|
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Input.Pointer#positionToCamera
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {[type]} camera - [description]
|
|
|
|
* @param {[type]} output - [description]
|
|
|
|
*
|
|
|
|
* @return {[type]} [description]
|
|
|
|
*/
|
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-01-26 12:43:34 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Input.Pointer#x
|
2018-02-13 01:13:12 +00:00
|
|
|
* @type {number}
|
2018-01-26 12:43:34 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-23 01:44:58 +00:00
|
|
|
x: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.position.x;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
this.position.x = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Input.Pointer#y
|
2018-02-13 01:13:12 +00:00
|
|
|
* @type {number}
|
2018-01-26 12:43:34 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-23 01:44:58 +00:00
|
|
|
y: {
|
|
|
|
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.position.y;
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value)
|
|
|
|
{
|
|
|
|
this.position.y = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Input.Pointer#reset
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-07-14 00:38:21 +00:00
|
|
|
reset: function ()
|
|
|
|
{
|
2018-01-18 00:59:38 +00:00
|
|
|
// this.buttons = 0;
|
2017-07-25 11:33:53 +00:00
|
|
|
|
2017-07-14 00:38:21 +00:00
|
|
|
this.dirty = false;
|
2018-01-18 00:59:38 +00:00
|
|
|
|
2017-07-14 00:38:21 +00:00
|
|
|
this.justDown = false;
|
|
|
|
this.justUp = false;
|
|
|
|
this.justMoved = false;
|
2018-01-18 00:59:38 +00:00
|
|
|
|
2017-12-08 23:05:05 +00:00
|
|
|
this.movementX = 0;
|
|
|
|
this.movementY = 0;
|
2017-07-13 16:21:37 +00:00
|
|
|
},
|
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Input.Pointer#touchmove
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {[type]} event - [description]
|
2018-03-18 13:43:37 +00:00
|
|
|
* @param {integer} time - The current timestamp as generated by the Request Animation Frame or SetTimeout.
|
2018-01-26 12:43:34 +00:00
|
|
|
*/
|
2018-02-16 19:08:50 +00:00
|
|
|
touchmove: function (event)
|
2017-07-28 02:28:10 +00:00
|
|
|
{
|
|
|
|
this.event = event;
|
|
|
|
|
|
|
|
this.x = this.manager.transformX(event.changedTouches[0].pageX);
|
|
|
|
this.y = this.manager.transformY(event.changedTouches[0].pageY);
|
|
|
|
|
|
|
|
this.justMoved = true;
|
|
|
|
|
|
|
|
this.dirty = true;
|
2018-01-08 09:58:17 +00:00
|
|
|
|
|
|
|
this.wasTouch = true;
|
2017-07-28 02:28:10 +00:00
|
|
|
},
|
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Input.Pointer#move
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {[type]} event - [description]
|
2018-03-18 13:43:37 +00:00
|
|
|
* @param {integer} time - The current timestamp as generated by the Request Animation Frame or SetTimeout.
|
2018-01-26 12:43:34 +00:00
|
|
|
*/
|
2018-02-16 19:08:50 +00:00
|
|
|
move: function (event)
|
2017-07-13 16:21:37 +00:00
|
|
|
{
|
2017-07-25 11:33:53 +00:00
|
|
|
if (event.buttons)
|
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
|
|
|
|
2017-07-17 22:38:43 +00:00
|
|
|
this.x = this.manager.transformX(event.pageX);
|
|
|
|
this.y = this.manager.transformY(event.pageY);
|
|
|
|
|
2017-12-08 23:05:05 +00:00
|
|
|
if (this.manager.mouse.locked)
|
|
|
|
{
|
2017-12-08 23:08:04 +00:00
|
|
|
// Multiple DOM events may occur within one frame, but only one Phaser event will fire
|
2017-12-08 23:05:05 +00:00
|
|
|
this.movementX += event.movementX || event.mozMovementX || event.webkitMovementX || 0;
|
|
|
|
this.movementY += event.movementY || event.mozMovementY || event.webkitMovementY || 0;
|
|
|
|
}
|
|
|
|
|
2017-07-14 00:38:21 +00:00
|
|
|
this.justMoved = true;
|
2017-07-18 16:22:14 +00:00
|
|
|
|
|
|
|
this.dirty = true;
|
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
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Input.Pointer#down
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {[type]} event - [description]
|
2018-03-18 13:43:37 +00:00
|
|
|
* @param {integer} time - The current timestamp as generated by the Request Animation Frame or SetTimeout.
|
2018-01-26 12:43:34 +00:00
|
|
|
*/
|
2017-07-27 02:40:58 +00:00
|
|
|
down: function (event, time)
|
2017-07-14 00:38:21 +00:00
|
|
|
{
|
2017-07-25 11:33:53 +00:00
|
|
|
if (event.buttons)
|
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;
|
|
|
|
|
|
|
|
this.x = this.manager.transformX(event.pageX);
|
|
|
|
this.y = this.manager.transformY(event.pageY);
|
|
|
|
|
2017-07-27 02:40:58 +00:00
|
|
|
// 0: Main button pressed, usually the left button or the un-initialized state
|
|
|
|
if (event.button === 0)
|
|
|
|
{
|
|
|
|
this.primaryDown = true;
|
|
|
|
this.downX = this.x;
|
|
|
|
this.downY = this.y;
|
|
|
|
this.downTime = time;
|
|
|
|
}
|
|
|
|
|
2017-07-14 00:38:21 +00:00
|
|
|
this.justDown = true;
|
2017-07-18 16:22:14 +00:00
|
|
|
this.isDown = true;
|
|
|
|
|
|
|
|
this.dirty = true;
|
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
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Input.Pointer#touchstart
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {[type]} event - [description]
|
2018-03-18 13:43:37 +00:00
|
|
|
* @param {integer} time - The current timestamp as generated by the Request Animation Frame or SetTimeout.
|
2018-01-26 12:43:34 +00:00
|
|
|
*/
|
2017-07-28 02:28:10 +00:00
|
|
|
touchstart: function (event, time)
|
|
|
|
{
|
|
|
|
this.buttons = 1;
|
|
|
|
|
|
|
|
this.event = event;
|
|
|
|
|
|
|
|
this.x = this.manager.transformX(event.changedTouches[0].pageX);
|
|
|
|
this.y = this.manager.transformY(event.changedTouches[0].pageY);
|
|
|
|
|
|
|
|
this.primaryDown = true;
|
|
|
|
this.downX = this.x;
|
|
|
|
this.downY = this.y;
|
|
|
|
this.downTime = time;
|
|
|
|
|
|
|
|
this.justDown = true;
|
|
|
|
this.isDown = true;
|
|
|
|
|
|
|
|
this.dirty = true;
|
2018-01-08 09:58:17 +00:00
|
|
|
|
|
|
|
this.wasTouch = true;
|
2017-07-28 02:28:10 +00:00
|
|
|
},
|
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Input.Pointer#up
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {[type]} event - [description]
|
2018-03-18 13:43:37 +00:00
|
|
|
* @param {integer} time - The current timestamp as generated by the Request Animation Frame or SetTimeout.
|
2018-01-26 12:43:34 +00:00
|
|
|
*/
|
2017-07-27 02:40:58 +00:00
|
|
|
up: function (event, time)
|
2017-07-14 00:38:21 +00:00
|
|
|
{
|
2017-07-25 11:33:53 +00:00
|
|
|
if (event.buttons)
|
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
|
|
|
}
|
|
|
|
|
|
|
|
this.event = event;
|
|
|
|
|
|
|
|
this.x = this.manager.transformX(event.pageX);
|
|
|
|
this.y = this.manager.transformY(event.pageY);
|
2017-07-14 00:38:21 +00:00
|
|
|
|
2017-07-27 02:40:58 +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;
|
|
|
|
this.upTime = time;
|
|
|
|
}
|
|
|
|
|
2017-07-14 00:38:21 +00:00
|
|
|
this.justUp = true;
|
2017-07-18 16:22:14 +00:00
|
|
|
this.isDown = false;
|
|
|
|
|
|
|
|
this.dirty = true;
|
2018-01-08 09:58:17 +00:00
|
|
|
|
|
|
|
this.wasTouch = false;
|
2017-07-25 11:33:53 +00:00
|
|
|
},
|
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Input.Pointer#touchend
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {[type]} event - [description]
|
2018-03-18 13:43:37 +00:00
|
|
|
* @param {integer} time - The current timestamp as generated by the Request Animation Frame or SetTimeout.
|
2018-01-26 12:43:34 +00:00
|
|
|
*/
|
2017-07-28 02:28:10 +00:00
|
|
|
touchend: function (event, time)
|
|
|
|
{
|
|
|
|
this.buttons = 0;
|
|
|
|
|
|
|
|
this.event = event;
|
|
|
|
|
|
|
|
this.x = this.manager.transformX(event.changedTouches[0].pageX);
|
|
|
|
this.y = this.manager.transformY(event.changedTouches[0].pageY);
|
|
|
|
|
|
|
|
this.primaryDown = false;
|
|
|
|
this.upX = this.x;
|
|
|
|
this.upY = this.y;
|
|
|
|
this.upTime = time;
|
|
|
|
|
|
|
|
this.justUp = true;
|
|
|
|
this.isDown = false;
|
|
|
|
|
|
|
|
this.dirty = true;
|
2018-01-08 09:58:17 +00:00
|
|
|
|
|
|
|
this.wasTouch = true;
|
2017-07-28 02:28:10 +00:00
|
|
|
},
|
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Input.Pointer#noButtonDown
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @return {boolean} [description]
|
|
|
|
*/
|
2017-07-25 11:33:53 +00:00
|
|
|
noButtonDown: function ()
|
|
|
|
{
|
|
|
|
return (this.buttons === 0);
|
|
|
|
},
|
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Input.Pointer#leftButtonDown
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @return {boolean} [description]
|
|
|
|
*/
|
2017-07-25 11:33:53 +00:00
|
|
|
leftButtonDown: function ()
|
|
|
|
{
|
|
|
|
return (this.buttons & 1);
|
|
|
|
},
|
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Input.Pointer#rightButtonDown
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @return {boolean} [description]
|
|
|
|
*/
|
2017-07-25 11:33:53 +00:00
|
|
|
rightButtonDown: function ()
|
|
|
|
{
|
|
|
|
return (this.buttons & 2);
|
|
|
|
},
|
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Input.Pointer#middleButtonDown
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @return {boolean} [description]
|
|
|
|
*/
|
2017-07-25 11:33:53 +00:00
|
|
|
middleButtonDown: function ()
|
|
|
|
{
|
|
|
|
return (this.buttons & 4);
|
|
|
|
},
|
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Input.Pointer#backButtonDown
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @return {boolean} [description]
|
|
|
|
*/
|
2017-07-25 11:33:53 +00:00
|
|
|
backButtonDown: function ()
|
|
|
|
{
|
|
|
|
return (this.buttons & 8);
|
|
|
|
},
|
|
|
|
|
2018-01-26 12:43:34 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Input.Pointer#forwardButtonDown
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @return {boolean} [description]
|
|
|
|
*/
|
2017-07-25 11:33:53 +00:00
|
|
|
forwardButtonDown: function ()
|
|
|
|
{
|
|
|
|
return (this.buttons & 16);
|
2018-01-31 03:38:10 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Input.Pointer#destroy
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
|
|
|
destroy: function ()
|
|
|
|
{
|
|
|
|
this.camera = null;
|
|
|
|
this.manager = null;
|
|
|
|
this.position = null;
|
2017-07-13 16:21:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = Pointer;
|