Input and keyboard docs.

This commit is contained in:
Richard Davey
2013-10-02 13:18:58 +01:00
parent 852e82d0ca
commit 1a2dc05609
52 changed files with 8935 additions and 284 deletions
+146 -122
View File
@@ -2,7 +2,6 @@
* @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
*/
/**
@@ -34,8 +33,22 @@ Phaser.Input = function (game) {
};
/**
* @constant
* @type {number}
*/
Phaser.Input.MOUSE_OVERRIDES_TOUCH = 0;
/**
* @constant
* @type {number}
*/
Phaser.Input.TOUCH_OVERRIDES_MOUSE = 1;
/**
* @constant
* @type {number}
*/
Phaser.Input.MOUSE_TOUCH_COMBINE = 2;
Phaser.Input.prototype = {
@@ -63,8 +76,9 @@ Phaser.Input.prototype = {
/**
* A vector object representing the previous position of the Pointer.
* @property {Vec2} vector
* @private
* @default
**/
*/
_oldPosition: null,
/**
@@ -99,31 +113,31 @@ Phaser.Input.prototype = {
/**
* A vector object representing the current position of the Pointer.
* @property {Vec2} position
* @property {Phaser.Point} 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 {Vec2} speed
* @property {Phaser.Point} 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} circle
* Default size of 44px (Apples recommended "finger tip" size) but can be changed to anything.
* @property {Phaser.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.
* @property {Vec2} scale
* @property {Phaser.Point} scale
* @default
*/
scale: null,
@@ -147,35 +161,35 @@ Phaser.Input.prototype = {
* 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 {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 {number} holdRate
* @default
**/
*/
holdRate: 2000,
/**
* The number of milliseconds below which the Pointer is considered justPressed
* @property {number} justPressedRate
* @default
**/
*/
justPressedRate: 200,
/**
* The number of milliseconds below which the Pointer is considered justReleased
* @property {number} justReleasedRate
* @default
**/
*/
justReleasedRate: 200,
/**
@@ -184,7 +198,7 @@ Phaser.Input.prototype = {
* The history is updated at the rate specified in Input.pollRate
* @property {boolean} recordPointerHistory
* @default
**/
*/
recordPointerHistory: false,
/**
@@ -204,142 +218,146 @@ Phaser.Input.prototype = {
/**
* A Pointer object
* @property {Pointer} pointer1
**/
* @property {Phaser.Pointer} pointer1
*/
pointer1: null,
/**
* A Pointer object
* @property {Pointer} pointer2
**/
* @property {Phaser.Pointer} pointer2
*/
pointer2: null,
/**
* A Pointer object
* @property {Pointer} pointer3
**/
* @property {Phaser.Pointer} pointer3
*/
pointer3: null,
/**
* A Pointer object
* @property {Pointer} pointer4
**/
* @property {Phaser.Pointer} pointer4
*/
pointer4: null,
/**
* A Pointer object
* @property {Pointer} pointer5
**/
* @property {Phaser.Pointer} pointer5
*/
pointer5: null,
/**
* A Pointer object
* @property {Pointer} pointer6
**/
* @property {Phaser.Pointer} pointer6
*/
pointer6: null,
/**
* A Pointer object
* @property {Pointer} pointer7
**/
* @property {Phaser.Pointer} pointer7
*/
pointer7: null,
/**
* A Pointer object
* @property {Pointer} pointer8
**/
* @property {Phaser.Pointer} pointer8
*/
pointer8: null,
/**
* A Pointer object
* @property {Pointer} pointer9
**/
* @property {Phaser.Pointer} pointer9
*/
pointer9: null,
/**
* A Pointer object.
* @property {Pointer} pointer10
**/
* @property {Phaser.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 {Pointer} activePointer
* @property {Phaser.Pointer} activePointer
* @default
**/
*/
activePointer: null,
/**
* Description.
* The mouse has its own unique Phaser.Pointer object which you can use if making a desktop specific game.
* @property {Pointer} mousePointer
* @default
**/
*/
mousePointer: null,
/**
* Description.
* @property {Description} mouse
* The Mouse Input manager.
* @property {Phaser.Mouse} mouse - The Mouse Input manager.
* @default
**/
*/
mouse: null,
/**
* Description.
* @property {Description} keyboard
* The Keyboard Input manager.
* @property {Phaser.Keyboard} keyboard - The Keyboard Input manager.
* @default
**/
*/
keyboard: null,
/**
* Description.
* @property {Description} touch
* The Touch Input manager.
* @property {Phaser.Touch} touch - the Touch Input manager.
* @default
**/
*/
touch: null,
/**
* Description.
* @property {Description} mspointer
* The MSPointer Input manager.
* @property {Phaser.MSPointer} mspointer - The MSPointer Input manager.
* @default
**/
*/
mspointer: null,
/**
* Description.
* @property {Description} onDown
* A Signal that is dispatched each time a pointer is pressed down.
* @property {Phaser.Signal} onDown
* @default
**/
*/
onDown: null,
/**
* Description.
* @property {Description} onUp
* A Signal that is dispatched each time a pointer is released.
* @property {Phaser.Signal} onUp
* @default
**/
*/
onUp: null,
/**
* Description.
* @property {Description} onTap
* A Signal that is dispatched each time a pointer is tapped.
* @property {Phaser.Signal} onTap
* @default
**/
*/
onTap: null,
/**
* Description.
* @property {Description} onHold
* A Signal that is dispatched each time a pointer is held down.
* @property {Phaser.Signal} onHold
* @default
**/
*/
onHold: null,
// A linked list of interactive objects, the InputHandler components (belong to Sprites) register themselves with this
/**
* A linked list of interactive objects, the InputHandler components (belonging to Sprites) register themselves with this.
* @property {Phaser.LinkedList} interactiveItems
*/
interactiveItems: new Phaser.LinkedList(),
/**
* Starts the Input Manager running.
* @method start
**/
* @method Phaser.Input#boot
* @protected
*/
boot: function () {
this.mousePointer = new Phaser.Pointer(this.game, 0);
@@ -380,11 +398,11 @@ 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.
**/
* Add a new Pointer object to the Input Manager. By default Input creates 3 pointer objects: mousePointer, pointer1 and pointer2.
* If you need more then use this to create a new one, up to a maximum of 10.
* @method Phaser.Input#addPointer
* @return {Phaser.Pointer} A reference to the new Pointer object that was created.
*/
addPointer: function () {
var next = 0;
@@ -412,8 +430,9 @@ Phaser.Input.prototype = {
/**
* Updates the Input Manager. Called by the core Game loop.
* @method update
**/
* @method Phaser.Input#update
* @protected
*/
update: function () {
if (this.pollRate > 0 && this._pollCounter < this.pollRate)
@@ -445,9 +464,9 @@ Phaser.Input.prototype = {
/**
* Reset all of the Pointers and Input states
* @method reset
* @param {boolean} hard - A soft reset (hard = false) won't reset any signals that might be bound. A hard reset will.
**/
* @method Phaser.Input#reset
* @param {boolean} hard - A soft reset (hard = false) won't reset any Signals that might be bound. A hard reset will.
*/
reset: function (hard) {
if (this.game.isBooted == false)
@@ -489,6 +508,12 @@ Phaser.Input.prototype = {
},
/**
* Resets the speed and old position properties.
* @method Phaser.Input#resetSpeed
* @param {number} x - Sets the oldPosition.x value.
* @param {number} y - Sets the oldPosition.y value.
*/
resetSpeed: function (x, y) {
this._oldPosition.setTo(x, y);
@@ -497,11 +522,11 @@ Phaser.Input.prototype = {
},
/**
* Find the first free Pointer object and start it, passing in the event data.
* @method startPointer
* Find the first free Pointer object and start it, passing in the event data. This is called automatically by Phaser.Touch and Phaser.MSPointer.
* @method Phaser.Input#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.
**/
* @return {Phaser.Pointer} The Pointer object that was started or null if no Pointer object is available.
*/
startPointer: function (event) {
if (this.maxPointers < 10 && this.totalActivePointers == this.maxPointers)
@@ -533,11 +558,11 @@ Phaser.Input.prototype = {
},
/**
* Updates the matching Pointer object, passing in the event data.
* @method updatePointer
* Updates the matching Pointer object, passing in the event data. This is called automatically and should not normally need to be invoked.
* @method Phaser.Input#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.
**/
* @return {Phaser.Pointer} The Pointer object that was updated or null if no Pointer object is available.
*/
updatePointer: function (event) {
if (this.pointer1.active && this.pointer1.identifier == event.identifier)
@@ -565,10 +590,10 @@ Phaser.Input.prototype = {
/**
* Stops the matching Pointer object, passing in the event data.
* @method stopPointer
* @method Phaser.Input#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.
**/
* @return {Phaser.Pointer} The Pointer object that was stopped or null if no Pointer object is available.
*/
stopPointer: function (event) {
if (this.pointer1.active && this.pointer1.identifier == event.identifier)
@@ -596,10 +621,10 @@ Phaser.Input.prototype = {
/**
* Get the next Pointer object whos active property matches the given state
* @method getPointer
* @method Phaser.Input#getPointer
* @param {boolean} 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.
**/
* @return {Phaser.Pointer} A Pointer object or null if no Pointer object matches the requested state.
*/
getPointer: function (state) {
state = state || false;
@@ -629,10 +654,10 @@ Phaser.Input.prototype = {
/**
* Get the Pointer object whos identified property matches the given identifier value.
* @method getPointerFromIdentifier
* @method Phaser.Input#getPointerFromIdentifier
* @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.
**/
* @return {Phaser.Pointer} A Pointer object or null if no Pointer object matches the requested identifier.
*/
getPointerFromIdentifier: function (identifier) {
if (this.pointer1.identifier == identifier)
@@ -660,37 +685,32 @@ Phaser.Input.prototype = {
/**
* Get the distance between two Pointer objects.
* @method getDistance
* @method Phaser.Input#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.
* @method getAngle
* @method Phaser.Input#getAngle
* @param {Pointer} pointer1
* @param {Pointer} pointer2
* @return {Description} Description.
**/
*/
getAngle: function (pointer1, pointer2) {
// return Phaser.Vec2Utils.angle(pointer1.position, pointer2.position);
}
};
// 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.
* The X coordinate of the most recently active pointer. This value takes game scaling into account automatically. See Pointer.screenX/clientX for source values.
* @name Phaser.Input#x
* @property {number} x - The X coordinate of the most recently active pointer.
*/
Object.defineProperty(Phaser.Input.prototype, "x", {
@@ -705,12 +725,9 @@ 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.
* The Y coordinate of the most recently active pointer. This value takes game scaling into account automatically. See Pointer.screenY/clientY for source values.
* @name Phaser.Input#y
* @property {number} y - The Y coordinate of the most recently active pointer.
*/
Object.defineProperty(Phaser.Input.prototype, "y", {
@@ -725,8 +742,9 @@ Object.defineProperty(Phaser.Input.prototype, "y", {
});
/**
* Get
* @return {Description} Description.
* @name Phaser.Input#pollLocked
* @property {boolean} pollLocked - True if the Input is currently poll rate locked.
* @readonly
*/
Object.defineProperty(Phaser.Input.prototype, "pollLocked", {
@@ -737,8 +755,10 @@ Object.defineProperty(Phaser.Input.prototype, "pollLocked", {
});
/**
* Get the total number of inactive Pointers
* @return {number} The number of Pointers currently inactive.
* The total number of inactive Pointers
* @name Phaser.Input#totalInactivePointers
* @property {number} totalInactivePointers - The total number of inactive Pointers.
* @readonly
*/
Object.defineProperty(Phaser.Input.prototype, "totalInactivePointers", {
@@ -749,8 +769,10 @@ Object.defineProperty(Phaser.Input.prototype, "totalInactivePointers", {
});
/**
* Recalculates the total number of active Pointers
* @return {number} The number of Pointers currently active.
* The total number of active Pointers
* @name Phaser.Input#totalActivePointers
* @property {number} totalActivePointers - The total number of active Pointers.
* @readonly
*/
Object.defineProperty(Phaser.Input.prototype, "totalActivePointers", {
@@ -773,8 +795,9 @@ Object.defineProperty(Phaser.Input.prototype, "totalActivePointers", {
});
/**
* Get
* @return {Description}
* The world X coordinate of the most recently active pointer.
* @name Phaser.Input#worldX
* @property {number} worldX - The world X coordinate of the most recently active pointer.
*/
Object.defineProperty(Phaser.Input.prototype, "worldX", {
@@ -785,8 +808,9 @@ Object.defineProperty(Phaser.Input.prototype, "worldX", {
});
/**
* Get
* @return {Description}
* The world Y coordinate of the most recently active pointer.
* @name Phaser.Input#worldY
* @property {number} worldY - The world Y coordinate of the most recently active pointer.
*/
Object.defineProperty(Phaser.Input.prototype, "worldY", {