mirror of
https://github.com/wassname/phaser.git
synced 2026-07-08 00:10:32 +08:00
Adding docs.
This commit is contained in:
+197
-102
@@ -1,14 +1,35 @@
|
||||
/**
|
||||
* Phaser.Input
|
||||
*
|
||||
* A game specific Input manager that looks after the mouse, keyboard and touch objects.
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
* @module Phaser.Input
|
||||
*/
|
||||
|
||||
/**
|
||||
* Constructor for Phaser Input.
|
||||
* @class Phaser.Input
|
||||
* @classdesc A game specific Input manager that looks after the mouse, keyboard and touch objects.
|
||||
* This is updated by the core game loop.
|
||||
* @constructor
|
||||
* @param {Phaser.Game} game - Current game instance.
|
||||
*/
|
||||
Phaser.Input = function (game) {
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - A reference to the currently running game.
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* @property {Description} hitCanvas - Description.
|
||||
* @default
|
||||
*/
|
||||
this.hitCanvas = null;
|
||||
|
||||
/**
|
||||
* @property {Description} hitContext - Description.
|
||||
* @default
|
||||
*/
|
||||
this.hitContext = null;
|
||||
|
||||
};
|
||||
@@ -19,124 +40,141 @@ Phaser.Input.MOUSE_TOUCH_COMBINE = 2;
|
||||
|
||||
Phaser.Input.prototype = {
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game
|
||||
*/
|
||||
game: null,
|
||||
|
||||
/**
|
||||
* How often should the input pointers be checked for updates?
|
||||
* A value of 0 means every single frame (60fps), a value of 1 means every other frame (30fps) and so on.
|
||||
* @type {number}
|
||||
* @property {number} pollRate
|
||||
* @default
|
||||
*/
|
||||
pollRate: 0,
|
||||
|
||||
/**
|
||||
* @property {number} _pollCounter - Description.
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
_pollCounter: 0,
|
||||
|
||||
/**
|
||||
* A vector object representing the previous position of the Pointer.
|
||||
* @property vector
|
||||
* @type {Vec2}
|
||||
* @property {Vec2} vector
|
||||
* @default
|
||||
**/
|
||||
_oldPosition: null,
|
||||
|
||||
/**
|
||||
* X coordinate of the most recent Pointer event
|
||||
* @type {Number}
|
||||
* @property {number} _x
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
_x: 0,
|
||||
|
||||
/**
|
||||
* X coordinate of the most recent Pointer event
|
||||
* @type {Number}
|
||||
* Y coordinate of the most recent Pointer event
|
||||
* @property {number} _y
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
_y: 0,
|
||||
|
||||
/**
|
||||
* You can disable all Input by setting Input.disabled: true. While set all new input related events will be ignored.
|
||||
* If you need to disable just one type of input, for example mouse, use Input.mouse.disabled: true instead
|
||||
* @type {bool}
|
||||
* @property {bool} disabled
|
||||
* @default
|
||||
*/
|
||||
disabled: false,
|
||||
|
||||
/**
|
||||
* Controls the expected behaviour when using a mouse and touch together on a multi-input device
|
||||
* Controls the expected behaviour when using a mouse and touch together on a multi-input device.
|
||||
* @property {Description} multiInputOverride
|
||||
*/
|
||||
multiInputOverride: Phaser.Input.MOUSE_TOUCH_COMBINE,
|
||||
|
||||
/**
|
||||
* A vector object representing the current position of the Pointer.
|
||||
* @property vector
|
||||
* @type {Vec2}
|
||||
* @property {Vec2} position
|
||||
* @default
|
||||
**/
|
||||
position: null,
|
||||
|
||||
/**
|
||||
* A vector object representing the speed of the Pointer. Only really useful in single Pointer games,
|
||||
* otherwise see the Pointer objects directly.
|
||||
* @property vector
|
||||
* @type {Vec2}
|
||||
* @property {Vec2} speed
|
||||
* @default
|
||||
**/
|
||||
speed: null,
|
||||
|
||||
/**
|
||||
* A Circle object centered on the x/y screen coordinates of the Input.
|
||||
* Default size of 44px (Apples recommended "finger tip" size) but can be changed to anything
|
||||
* @property circle
|
||||
* @type {Circle}
|
||||
* @property {Circle} circle
|
||||
* @default
|
||||
**/
|
||||
circle: null,
|
||||
|
||||
/**
|
||||
* The scale by which all input coordinates are multiplied, calculated by the StageScaleMode.
|
||||
* In an un-scaled game the values will be x: 1 and y: 1.
|
||||
* @type {Vec2}
|
||||
* @property {Vec2} scale
|
||||
* @default
|
||||
*/
|
||||
scale: null,
|
||||
|
||||
/**
|
||||
* The maximum number of Pointers allowed to be active at any one time.
|
||||
* For lots of games it's useful to set this to 1
|
||||
* @type {Number}
|
||||
* For lots of games it's useful to set this to 1.
|
||||
* @property {number} maxPointers
|
||||
* @default
|
||||
*/
|
||||
maxPointers: 10,
|
||||
|
||||
/**
|
||||
* The current number of active Pointers.
|
||||
* @type {Number}
|
||||
* @property {number} currentPointers
|
||||
* @default
|
||||
*/
|
||||
currentPointers: 0,
|
||||
|
||||
/**
|
||||
* The number of milliseconds that the Pointer has to be pressed down and then released to be considered a tap or click
|
||||
* @property tapRate
|
||||
* @type {Number}
|
||||
* The number of milliseconds that the Pointer has to be pressed down and then released to be considered a tap or clicke
|
||||
* @property {number} tapRate
|
||||
* @default
|
||||
**/
|
||||
tapRate: 200,
|
||||
|
||||
/**
|
||||
* The number of milliseconds between taps of the same Pointer for it to be considered a double tap / click
|
||||
* @property doubleTapRate
|
||||
* @type {Number}
|
||||
* @property {number} doubleTapRate
|
||||
* @default
|
||||
**/
|
||||
doubleTapRate: 300,
|
||||
|
||||
/**
|
||||
* The number of milliseconds that the Pointer has to be pressed down for it to fire a onHold event
|
||||
* @property holdRate
|
||||
* @type {Number}
|
||||
* @property {number} holdRate
|
||||
* @default
|
||||
**/
|
||||
holdRate: 2000,
|
||||
|
||||
/**
|
||||
* The number of milliseconds below which the Pointer is considered justPressed
|
||||
* @property justPressedRate
|
||||
* @type {Number}
|
||||
* @property {number} justPressedRate
|
||||
* @default
|
||||
**/
|
||||
justPressedRate: 200,
|
||||
|
||||
/**
|
||||
* The number of milliseconds below which the Pointer is considered justReleased
|
||||
* @property justReleasedRate
|
||||
* @type {Number}
|
||||
* The number of milliseconds below which the Pointer is considered justReleased
|
||||
* @property {number} justReleasedRate
|
||||
* @default
|
||||
**/
|
||||
justReleasedRate: 200,
|
||||
|
||||
@@ -144,120 +182,162 @@ Phaser.Input.prototype = {
|
||||
* Sets if the Pointer objects should record a history of x/y coordinates they have passed through.
|
||||
* The history is cleared each time the Pointer is pressed down.
|
||||
* The history is updated at the rate specified in Input.pollRate
|
||||
* @property recordPointerHistory
|
||||
* @type {bool}
|
||||
* @property {bool} recordPointerHistory
|
||||
* @default
|
||||
**/
|
||||
recordPointerHistory: false,
|
||||
|
||||
/**
|
||||
* The rate in milliseconds at which the Pointer objects should update their tracking history
|
||||
* @property recordRate
|
||||
* @type {Number}
|
||||
* @property {number} recordRate
|
||||
* @default
|
||||
*/
|
||||
recordRate: 100,
|
||||
|
||||
/**
|
||||
* The total number of entries that can be recorded into the Pointer objects tracking history.
|
||||
* If the Pointer is tracking one event every 100ms, then a trackLimit of 100 would store the last 10 seconds worth of history.
|
||||
* @property recordLimit
|
||||
* @type {Number}
|
||||
* @property {number} recordLimit
|
||||
* @default
|
||||
*/
|
||||
recordLimit: 100,
|
||||
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer1
|
||||
* @type {Pointer}
|
||||
* @property {Pointer} pointer1
|
||||
**/
|
||||
pointer1: null,
|
||||
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer2
|
||||
* @type {Pointer}
|
||||
* @property {Pointer} pointer2
|
||||
**/
|
||||
pointer2: null,
|
||||
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer3
|
||||
* @type {Pointer}
|
||||
* A Pointer object
|
||||
* @property {Pointer} pointer3
|
||||
**/
|
||||
pointer3: null,
|
||||
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer4
|
||||
* @type {Pointer}
|
||||
* @property {Pointer} pointer4
|
||||
**/
|
||||
pointer4: null,
|
||||
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer5
|
||||
* @type {Pointer}
|
||||
* @property {Pointer} pointer5
|
||||
**/
|
||||
pointer5: null,
|
||||
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer6
|
||||
* @type {Pointer}
|
||||
* @property {Pointer} pointer6
|
||||
**/
|
||||
pointer6: null,
|
||||
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer7
|
||||
* @type {Pointer}
|
||||
* A Pointer object
|
||||
* @property {Pointer} pointer7
|
||||
**/
|
||||
pointer7: null,
|
||||
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer8
|
||||
* @type {Pointer}
|
||||
* @property {Pointer} pointer8
|
||||
**/
|
||||
pointer8: null,
|
||||
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer9
|
||||
* @type {Pointer}
|
||||
**/
|
||||
* @property {Pointer} pointer9
|
||||
**/
|
||||
pointer9: null,
|
||||
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer10
|
||||
* @type {Pointer}
|
||||
* A Pointer object.
|
||||
* @property {Pointer} pointer10
|
||||
**/
|
||||
pointer10: null,
|
||||
|
||||
/**
|
||||
* The most recently active Pointer object.
|
||||
* When you've limited max pointers to 1 this will accurately be either the first finger touched or mouse.
|
||||
* @property activePointer
|
||||
* @type {Pointer}
|
||||
* @property {Pointer} activePointer
|
||||
* @default
|
||||
**/
|
||||
activePointer: null,
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @property {Pointer} mousePointer
|
||||
* @default
|
||||
**/
|
||||
mousePointer: null,
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @property {Description} mouse
|
||||
* @default
|
||||
**/
|
||||
mouse: null,
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @property {Description} keyboard
|
||||
* @default
|
||||
**/
|
||||
keyboard: null,
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @property {Description} touch
|
||||
* @default
|
||||
**/
|
||||
touch: null,
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @property {Description} mspointer
|
||||
* @default
|
||||
**/
|
||||
mspointer: null,
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @property {Description} onDown
|
||||
* @default
|
||||
**/
|
||||
onDown: null,
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @property {Description} onUp
|
||||
* @default
|
||||
**/
|
||||
onUp: null,
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @property {Description} onTap
|
||||
* @default
|
||||
**/
|
||||
onTap: null,
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @property {Description} onHold
|
||||
* @default
|
||||
**/
|
||||
onHold: null,
|
||||
|
||||
// A linked list of interactive objects, the InputHandler components (belong to Sprites) register themselves with this
|
||||
interactiveItems: new Phaser.LinkedList(),
|
||||
|
||||
/**
|
||||
* Starts the Input Manager running
|
||||
* Starts the Input Manager running.
|
||||
* @method start
|
||||
**/
|
||||
boot: function () {
|
||||
@@ -303,7 +383,7 @@ Phaser.Input.prototype = {
|
||||
* Add a new Pointer object to the Input Manager. By default Input creates 2 pointer objects for you. If you need more
|
||||
* use this to create a new one, up to a maximum of 10.
|
||||
* @method addPointer
|
||||
* @return {Pointer} A reference to the new Pointer object
|
||||
* @return {Pointer} A reference to the new Pointer object.
|
||||
**/
|
||||
addPointer: function () {
|
||||
|
||||
@@ -361,13 +441,12 @@ Phaser.Input.prototype = {
|
||||
if (this.pointer10) { this.pointer10.update(); }
|
||||
|
||||
this._pollCounter = 0;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Reset all of the Pointers and Input states
|
||||
* @method reset
|
||||
* @param hard {bool} A soft reset (hard = false) won't reset any signals that might be bound. A hard reset will.
|
||||
* @param {bool} hard - A soft reset (hard = false) won't reset any signals that might be bound. A hard reset will.
|
||||
**/
|
||||
reset: function (hard) {
|
||||
|
||||
@@ -420,8 +499,8 @@ Phaser.Input.prototype = {
|
||||
/**
|
||||
* Find the first free Pointer object and start it, passing in the event data.
|
||||
* @method startPointer
|
||||
* @param {Any} event The event data from the Touch event
|
||||
* @return {Pointer} The Pointer object that was started or null if no Pointer object is available
|
||||
* @param {Any} event - The event data from the Touch event.
|
||||
* @return {Pointer} The Pointer object that was started or null if no Pointer object is available.
|
||||
**/
|
||||
startPointer: function (event) {
|
||||
|
||||
@@ -456,8 +535,8 @@ Phaser.Input.prototype = {
|
||||
/**
|
||||
* Updates the matching Pointer object, passing in the event data.
|
||||
* @method updatePointer
|
||||
* @param {Any} event The event data from the Touch event
|
||||
* @return {Pointer} The Pointer object that was updated or null if no Pointer object is available
|
||||
* @param {Any} event - The event data from the Touch event.
|
||||
* @return {Pointer} The Pointer object that was updated or null if no Pointer object is available.
|
||||
**/
|
||||
updatePointer: function (event) {
|
||||
|
||||
@@ -487,8 +566,8 @@ Phaser.Input.prototype = {
|
||||
/**
|
||||
* Stops the matching Pointer object, passing in the event data.
|
||||
* @method stopPointer
|
||||
* @param {Any} event The event data from the Touch event
|
||||
* @return {Pointer} The Pointer object that was stopped or null if no Pointer object is available
|
||||
* @param {Any} event - The event data from the Touch event.
|
||||
* @return {Pointer} The Pointer object that was stopped or null if no Pointer object is available.
|
||||
**/
|
||||
stopPointer: function (event) {
|
||||
|
||||
@@ -518,7 +597,7 @@ Phaser.Input.prototype = {
|
||||
/**
|
||||
* Get the next Pointer object whos active property matches the given state
|
||||
* @method getPointer
|
||||
* @param {bool} state The state the Pointer should be in (false for inactive, true for active)
|
||||
* @param {bool} state - The state the Pointer should be in (false for inactive, true for active).
|
||||
* @return {Pointer} A Pointer object or null if no Pointer object matches the requested state.
|
||||
**/
|
||||
getPointer: function (state) {
|
||||
@@ -549,9 +628,9 @@ Phaser.Input.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the Pointer object whos identified property matches the given identifier value
|
||||
* Get the Pointer object whos identified property matches the given identifier value.
|
||||
* @method getPointerFromIdentifier
|
||||
* @param {Number} identifier The Pointer.identifier value to search for
|
||||
* @param {number} identifier - The Pointer.identifier value to search for.
|
||||
* @return {Pointer} A Pointer object or null if no Pointer object matches the requested identifier.
|
||||
**/
|
||||
getPointerFromIdentifier: function (identifier) {
|
||||
@@ -580,20 +659,22 @@ Phaser.Input.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the distance between two Pointer objects
|
||||
* Get the distance between two Pointer objects.
|
||||
* @method getDistance
|
||||
* @param {Pointer} pointer1
|
||||
* @param {Pointer} pointer2
|
||||
* @return {Description} Description.
|
||||
**/
|
||||
getDistance: function (pointer1, pointer2) {
|
||||
// return Phaser.Vec2Utils.distance(pointer1.position, pointer2.position);
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the angle between two Pointer objects
|
||||
* Get the angle between two Pointer objects.
|
||||
* @method getAngle
|
||||
* @param {Pointer} pointer1
|
||||
* @param {Pointer} pointer2
|
||||
* @return {Description} Description.
|
||||
**/
|
||||
getAngle: function (pointer1, pointer2) {
|
||||
// return Phaser.Vec2Utils.angle(pointer1.position, pointer2.position);
|
||||
@@ -603,14 +684,16 @@ Phaser.Input.prototype = {
|
||||
|
||||
// Getters / Setters
|
||||
|
||||
/**
|
||||
* The X coordinate of the most recently active pointer.
|
||||
* This value takes game scaling into account automatically. See Pointer.screenX/clientX for source values.
|
||||
* @return {number}
|
||||
*//**
|
||||
* Set
|
||||
* @param {number} value - Description.
|
||||
*/
|
||||
Object.defineProperty(Phaser.Input.prototype, "x", {
|
||||
|
||||
/**
|
||||
* The X coordinate of the most recently active pointer.
|
||||
* This value takes game scaling into account automatically. See Pointer.screenX/clientX for source values.
|
||||
* @property x
|
||||
* @type {Number}
|
||||
**/
|
||||
get: function () {
|
||||
return this._x;
|
||||
},
|
||||
@@ -621,14 +704,16 @@ Object.defineProperty(Phaser.Input.prototype, "x", {
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* The Y coordinate of the most recently active pointer.
|
||||
* This value takes game scaling into account automatically. See Pointer.screenY/clientY for source values.
|
||||
* @return {number}
|
||||
*//**
|
||||
* Set
|
||||
* @param {number} value - Description.
|
||||
*/
|
||||
Object.defineProperty(Phaser.Input.prototype, "y", {
|
||||
|
||||
/**
|
||||
* The Y coordinate of the most recently active pointer.
|
||||
* This value takes game scaling into account automatically. See Pointer.screenY/clientY for source values.
|
||||
* @property y
|
||||
* @type {Number}
|
||||
**/
|
||||
get: function () {
|
||||
return this._y;
|
||||
},
|
||||
@@ -639,6 +724,10 @@ Object.defineProperty(Phaser.Input.prototype, "y", {
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* Get
|
||||
* @return {Description} Description.
|
||||
*/
|
||||
Object.defineProperty(Phaser.Input.prototype, "pollLocked", {
|
||||
|
||||
get: function () {
|
||||
@@ -647,26 +736,24 @@ Object.defineProperty(Phaser.Input.prototype, "pollLocked", {
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* Get the total number of inactive Pointers
|
||||
* @return {number} The number of Pointers currently inactive.
|
||||
*/
|
||||
Object.defineProperty(Phaser.Input.prototype, "totalInactivePointers", {
|
||||
|
||||
/**
|
||||
* Get the total number of inactive Pointers
|
||||
* @method totalInactivePointers
|
||||
* @return {Number} The number of Pointers currently inactive
|
||||
**/
|
||||
get: function () {
|
||||
return 10 - this.currentPointers;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* Recalculates the total number of active Pointers
|
||||
* @return {number} The number of Pointers currently active.
|
||||
*/
|
||||
Object.defineProperty(Phaser.Input.prototype, "totalActivePointers", {
|
||||
|
||||
/**
|
||||
* Recalculates the total number of active Pointers
|
||||
* @method totalActivePointers
|
||||
* @return {Number} The number of Pointers currently active
|
||||
**/
|
||||
get: function () {
|
||||
|
||||
this.currentPointers = 0;
|
||||
@@ -685,6 +772,10 @@ Object.defineProperty(Phaser.Input.prototype, "totalActivePointers", {
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* Get
|
||||
* @return {Description}
|
||||
*/
|
||||
Object.defineProperty(Phaser.Input.prototype, "worldX", {
|
||||
|
||||
get: function () {
|
||||
@@ -693,6 +784,10 @@ Object.defineProperty(Phaser.Input.prototype, "worldX", {
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* Get
|
||||
* @return {Description}
|
||||
*/
|
||||
Object.defineProperty(Phaser.Input.prototype, "worldY", {
|
||||
|
||||
get: function () {
|
||||
|
||||
+253
-63
@@ -1,71 +1,174 @@
|
||||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
* @module Phaser.InputHandler
|
||||
*/
|
||||
|
||||
/**
|
||||
* Constructor for Phaser InputHandler.
|
||||
* @class Phaser.InputHandler
|
||||
* @classdesc Description.
|
||||
* @constructor
|
||||
* @param {Phaser.Sprite} game - Description.
|
||||
*/
|
||||
Phaser.InputHandler = function (sprite) {
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - A reference to the currently running game.
|
||||
*/
|
||||
this.game = sprite.game;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Sprite} sprite - Description.
|
||||
*/
|
||||
this.sprite = sprite;
|
||||
|
||||
/**
|
||||
* @property {bool} enabled - Description.
|
||||
* @default
|
||||
*/
|
||||
this.enabled = false;
|
||||
|
||||
// Linked list references
|
||||
/**
|
||||
* @property {Description} parent - Description.
|
||||
* @default
|
||||
*/
|
||||
this.parent = null;
|
||||
|
||||
/**
|
||||
* @property {Description} next - Description.
|
||||
* @default
|
||||
*/
|
||||
this.next = null;
|
||||
|
||||
/**
|
||||
* @property {Description} prev - Description.
|
||||
* @default
|
||||
*/
|
||||
this.prev = null;
|
||||
|
||||
/**
|
||||
* @property {Description} last - Description.
|
||||
* @default
|
||||
*/
|
||||
this.last = this;
|
||||
|
||||
/**
|
||||
* @property {Description} first - Description.
|
||||
* @default
|
||||
*/
|
||||
this.first = this;
|
||||
|
||||
/**
|
||||
* The PriorityID controls which Sprite receives an Input event first if they should overlap.
|
||||
*/
|
||||
/**
|
||||
* @property {number} priorityID - The PriorityID controls which Sprite receives an Input event first if they should overlap.
|
||||
* @default
|
||||
*/
|
||||
this.priorityID = 0;
|
||||
|
||||
/**
|
||||
* @property {bool} useHandCursor - Description.
|
||||
* @default
|
||||
*/
|
||||
this.useHandCursor = false;
|
||||
|
||||
/**
|
||||
* @property {bool} isDragged - Description.
|
||||
* @default
|
||||
*/
|
||||
this.isDragged = false;
|
||||
|
||||
/**
|
||||
* @property {bool} allowHorizontalDrag - Description.
|
||||
* @default
|
||||
*/
|
||||
this.allowHorizontalDrag = true;
|
||||
|
||||
/**
|
||||
* @property {bool} allowVerticalDrag - Description.
|
||||
* @default
|
||||
*/
|
||||
this.allowVerticalDrag = true;
|
||||
|
||||
/**
|
||||
* @property {bool} bringToTop - Description.
|
||||
* @default
|
||||
*/
|
||||
this.bringToTop = false;
|
||||
|
||||
/**
|
||||
* @property {Description} snapOffset - Description.
|
||||
* @default
|
||||
*/
|
||||
this.snapOffset = null;
|
||||
|
||||
/**
|
||||
* @property {bool} snapOnDrag - Description.
|
||||
* @default
|
||||
*/
|
||||
this.snapOnDrag = false;
|
||||
|
||||
/**
|
||||
* @property {bool} snapOnRelease - Description.
|
||||
* @default
|
||||
*/
|
||||
this.snapOnRelease = false;
|
||||
|
||||
/**
|
||||
* @property {number} snapX - Description.
|
||||
* @default
|
||||
*/
|
||||
this.snapX = 0;
|
||||
|
||||
/**
|
||||
* @property {number} snapY - Description.
|
||||
* @default
|
||||
*/
|
||||
this.snapY = 0;
|
||||
|
||||
/**
|
||||
* Should we use pixel perfect hit detection? Warning: expensive. Only enable if you really need it!
|
||||
* @default false
|
||||
*/
|
||||
/**
|
||||
* @property {number} pixelPerfect - Should we use pixel perfect hit detection? Warning: expensive. Only enable if you really need it!
|
||||
* @default
|
||||
*/
|
||||
this.pixelPerfect = false;
|
||||
|
||||
/**
|
||||
* The alpha tolerance threshold. If the alpha value of the pixel matches or is above this value, it's considered a hit.
|
||||
* @default 255
|
||||
* @property {number} pixelPerfectAlpha - The alpha tolerance threshold. If the alpha value of the pixel matches or is above this value, it's considered a hit.
|
||||
* @default
|
||||
*/
|
||||
this.pixelPerfectAlpha = 255;
|
||||
|
||||
/**
|
||||
* Is this sprite allowed to be dragged by the mouse? true = yes, false = no
|
||||
* @default false
|
||||
* @property {bool} draggable - Is this sprite allowed to be dragged by the mouse? true = yes, false = no
|
||||
* @default
|
||||
*/
|
||||
this.draggable = false;
|
||||
|
||||
/**
|
||||
* A region of the game world within which the sprite is restricted during drag
|
||||
* @default null
|
||||
* @property {Description} boundsRect - A region of the game world within which the sprite is restricted during drag.
|
||||
* @default
|
||||
*/
|
||||
this.boundsRect = null;
|
||||
|
||||
/**
|
||||
* An Sprite the bounds of which this sprite is restricted during drag
|
||||
* @default null
|
||||
* @property {Description} boundsSprite - A Sprite the bounds of which this sprite is restricted during drag.
|
||||
* @default
|
||||
*/
|
||||
this.boundsSprite = null;
|
||||
|
||||
/**
|
||||
* If this object is set to consume the pointer event then it will stop all propogation from this object on.
|
||||
* For example if you had a stack of 6 sprites with the same priority IDs and one consumed the event, none of the others would receive it.
|
||||
* @type {bool}
|
||||
* @property {bool} consumePointerEvent
|
||||
* @default
|
||||
*/
|
||||
this.consumePointerEvent = false;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} _tempPoint - Description.
|
||||
* @private
|
||||
*/
|
||||
this._tempPoint = new Phaser.Point;
|
||||
|
||||
this._pointerData = [];
|
||||
@@ -90,6 +193,13 @@ Phaser.InputHandler = function (sprite) {
|
||||
|
||||
Phaser.InputHandler.prototype = {
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method start
|
||||
* @param {number} priority - Description.
|
||||
* @param {bool} useHandCursor - Description.
|
||||
* @return {Phaser.Sprite} Description.
|
||||
*/
|
||||
start: function (priority, useHandCursor) {
|
||||
|
||||
priority = priority || 0;
|
||||
@@ -141,6 +251,10 @@ Phaser.InputHandler.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method reset
|
||||
*/
|
||||
reset: function () {
|
||||
|
||||
this.enabled = false;
|
||||
@@ -165,6 +279,10 @@ Phaser.InputHandler.prototype = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method stop
|
||||
*/
|
||||
stop: function () {
|
||||
|
||||
// Turning off
|
||||
@@ -182,8 +300,9 @@ Phaser.InputHandler.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Clean up memory.
|
||||
*/
|
||||
* Clean up memory.
|
||||
* @method destroy
|
||||
*/
|
||||
destroy: function () {
|
||||
|
||||
if (this.enabled)
|
||||
@@ -198,7 +317,9 @@ Phaser.InputHandler.prototype = {
|
||||
/**
|
||||
* The x coordinate of the Input pointer, relative to the top-left of the parent Sprite.
|
||||
* This value is only set when the pointer is over this Sprite.
|
||||
* @type {number}
|
||||
* @method pointerX
|
||||
* @param {Pointer} pointer
|
||||
* @return {number} The x coordinate of the Input pointer.
|
||||
*/
|
||||
pointerX: function (pointer) {
|
||||
|
||||
@@ -211,7 +332,9 @@ Phaser.InputHandler.prototype = {
|
||||
/**
|
||||
* The y coordinate of the Input pointer, relative to the top-left of the parent Sprite
|
||||
* This value is only set when the pointer is over this Sprite.
|
||||
* @type {number}
|
||||
* @method pointerY
|
||||
* @param {Pointer} pointer
|
||||
* @return {number} The y coordinate of the Input pointer.
|
||||
*/
|
||||
pointerY: function (pointer) {
|
||||
|
||||
@@ -222,10 +345,11 @@ Phaser.InputHandler.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* If the Pointer is touching the touchscreen, or the mouse button is held down, isDown is set to true
|
||||
* @property isDown
|
||||
* @type {bool}
|
||||
**/
|
||||
* If the Pointer is touching the touchscreen, or the mouse button is held down, isDown is set to true.
|
||||
* @method pointerDown
|
||||
* @param {Pointer} pointer
|
||||
* @return {bool}
|
||||
*/
|
||||
pointerDown: function (pointer) {
|
||||
|
||||
pointer = pointer || 0;
|
||||
@@ -236,9 +360,10 @@ Phaser.InputHandler.prototype = {
|
||||
|
||||
/**
|
||||
* If the Pointer is not touching the touchscreen, or the mouse button is up, isUp is set to true
|
||||
* @property isUp
|
||||
* @type {bool}
|
||||
**/
|
||||
* @method pointerUp
|
||||
* @param {Pointer} pointer
|
||||
* @return {bool}
|
||||
*/
|
||||
pointerUp: function (pointer) {
|
||||
|
||||
pointer = pointer || 0;
|
||||
@@ -249,9 +374,10 @@ Phaser.InputHandler.prototype = {
|
||||
|
||||
/**
|
||||
* A timestamp representing when the Pointer first touched the touchscreen.
|
||||
* @property timeDown
|
||||
* @type {Number}
|
||||
**/
|
||||
* @method pointerTimeDown
|
||||
* @param {Pointer} pointer
|
||||
* @return {number}
|
||||
*/
|
||||
pointerTimeDown: function (pointer) {
|
||||
|
||||
pointer = pointer || 0;
|
||||
@@ -262,9 +388,10 @@ Phaser.InputHandler.prototype = {
|
||||
|
||||
/**
|
||||
* A timestamp representing when the Pointer left the touchscreen.
|
||||
* @property timeUp
|
||||
* @type {Number}
|
||||
**/
|
||||
* @method pointerTimeUp
|
||||
* @param {Pointer} pointer
|
||||
* @return {number}
|
||||
*/
|
||||
pointerTimeUp: function (pointer) {
|
||||
|
||||
pointer = pointer || 0;
|
||||
@@ -274,10 +401,11 @@ Phaser.InputHandler.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Is the Pointer over this Sprite
|
||||
* @property isOver
|
||||
* @type {bool}
|
||||
**/
|
||||
* Is the Pointer over this Sprite?
|
||||
* @method pointerOver
|
||||
* @param {Pointer} pointer
|
||||
* @return {bool
|
||||
*/
|
||||
pointerOver: function (pointer) {
|
||||
|
||||
pointer = pointer || 0;
|
||||
@@ -287,10 +415,11 @@ Phaser.InputHandler.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Is the Pointer outside of this Sprite
|
||||
* @property isOut
|
||||
* @type {bool}
|
||||
**/
|
||||
* Is the Pointer outside of this Sprite?
|
||||
* @method pointerOut
|
||||
* @param {Pointer} pointer
|
||||
* @return {bool}
|
||||
*/
|
||||
pointerOut: function (pointer) {
|
||||
|
||||
pointer = pointer || 0;
|
||||
@@ -301,9 +430,10 @@ Phaser.InputHandler.prototype = {
|
||||
|
||||
/**
|
||||
* A timestamp representing when the Pointer first touched the touchscreen.
|
||||
* @property timeDown
|
||||
* @type {Number}
|
||||
**/
|
||||
* @method pointerTimeOver
|
||||
* @param {Pointer} pointer
|
||||
* @return {number}
|
||||
*/
|
||||
pointerTimeOver: function (pointer) {
|
||||
|
||||
pointer = pointer || 0;
|
||||
@@ -314,9 +444,10 @@ Phaser.InputHandler.prototype = {
|
||||
|
||||
/**
|
||||
* A timestamp representing when the Pointer left the touchscreen.
|
||||
* @property timeUp
|
||||
* @type {Number}
|
||||
**/
|
||||
* @method pointerTimeOut
|
||||
* @param {Pointer} pointer
|
||||
* @return {number}
|
||||
*/
|
||||
pointerTimeOut: function (pointer) {
|
||||
|
||||
pointer = pointer || 0;
|
||||
@@ -327,7 +458,9 @@ Phaser.InputHandler.prototype = {
|
||||
|
||||
/**
|
||||
* Is this sprite being dragged by the mouse or not?
|
||||
* @default false
|
||||
* @method pointerTimeOut
|
||||
* @param {Pointer} pointer
|
||||
* @return {number}
|
||||
*/
|
||||
pointerDragged: function (pointer) {
|
||||
|
||||
@@ -339,6 +472,9 @@ Phaser.InputHandler.prototype = {
|
||||
|
||||
/**
|
||||
* Checks if the given pointer is over this Sprite.
|
||||
* @method checkPointerOver
|
||||
* @param {Pointer} pointer
|
||||
* @return {bool}
|
||||
*/
|
||||
checkPointerOver: function (pointer) {
|
||||
|
||||
@@ -372,6 +508,13 @@ Phaser.InputHandler.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method checkPixel
|
||||
* @param {Description} x - Description.
|
||||
* @param {Description} y - Description.
|
||||
* @return {bool}
|
||||
*/
|
||||
checkPixel: function (x, y) {
|
||||
|
||||
x += (this.sprite.texture.frame.width * this.sprite.anchor.x);
|
||||
@@ -399,7 +542,9 @@ Phaser.InputHandler.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Update
|
||||
* Update.
|
||||
* @method update
|
||||
* @param {Pointer} pointer
|
||||
*/
|
||||
update: function (pointer) {
|
||||
|
||||
@@ -429,6 +574,12 @@ Phaser.InputHandler.prototype = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method _pointerOverHandler
|
||||
* @private
|
||||
* @param {Pointer} pointer
|
||||
*/
|
||||
_pointerOverHandler: function (pointer) {
|
||||
|
||||
if (this._pointerData[pointer.id].isOver == false)
|
||||
@@ -448,6 +599,12 @@ Phaser.InputHandler.prototype = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method _pointerOutHandler
|
||||
* @private
|
||||
* @param {Pointer} pointer
|
||||
*/
|
||||
_pointerOutHandler: function (pointer) {
|
||||
|
||||
this._pointerData[pointer.id].isOver = false;
|
||||
@@ -463,6 +620,12 @@ Phaser.InputHandler.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method _touchedHandler
|
||||
* @private
|
||||
* @param {Pointer} pointer
|
||||
*/
|
||||
_touchedHandler: function (pointer) {
|
||||
|
||||
if (this._pointerData[pointer.id].isDown == false && this._pointerData[pointer.id].isOver == true)
|
||||
@@ -489,6 +652,12 @@ Phaser.InputHandler.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method _releasedHandler
|
||||
* @private
|
||||
* @param {Pointer} pointer
|
||||
*/
|
||||
_releasedHandler: function (pointer) {
|
||||
|
||||
// If was previously touched by this Pointer, check if still is AND still over this item
|
||||
@@ -525,6 +694,9 @@ Phaser.InputHandler.prototype = {
|
||||
|
||||
/**
|
||||
* Updates the Pointer drag on this Sprite.
|
||||
* @method updateDrag
|
||||
* @param {Pointer} pointer
|
||||
* @return {bool}
|
||||
*/
|
||||
updateDrag: function (pointer) {
|
||||
|
||||
@@ -566,8 +738,10 @@ Phaser.InputHandler.prototype = {
|
||||
|
||||
/**
|
||||
* Returns true if the pointer has entered the Sprite within the specified delay time (defaults to 500ms, half a second)
|
||||
* @param delay The time below which the pointer is considered as just over.
|
||||
* @returns {bool}
|
||||
* @method justOver
|
||||
* @param {Pointer} pointer
|
||||
* @param {number} delay - The time below which the pointer is considered as just over.
|
||||
* @return {bool}
|
||||
*/
|
||||
justOver: function (pointer, delay) {
|
||||
|
||||
@@ -580,8 +754,10 @@ Phaser.InputHandler.prototype = {
|
||||
|
||||
/**
|
||||
* Returns true if the pointer has left the Sprite within the specified delay time (defaults to 500ms, half a second)
|
||||
* @param delay The time below which the pointer is considered as just out.
|
||||
* @returns {bool}
|
||||
* @method justOut
|
||||
* @param {Pointer} pointer
|
||||
* @param {number} delay - The time below which the pointer is considered as just out.
|
||||
* @return {bool}
|
||||
*/
|
||||
justOut: function (pointer, delay) {
|
||||
|
||||
@@ -594,8 +770,10 @@ Phaser.InputHandler.prototype = {
|
||||
|
||||
/**
|
||||
* Returns true if the pointer has entered the Sprite within the specified delay time (defaults to 500ms, half a second)
|
||||
* @param delay The time below which the pointer is considered as just over.
|
||||
* @returns {bool}
|
||||
* @method justPressed
|
||||
* @param {Pointer} pointer
|
||||
* @param {number} delay - The time below which the pointer is considered as just over.
|
||||
* @return {bool}
|
||||
*/
|
||||
justPressed: function (pointer, delay) {
|
||||
|
||||
@@ -608,8 +786,10 @@ Phaser.InputHandler.prototype = {
|
||||
|
||||
/**
|
||||
* Returns true if the pointer has left the Sprite within the specified delay time (defaults to 500ms, half a second)
|
||||
* @param delay The time below which the pointer is considered as just out.
|
||||
* @returns {bool}
|
||||
* @method justReleased
|
||||
* @param {Pointer} pointer
|
||||
* @param {number} delay - The time below which the pointer is considered as just out.
|
||||
* @return {bool}
|
||||
*/
|
||||
justReleased: function (pointer, delay) {
|
||||
|
||||
@@ -622,7 +802,9 @@ Phaser.InputHandler.prototype = {
|
||||
|
||||
/**
|
||||
* If the pointer is currently over this Sprite this returns how long it has been there for in milliseconds.
|
||||
* @returns {number} The number of milliseconds the pointer has been over the Sprite, or -1 if not over.
|
||||
* @method overDuration
|
||||
* @param {Pointer} pointer
|
||||
* @return {number} The number of milliseconds the pointer has been over the Sprite, or -1 if not over.
|
||||
*/
|
||||
overDuration: function (pointer) {
|
||||
|
||||
@@ -639,7 +821,9 @@ Phaser.InputHandler.prototype = {
|
||||
|
||||
/**
|
||||
* If the pointer is currently over this Sprite this returns how long it has been there for in milliseconds.
|
||||
* @returns {number} The number of milliseconds the pointer has been pressed down on the Sprite, or -1 if not over.
|
||||
* @method downDuration
|
||||
* @param {Pointer} pointer
|
||||
* @return {number} The number of milliseconds the pointer has been pressed down on the Sprite, or -1 if not over.
|
||||
*/
|
||||
downDuration: function (pointer) {
|
||||
|
||||
@@ -656,7 +840,7 @@ Phaser.InputHandler.prototype = {
|
||||
|
||||
/**
|
||||
* Make this Sprite draggable by the mouse. You can also optionally set mouseStartDragCallback and mouseStopDragCallback
|
||||
*
|
||||
* @method enableDrag
|
||||
* @param lockCenter If false the Sprite will drag from where you click it minus the dragOffset. If true it will center itself to the tip of the mouse pointer.
|
||||
* @param bringToTop If true the Sprite will be bought to the top of the rendering list in its current Group.
|
||||
* @param pixelPerfect If true it will use a pixel perfect test to see if you clicked the Sprite. False uses the bounding box.
|
||||
@@ -697,6 +881,7 @@ Phaser.InputHandler.prototype = {
|
||||
|
||||
/**
|
||||
* Stops this sprite from being able to be dragged. If it is currently the target of an active drag it will be stopped immediately. Also disables any set callbacks.
|
||||
* @method disableDrag
|
||||
*/
|
||||
disableDrag: function () {
|
||||
|
||||
@@ -716,6 +901,7 @@ Phaser.InputHandler.prototype = {
|
||||
|
||||
/**
|
||||
* Called by Pointer when drag starts on this Sprite. Should not usually be called directly.
|
||||
* @method startDrag
|
||||
*/
|
||||
startDrag: function (pointer) {
|
||||
|
||||
@@ -746,6 +932,7 @@ Phaser.InputHandler.prototype = {
|
||||
|
||||
/**
|
||||
* Called by Pointer when drag is stopped on this Sprite. Should not usually be called directly.
|
||||
* @method stopDrag
|
||||
*/
|
||||
stopDrag: function (pointer) {
|
||||
|
||||
@@ -766,7 +953,7 @@ Phaser.InputHandler.prototype = {
|
||||
|
||||
/**
|
||||
* Restricts this sprite to drag movement only on the given axis. Note: If both are set to false the sprite will never move!
|
||||
*
|
||||
* @method setDragLock
|
||||
* @param allowHorizontal To enable the sprite to be dragged horizontally set to true, otherwise false
|
||||
* @param allowVertical To enable the sprite to be dragged vertically set to true, otherwise false
|
||||
*/
|
||||
@@ -783,7 +970,7 @@ Phaser.InputHandler.prototype = {
|
||||
/**
|
||||
* Make this Sprite snap to the given grid either during drag or when it's released.
|
||||
* For example 16x16 as the snapX and snapY would make the sprite snap to every 16 pixels.
|
||||
*
|
||||
* @method enableSnap
|
||||
* @param snapX The width of the grid cell in pixels
|
||||
* @param snapY The height of the grid cell in pixels
|
||||
* @param onDrag If true the sprite will snap to the grid while being dragged
|
||||
@@ -803,6 +990,7 @@ Phaser.InputHandler.prototype = {
|
||||
|
||||
/**
|
||||
* Stops the sprite from snapping to a grid during drag or release.
|
||||
* @method disableSnap
|
||||
*/
|
||||
disableSnap: function () {
|
||||
|
||||
@@ -813,6 +1001,7 @@ Phaser.InputHandler.prototype = {
|
||||
|
||||
/**
|
||||
* Bounds Rect check for the sprite drag
|
||||
* @method checkBoundsRect
|
||||
*/
|
||||
checkBoundsRect: function () {
|
||||
|
||||
@@ -837,7 +1026,8 @@ Phaser.InputHandler.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Parent Sprite Bounds check for the sprite drag
|
||||
* Parent Sprite Bounds check for the sprite drag.
|
||||
* @method checkBoundsSprite
|
||||
*/
|
||||
checkBoundsSprite: function () {
|
||||
|
||||
|
||||
+84
-36
@@ -1,8 +1,36 @@
|
||||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
* @module Phaser.Keyboard
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Phaser - Keyboard constructor.
|
||||
*
|
||||
* @class Phaser.Keyboard
|
||||
* @classdesc A Keyboard object Description.
|
||||
* @constructor
|
||||
* @param {Phaser.Game} game - A reference to the currently running game.
|
||||
*/
|
||||
Phaser.Keyboard = function (game) {
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - Local reference to game.
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* @property {Description} _keys - Description.
|
||||
* @private
|
||||
*/
|
||||
this._keys = {};
|
||||
this._hotkeys = {};
|
||||
|
||||
/**
|
||||
* @property {Description} _capture - Description.
|
||||
* @private
|
||||
*/
|
||||
this._capture = {};
|
||||
|
||||
this.callbackContext = this;
|
||||
@@ -16,42 +44,38 @@ Phaser.Keyboard = function (game) {
|
||||
|
||||
Phaser.Keyboard.prototype = {
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - Local reference to game.
|
||||
*/
|
||||
game: null,
|
||||
|
||||
/**
|
||||
* You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
|
||||
* @type {bool}
|
||||
* @default
|
||||
* @property {bool} disabled
|
||||
*/
|
||||
disabled: false,
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @property {Description} _onKeyDown
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
_onKeyDown: null,
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @property {Description} _onKeyUp
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
_onKeyUp: null,
|
||||
|
||||
addCallbacks: function (context, onDown, onUp) {
|
||||
|
||||
this.callbackContext = context;
|
||||
this.onDownCallback = onDown;
|
||||
|
||||
if (typeof onUp !== 'undefined')
|
||||
{
|
||||
this.onUpCallback = onUp;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
addKey: function (keycode) {
|
||||
|
||||
this._hotkeys[keycode] = new Phaser.Key(this.game, keycode);
|
||||
return this._hotkeys[keycode];
|
||||
|
||||
},
|
||||
|
||||
removeKey: function (keycode) {
|
||||
|
||||
delete (this._hotkeys[keycode]);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method start
|
||||
*/
|
||||
start: function () {
|
||||
|
||||
var _this = this;
|
||||
@@ -69,6 +93,10 @@ Phaser.Keyboard.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method stop
|
||||
*/
|
||||
stop: function () {
|
||||
|
||||
document.body.removeEventListener('keydown', this._onKeyDown);
|
||||
@@ -81,6 +109,7 @@ Phaser.Keyboard.prototype = {
|
||||
* There are some keys this can be annoying for, like the arrow keys or space bar, which make the browser window scroll.
|
||||
* You can use addKeyCapture to consume the keyboard event for specific keys so it doesn't bubble up to the the browser.
|
||||
* Pass in either a single keycode or an array/hash of keycodes.
|
||||
* @method addKeyCapture
|
||||
* @param {Any} keycode
|
||||
*/
|
||||
addKeyCapture: function (keycode) {
|
||||
@@ -99,7 +128,9 @@ Phaser.Keyboard.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Number} keycode
|
||||
* Description.
|
||||
* @method removeKeyCapture
|
||||
* @param {number} keycode
|
||||
*/
|
||||
removeKeyCapture: function (keycode) {
|
||||
|
||||
@@ -107,14 +138,19 @@ Phaser.Keyboard.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method clearCaptures
|
||||
*/
|
||||
clearCaptures: function () {
|
||||
|
||||
this._capture = {};
|
||||
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method processKeyDown
|
||||
* @param {KeyboardEvent} event
|
||||
*/
|
||||
processKeyDown: function (event) {
|
||||
@@ -168,6 +204,8 @@ Phaser.Keyboard.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method processKeyUp
|
||||
* @param {KeyboardEvent} event
|
||||
*/
|
||||
processKeyUp: function (event) {
|
||||
@@ -197,6 +235,10 @@ Phaser.Keyboard.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method reset
|
||||
*/
|
||||
reset: function () {
|
||||
|
||||
for (var key in this._keys)
|
||||
@@ -207,8 +249,10 @@ Phaser.Keyboard.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Number} keycode
|
||||
* @param {Number} [duration]
|
||||
* Description.
|
||||
* @method justPressed
|
||||
* @param {number} keycode
|
||||
* @param {number} [duration]
|
||||
* @return {bool}
|
||||
*/
|
||||
justPressed: function (keycode, duration) {
|
||||
@@ -224,9 +268,11 @@ Phaser.Keyboard.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Number} keycode
|
||||
* @param {Number} [duration]
|
||||
/**
|
||||
* Description.
|
||||
* @method justReleased
|
||||
* @param {number} keycode
|
||||
* @param {number} [duration]
|
||||
* @return {bool}
|
||||
*/
|
||||
justReleased: function (keycode, duration) {
|
||||
@@ -242,8 +288,10 @@ Phaser.Keyboard.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Number} keycode
|
||||
/**
|
||||
* Description.
|
||||
* @method isDown
|
||||
* @param {number} keycode
|
||||
* @return {bool}
|
||||
*/
|
||||
isDown: function (keycode) {
|
||||
|
||||
+63
-5
@@ -1,37 +1,92 @@
|
||||
/**
|
||||
* Phaser.MSPointer
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
* @module Phaser.MSPointer
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Phaser - MSPointer constructor.
|
||||
*
|
||||
* The MSPointer class handles touch interactions with the game and the resulting Pointer objects.
|
||||
* @class Phaser.MSPointer
|
||||
* @classdesc The MSPointer class handles touch interactions with the game and the resulting Pointer objects.
|
||||
* 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
|
||||
* @constructor
|
||||
* @param {Phaser.Game} game - A reference to the currently running game.
|
||||
*/
|
||||
Phaser.MSPointer = function (game) {
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - Local reference to game.
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} callbackContext - Description.
|
||||
*/
|
||||
this.callbackContext = this.game;
|
||||
|
||||
/**
|
||||
* @property {Description} mouseDownCallback - Description.
|
||||
* @default
|
||||
*/
|
||||
this.mouseDownCallback = null;
|
||||
|
||||
/**
|
||||
* @property {Description} mouseMoveCallback - Description.
|
||||
* @default
|
||||
*/
|
||||
this.mouseMoveCallback = null;
|
||||
|
||||
/**
|
||||
* @property {Description} mouseUpCallback - Description.
|
||||
* @default
|
||||
*/
|
||||
this.mouseUpCallback = null;
|
||||
|
||||
};
|
||||
|
||||
Phaser.MSPointer.prototype = {
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - Local reference to game.
|
||||
*/
|
||||
game: null,
|
||||
|
||||
/**
|
||||
* You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
|
||||
* @type {bool}
|
||||
* @property {bool} disabled
|
||||
*/
|
||||
disabled: false,
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @property {Description} _onMSPointerDown
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
_onMSPointerDown: null,
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @property {Description} _onMSPointerMove
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
_onMSPointerMove: null,
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @property {Description} _onMSPointerUp
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
_onMSPointerUp: null,
|
||||
|
||||
/**
|
||||
* Starts the event listeners running
|
||||
* Starts the event listeners running.
|
||||
* @method start
|
||||
*/
|
||||
start: function () {
|
||||
@@ -64,6 +119,7 @@ Phaser.MSPointer.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method onPointerDown
|
||||
* @param {Any} event
|
||||
**/
|
||||
@@ -82,6 +138,7 @@ Phaser.MSPointer.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method onPointerMove
|
||||
* @param {Any} event
|
||||
**/
|
||||
@@ -100,6 +157,7 @@ Phaser.MSPointer.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method onPointerUp
|
||||
* @param {Any} event
|
||||
**/
|
||||
@@ -118,7 +176,7 @@ Phaser.MSPointer.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Stop the event listeners
|
||||
* Stop the event listeners.
|
||||
* @method stop
|
||||
*/
|
||||
stop: function () {
|
||||
|
||||
+65
-4
@@ -1,10 +1,47 @@
|
||||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
* @module Phaser.Mouse
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Phaser - Mouse constructor.
|
||||
*
|
||||
* @class Phaser.Mouse
|
||||
* @classdesc The Mouse class
|
||||
* @constructor
|
||||
* @param {Phaser.Game} game - A reference to the currently running game.
|
||||
*/
|
||||
Phaser.Mouse = function (game) {
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - Local reference to game.
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} callbackContext - Description.
|
||||
*/
|
||||
this.callbackContext = this.game;
|
||||
|
||||
/**
|
||||
* @property {Description} mouseDownCallback - Description.
|
||||
* @default
|
||||
*/
|
||||
this.mouseDownCallback = null;
|
||||
|
||||
/**
|
||||
* @property {Description} mouseMoveCallback - Description.
|
||||
* @default
|
||||
*/
|
||||
this.mouseMoveCallback = null;
|
||||
|
||||
/**
|
||||
* @property {Description} mouseUpCallback - Description.
|
||||
* @default
|
||||
*/
|
||||
this.mouseUpCallback = null;
|
||||
|
||||
};
|
||||
@@ -15,22 +52,27 @@ Phaser.Mouse.RIGHT_BUTTON = 2;
|
||||
|
||||
Phaser.Mouse.prototype = {
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - Local reference to game.
|
||||
*/
|
||||
game: null,
|
||||
|
||||
/**
|
||||
* You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
|
||||
* @type {bool}
|
||||
* @property {bool} disabled
|
||||
* @default
|
||||
*/
|
||||
disabled: false,
|
||||
|
||||
/**
|
||||
* If the mouse has been Pointer Locked successfully this will be set to true.
|
||||
* @type {bool}
|
||||
* @property {bool} locked
|
||||
* @default
|
||||
*/
|
||||
locked: false,
|
||||
|
||||
/**
|
||||
* Starts the event listeners running
|
||||
* Starts the event listeners running.
|
||||
* @method start
|
||||
*/
|
||||
start: function () {
|
||||
@@ -62,6 +104,8 @@ Phaser.Mouse.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method onMouseDown
|
||||
* @param {MouseEvent} event
|
||||
*/
|
||||
onMouseDown: function (event) {
|
||||
@@ -83,6 +127,8 @@ Phaser.Mouse.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Description
|
||||
* @method onMouseMove
|
||||
* @param {MouseEvent} event
|
||||
*/
|
||||
onMouseMove: function (event) {
|
||||
@@ -104,6 +150,8 @@ Phaser.Mouse.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method onMouseUp
|
||||
* @param {MouseEvent} event
|
||||
*/
|
||||
onMouseUp: function (event) {
|
||||
@@ -124,6 +172,10 @@ Phaser.Mouse.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method requestPointerLock
|
||||
*/
|
||||
requestPointerLock: function () {
|
||||
|
||||
if (this.game.device.pointerLock)
|
||||
@@ -147,6 +199,11 @@ Phaser.Mouse.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method pointerLockChange
|
||||
* @param {MouseEvent} event
|
||||
*/
|
||||
pointerLockChange: function (event) {
|
||||
|
||||
var element = this.game.stage.canvas;
|
||||
@@ -164,6 +221,10 @@ Phaser.Mouse.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method releasePointerLock
|
||||
*/
|
||||
releasePointerLock: function () {
|
||||
|
||||
document.exitPointerLock = document.exitPointerLock || document.mozExitPointerLock || document.webkitExitPointerLock;
|
||||
@@ -177,7 +238,7 @@ Phaser.Mouse.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Stop the event listeners
|
||||
* Stop the event listeners.
|
||||
* @method stop
|
||||
*/
|
||||
stop: function () {
|
||||
|
||||
+138
-96
@@ -1,193 +1,232 @@
|
||||
/**
|
||||
* Phaser - Pointer
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
* @module Phaser.Pointer
|
||||
*/
|
||||
|
||||
/**
|
||||
* Phaser - Pointer constructor.
|
||||
*
|
||||
* A Pointer object is used by the Mouse, Touch and MSPoint managers and represents a single finger on the touch screen.
|
||||
* @class Phaser.Pointer
|
||||
* @classdesc A Pointer object is used by the Mouse, Touch and MSPoint managers and represents a single finger on the touch screen.
|
||||
* @constructor
|
||||
* @param {Phaser.Game} game - A reference to the currently running game.
|
||||
* @param {Description} id - Description.
|
||||
*/
|
||||
Phaser.Pointer = function (game, id) {
|
||||
|
||||
/**
|
||||
* Local private variable to store the status of dispatching a hold event
|
||||
* @property _holdSent
|
||||
* @type {bool}
|
||||
* Local private variable to store the status of dispatching a hold event.
|
||||
* @property {bool} _holdSent
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._holdSent = false;
|
||||
|
||||
/**
|
||||
* Local private variable storing the short-term history of pointer movements
|
||||
* @property _history
|
||||
* @type {Array}
|
||||
* Local private variable storing the short-term history of pointer movements.
|
||||
* @property {array} _history
|
||||
* @private
|
||||
*/
|
||||
this._history = [];
|
||||
|
||||
/**
|
||||
* Local private variable storing the time at which the next history drop should occur
|
||||
* @property _lastDrop
|
||||
* @type {Number}
|
||||
* @property {number} _lastDrop
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._nextDrop = 0;
|
||||
|
||||
// Monitor events outside of a state reset loop
|
||||
/**
|
||||
* Monitor events outside of a state reset loop.
|
||||
* @property {bool} _stateReset
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._stateReset = false;
|
||||
|
||||
/**
|
||||
* A Vector object containing the initial position when the Pointer was engaged with the screen.
|
||||
* @property positionDown
|
||||
* @type {Vec2}
|
||||
* @property {Vec2} positionDown
|
||||
* @default
|
||||
**/
|
||||
this.positionDown = null;
|
||||
|
||||
/**
|
||||
* A Vector object containing the current position of the Pointer on the screen.
|
||||
* @property position
|
||||
* @type {Vec2}
|
||||
* @property {Vec2} position
|
||||
* @default
|
||||
**/
|
||||
this.position = null;
|
||||
|
||||
/**
|
||||
* A Circle object centered on the x/y screen coordinates of the Pointer.
|
||||
* Default size of 44px (Apple's recommended "finger tip" size)
|
||||
* @property circle
|
||||
* @type {Circle}
|
||||
* Default size of 44px (Apple's recommended "finger tip" size).
|
||||
* @property {Circle} circle
|
||||
* @default
|
||||
**/
|
||||
this.circle = null;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property withinGame
|
||||
* @type {bool}
|
||||
* Description.
|
||||
* @property {bool} withinGame
|
||||
*/
|
||||
this.withinGame = false;
|
||||
|
||||
/**
|
||||
* The horizontal coordinate of point relative to the viewport in pixels, excluding any scroll offset
|
||||
* @property clientX
|
||||
* @type {Number}
|
||||
* The horizontal coordinate of point relative to the viewport in pixels, excluding any scroll offset.
|
||||
* @property {number} clientX
|
||||
* @default
|
||||
*/
|
||||
this.clientX = -1;
|
||||
|
||||
/**
|
||||
* The vertical coordinate of point relative to the viewport in pixels, excluding any scroll offset
|
||||
* @property clientY
|
||||
* @type {Number}
|
||||
* The vertical coordinate of point relative to the viewport in pixels, excluding any scroll offset.
|
||||
* @property {number} clientY
|
||||
* @default
|
||||
*/
|
||||
this.clientY = -1;
|
||||
|
||||
/**
|
||||
* The horizontal coordinate of point relative to the viewport in pixels, including any scroll offset
|
||||
* @property pageX
|
||||
* @type {Number}
|
||||
* The horizontal coordinate of point relative to the viewport in pixels, including any scroll offset.
|
||||
* @property {number} pageX
|
||||
* @default
|
||||
*/
|
||||
this.pageX = -1;
|
||||
|
||||
/**
|
||||
* The vertical coordinate of point relative to the viewport in pixels, including any scroll offset
|
||||
* @property pageY
|
||||
* @type {Number}
|
||||
* The vertical coordinate of point relative to the viewport in pixels, including any scroll offset.
|
||||
* @property {number} pageY
|
||||
* @default
|
||||
*/
|
||||
this.pageY = -1;
|
||||
|
||||
/**
|
||||
* The horizontal coordinate of point relative to the screen in pixels
|
||||
* @property screenX
|
||||
* @type {Number}
|
||||
* The horizontal coordinate of point relative to the screen in pixels.
|
||||
* @property {number} screenX
|
||||
* @default
|
||||
*/
|
||||
this.screenX = -1;
|
||||
|
||||
/**
|
||||
* The vertical coordinate of point relative to the screen in pixels
|
||||
* @property screenY
|
||||
* @type {Number}
|
||||
* The vertical coordinate of point relative to the screen in pixels.
|
||||
* @property {number} screenY
|
||||
* @default
|
||||
*/
|
||||
this.screenY = -1;
|
||||
|
||||
/**
|
||||
* The horizontal coordinate of point relative to the game element. This value is automatically scaled based on game size.
|
||||
* @property x
|
||||
* @type {Number}
|
||||
* @property {number} x
|
||||
* @default
|
||||
*/
|
||||
this.x = -1;
|
||||
|
||||
/**
|
||||
* The vertical coordinate of point relative to the game element. This value is automatically scaled based on game size.
|
||||
* @property y
|
||||
* @type {Number}
|
||||
* @property {number} y
|
||||
* @default
|
||||
*/
|
||||
this.y = -1;
|
||||
|
||||
/**
|
||||
* If the Pointer is a mouse this is true, otherwise false
|
||||
* @property isMouse
|
||||
* If the Pointer is a mouse this is true, otherwise false.
|
||||
* @property {bool} isMouse
|
||||
* @type {bool}
|
||||
**/
|
||||
*/
|
||||
this.isMouse = false;
|
||||
|
||||
/**
|
||||
* If the Pointer is touching the touchscreen, or the mouse button is held down, isDown is set to true
|
||||
* @property isDown
|
||||
* @type {bool}
|
||||
**/
|
||||
* If the Pointer is touching the touchscreen, or the mouse button is held down, isDown is set to true.
|
||||
* @property {bool} isDown
|
||||
* @default
|
||||
*/
|
||||
this.isDown = false;
|
||||
|
||||
/**
|
||||
* If the Pointer is not touching the touchscreen, or the mouse button is up, isUp is set to true
|
||||
* @property isUp
|
||||
* @type {bool}
|
||||
**/
|
||||
* If the Pointer is not touching the touchscreen, or the mouse button is up, isUp is set to true.
|
||||
* @property {bool} isUp
|
||||
* @default
|
||||
*/
|
||||
this.isUp = true;
|
||||
|
||||
/**
|
||||
* A timestamp representing when the Pointer first touched the touchscreen.
|
||||
* @property timeDown
|
||||
* @type {Number}
|
||||
**/
|
||||
* @property {number} timeDown
|
||||
* @default
|
||||
*/
|
||||
this.timeDown = 0;
|
||||
|
||||
/**
|
||||
* A timestamp representing when the Pointer left the touchscreen.
|
||||
* @property timeUp
|
||||
* @type {Number}
|
||||
**/
|
||||
* @property {number} timeUp
|
||||
* @default
|
||||
*/
|
||||
this.timeUp = 0;
|
||||
|
||||
/**
|
||||
* A timestamp representing when the Pointer was last tapped or clicked
|
||||
* @property previousTapTime
|
||||
* @type {Number}
|
||||
**/
|
||||
* A timestamp representing when the Pointer was last tapped or clicked.
|
||||
* @property {number} previousTapTime
|
||||
* @default
|
||||
*/
|
||||
this.previousTapTime = 0;
|
||||
|
||||
/**
|
||||
* The total number of times this Pointer has been touched to the touchscreen
|
||||
* @property totalTouches
|
||||
* @type {Number}
|
||||
**/
|
||||
* The total number of times this Pointer has been touched to the touchscreen.
|
||||
* @property {number} totalTouches
|
||||
* @default
|
||||
*/
|
||||
this.totalTouches = 0;
|
||||
|
||||
/**
|
||||
* The number of miliseconds since the last click
|
||||
* @property msSinceLastClick
|
||||
* @type {Number}
|
||||
**/
|
||||
* The number of miliseconds since the last click.
|
||||
* @property {number} msSinceLastClick
|
||||
* @default
|
||||
*/
|
||||
this.msSinceLastClick = Number.MAX_VALUE;
|
||||
|
||||
/**
|
||||
* The Game Object this Pointer is currently over / touching / dragging.
|
||||
* @property targetObject
|
||||
* @type {Any}
|
||||
**/
|
||||
* @property {Any} targetObject
|
||||
* @default
|
||||
*/
|
||||
this.targetObject = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - Local reference to game.
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* @property {Description} id - Description.
|
||||
*/
|
||||
this.id = id;
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @property {bool} isDown - Description.
|
||||
* @default
|
||||
*/
|
||||
this.active = false;
|
||||
|
||||
/**
|
||||
* Description
|
||||
* @property {Phaser.Point} position
|
||||
*/
|
||||
this.position = new Phaser.Point();
|
||||
|
||||
/**
|
||||
* Description
|
||||
* @property {Phaser.Point} positionDown
|
||||
*/
|
||||
this.positionDown = new Phaser.Point();
|
||||
|
||||
/**
|
||||
* Description
|
||||
* @property {Phaser.Circle} circle
|
||||
*/
|
||||
this.circle = new Phaser.Circle(0, 0, 44);
|
||||
|
||||
if (id == 0)
|
||||
@@ -200,7 +239,7 @@ Phaser.Pointer = function (game, id) {
|
||||
Phaser.Pointer.prototype = {
|
||||
|
||||
/**
|
||||
* Called when the Pointer is pressed onto the touchscreen
|
||||
* Called when the Pointer is pressed onto the touchscreen.
|
||||
* @method start
|
||||
* @param {Any} event
|
||||
*/
|
||||
@@ -264,6 +303,10 @@ Phaser.Pointer.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method update
|
||||
*/
|
||||
update: function () {
|
||||
|
||||
if (this.active)
|
||||
@@ -438,7 +481,7 @@ Phaser.Pointer.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Called when the Pointer leaves the target area
|
||||
* Called when the Pointer leaves the target area.
|
||||
* @method leave
|
||||
* @param {Any} event
|
||||
*/
|
||||
@@ -450,7 +493,7 @@ Phaser.Pointer.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Called when the Pointer leaves the touchscreen
|
||||
* Called when the Pointer leaves the touchscreen.
|
||||
* @method stop
|
||||
* @param {Any} event
|
||||
*/
|
||||
@@ -529,9 +572,9 @@ Phaser.Pointer.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* The Pointer is considered justPressed if the time it was pressed onto the touchscreen or clicked is less than justPressedRate
|
||||
* The Pointer is considered justPressed if the time it was pressed onto the touchscreen or clicked is less than justPressedRate.
|
||||
* @method justPressed
|
||||
* @param {Number} [duration].
|
||||
* @param {number} [duration]
|
||||
* @return {bool}
|
||||
*/
|
||||
justPressed: function (duration) {
|
||||
@@ -543,9 +586,9 @@ Phaser.Pointer.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* The Pointer is considered justReleased if the time it left the touchscreen is less than justReleasedRate
|
||||
* The Pointer is considered justReleased if the time it left the touchscreen is less than justReleasedRate.
|
||||
* @method justReleased
|
||||
* @param {Number} [duration].
|
||||
* @param {number} [duration]
|
||||
* @return {bool}
|
||||
*/
|
||||
justReleased: function (duration) {
|
||||
@@ -587,7 +630,7 @@ Phaser.Pointer.prototype = {
|
||||
/**
|
||||
* Returns a string representation of this object.
|
||||
* @method toString
|
||||
* @return {String} a string representation of the instance.
|
||||
* @return {string} A string representation of the instance.
|
||||
**/
|
||||
toString: function () {
|
||||
return "[{Pointer (id=" + this.id + " identifer=" + this.identifier + " active=" + this.active + " duration=" + this.duration + " withinGame=" + this.withinGame + " x=" + this.x + " y=" + this.y + " clientX=" + this.clientX + " clientY=" + this.clientY + " screenX=" + this.screenX + " screenY=" + this.screenY + " pageX=" + this.pageX + " pageY=" + this.pageY + ")}]";
|
||||
@@ -595,13 +638,12 @@ Phaser.Pointer.prototype = {
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* How long the Pointer has been depressed on the touchscreen. If not currently down it returns -1.
|
||||
* @return {number}
|
||||
*/
|
||||
Object.defineProperty(Phaser.Pointer.prototype, "duration", {
|
||||
|
||||
/**
|
||||
* How long the Pointer has been depressed on the touchscreen. If not currently down it returns -1.
|
||||
* @property duration
|
||||
* @type {Number}
|
||||
**/
|
||||
get: function () {
|
||||
|
||||
if (this.isUp)
|
||||
@@ -615,12 +657,12 @@ Object.defineProperty(Phaser.Pointer.prototype, "duration", {
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* Gets the X value of this Pointer in world coordinates based on the given camera.
|
||||
* @return {Description}
|
||||
*/
|
||||
Object.defineProperty(Phaser.Pointer.prototype, "worldX", {
|
||||
|
||||
/**
|
||||
* Gets the X value of this Pointer in world coordinates based on the given camera.
|
||||
* @param {Camera} [camera]
|
||||
*/
|
||||
get: function () {
|
||||
|
||||
return this.game.world.camera.x + this.x;
|
||||
@@ -629,12 +671,12 @@ Object.defineProperty(Phaser.Pointer.prototype, "worldX", {
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* Gets the Y value of this Pointer in world coordinates based on the given camera.
|
||||
* @return {Description}
|
||||
*/
|
||||
Object.defineProperty(Phaser.Pointer.prototype, "worldY", {
|
||||
|
||||
/**
|
||||
* Gets the Y value of this Pointer in world coordinates based on the given camera.
|
||||
* @param {Camera} [camera]
|
||||
*/
|
||||
get: function () {
|
||||
|
||||
return this.game.world.camera.y + this.y;
|
||||
|
||||
+71
-20
@@ -1,24 +1,75 @@
|
||||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
* @module Phaser.Touch
|
||||
*/
|
||||
|
||||
/**
|
||||
* Phaser - Touch
|
||||
*
|
||||
* The Touch class handles touch interactions with the game and the resulting Pointer objects.
|
||||
* http://www.w3.org/TR/touch-events/
|
||||
* https://developer.mozilla.org/en-US/docs/DOM/TouchList
|
||||
* http://www.html5rocks.com/en/mobile/touchandmouse/
|
||||
* Note: Android 2.x only supports 1 touch event at once, no multi-touch
|
||||
* @class
|
||||
*
|
||||
* @classdesc The Touch class handles touch interactions with the game and the resulting Pointer objects.
|
||||
* {@link http://www.w3.org/TR/touch-events/}
|
||||
* {@link https://developer.mozilla.org/en-US/docs/DOM/TouchList}
|
||||
* {@link http://www.html5rocks.com/en/mobile/touchandmouse/}
|
||||
* <p>Note: Android 2.x only supports 1 touch event at once, no multi-touch.
|
||||
* @constructor
|
||||
* @param {Phaser.Game} game - A reference to the currently running game.
|
||||
*/
|
||||
Phaser.Touch = function (game) {
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - Local reference to game.
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} callbackContext - Description.
|
||||
*/
|
||||
this.callbackContext = this.game;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} touchStartCallback - Description.
|
||||
* @default
|
||||
*/
|
||||
this.touchStartCallback = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} touchMoveCallback - Description.
|
||||
* @default
|
||||
*/
|
||||
this.touchMoveCallback = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} touchEndCallback - Description.
|
||||
* @default
|
||||
*/
|
||||
this.touchEndCallback = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} touchEnterCallback - Description.
|
||||
* @default
|
||||
*/
|
||||
this.touchEnterCallback = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} touchLeaveCallback - Description.
|
||||
* @default
|
||||
*/
|
||||
this.touchLeaveCallback = null;
|
||||
|
||||
/**
|
||||
* @property {Description} touchCancelCallback - Description.
|
||||
* @default
|
||||
*/
|
||||
this.touchCancelCallback = null;
|
||||
|
||||
|
||||
/**
|
||||
* @property {bool} preventDefault - Description.
|
||||
* @default
|
||||
*/
|
||||
this.preventDefault = true;
|
||||
|
||||
};
|
||||
@@ -29,7 +80,8 @@ Phaser.Touch.prototype = {
|
||||
|
||||
/**
|
||||
* You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
|
||||
* @type {bool}
|
||||
* @method disabled
|
||||
* @return {bool}
|
||||
*/
|
||||
disabled: false,
|
||||
|
||||
@@ -42,7 +94,7 @@ Phaser.Touch.prototype = {
|
||||
_onTouchMove: null,
|
||||
|
||||
/**
|
||||
* Starts the event listeners running
|
||||
* Starts the event listeners running.
|
||||
* @method start
|
||||
*/
|
||||
start: function () {
|
||||
@@ -86,9 +138,8 @@ Phaser.Touch.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Consumes all touchmove events on the document (only enable this if you know you need it!)
|
||||
* Consumes all touchmove events on the document (only enable this if you know you need it!).
|
||||
* @method consumeTouchMove
|
||||
* @param {Any} event
|
||||
**/
|
||||
consumeDocumentTouches: function () {
|
||||
|
||||
@@ -101,7 +152,7 @@ Phaser.Touch.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* Description.
|
||||
* @method onTouchStart
|
||||
* @param {Any} event
|
||||
**/
|
||||
@@ -133,8 +184,8 @@ Phaser.Touch.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Touch cancel - touches that were disrupted (perhaps by moving into a plugin or browser chrome)
|
||||
* Occurs for example on iOS when you put down 4 fingers and the app selector UI appears
|
||||
* Touch cancel - touches that were disrupted (perhaps by moving into a plugin or browser chrome).
|
||||
* Occurs for example on iOS when you put down 4 fingers and the app selector UI appears.
|
||||
* @method onTouchCancel
|
||||
* @param {Any} event
|
||||
**/
|
||||
@@ -165,8 +216,8 @@ Phaser.Touch.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* For touch enter and leave its a list of the touch points that have entered or left the target
|
||||
* Doesn't appear to be supported by most browsers on a canvas element yet
|
||||
* For touch enter and leave its a list of the touch points that have entered or left the target.
|
||||
* Doesn't appear to be supported by most browsers on a canvas element yet.
|
||||
* @method onTouchEnter
|
||||
* @param {Any} event
|
||||
**/
|
||||
@@ -195,8 +246,8 @@ Phaser.Touch.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* For touch enter and leave its a list of the touch points that have entered or left the target
|
||||
* Doesn't appear to be supported by most browsers on a canvas element yet
|
||||
* For touch enter and leave its a list of the touch points that have entered or left the target.
|
||||
* Doesn't appear to be supported by most browsers on a canvas element yet.
|
||||
* @method onTouchLeave
|
||||
* @param {Any} event
|
||||
**/
|
||||
@@ -220,7 +271,7 @@ Phaser.Touch.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* Description.
|
||||
* @method onTouchMove
|
||||
* @param {Any} event
|
||||
**/
|
||||
@@ -244,7 +295,7 @@ Phaser.Touch.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* Description.
|
||||
* @method onTouchEnd
|
||||
* @param {Any} event
|
||||
**/
|
||||
@@ -271,7 +322,7 @@ Phaser.Touch.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Stop the event listeners
|
||||
* Stop the event listeners.
|
||||
* @method stop
|
||||
*/
|
||||
stop: function () {
|
||||
|
||||
Reference in New Issue
Block a user