mirror of
https://github.com/photonstorm/phaser
synced 2024-11-30 00:21:04 +00:00
jsdoc work
This commit is contained in:
parent
3ba739756c
commit
fabaa493ef
6 changed files with 1126 additions and 92 deletions
|
@ -14,51 +14,175 @@ var InputManager = new Class({
|
|||
|
||||
initialize:
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @class InputManager
|
||||
* @memberOf Phaser.Input
|
||||
* @constructor
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.Game} game - [description]
|
||||
* @param {object} config - [description]
|
||||
*/
|
||||
function InputManager (game, config)
|
||||
{
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {[type]} game
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {HTMLCanvasElement} canvas
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.canvas;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {object} config
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.config = config;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {boolean} enabled
|
||||
* @default true
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.enabled = true;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {[type]} events
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.events = new EventEmitter();
|
||||
|
||||
// Standard FIFO queue
|
||||
/**
|
||||
* Standard FIFO queue.
|
||||
*
|
||||
* @property {array} queue
|
||||
* @default []
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.queue = [];
|
||||
|
||||
// Listeners (will be based on config)
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {Phaser.Input.Keyboard.KeyboardManager} keyboard
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.keyboard = new Keyboard(this);
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {Phaser.Input.Mouse.MouseManager} mouse
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.mouse = new Mouse(this);
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {Phaser.Input.Touch.TouchManager} touch
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.touch = new Touch(this);
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {Phaser.Input.Gamepad.GamepadManager} gamepad
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.gamepad = new Gamepad(this);
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {[type]} activePointer
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.activePointer = new Pointer(this, 0);
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {object} scale
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.scale = { x: 1, y: 1 };
|
||||
|
||||
// If the top-most Scene in the Scene List receives an input it will stop input from
|
||||
// propagating any lower down the scene list, i.e. if you have a UI Scene at the top
|
||||
// and click something on it, that click will not then be passed down to any other
|
||||
// Scene below. Disable this to have input events passed through all Scenes, all the time.
|
||||
/**
|
||||
* If the top-most Scene in the Scene List receives an input it will stop input from
|
||||
* propagating any lower down the scene list, i.e. if you have a UI Scene at the top
|
||||
* and click something on it, that click will not then be passed down to any other
|
||||
* Scene below. Disable this to have input events passed through all Scenes, all the time.
|
||||
*
|
||||
* @property {boolean} globalTopOnly
|
||||
* @default true
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.globalTopOnly = true;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {boolean} ignoreEvents
|
||||
* @default false
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.ignoreEvents = false;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {Phaser.Geom.Rectangle} bounds
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.bounds = new Rectangle();
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {object} _tempPoint
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this._tempPoint = { x: 0, y: 0 };
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {array} _tempHitTest
|
||||
* @private
|
||||
* @default []
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this._tempHitTest = [];
|
||||
|
||||
game.events.once('boot', this.boot, this);
|
||||
},
|
||||
|
||||
/**
|
||||
* The Boot handler is called by Phaser.Game when it first starts up.
|
||||
* The renderer is available by now.
|
||||
*/
|
||||
* The Boot handler is called by Phaser.Game when it first starts up.
|
||||
* The renderer is available by now.
|
||||
*
|
||||
* @method Phaser.Input.InputManager#boot
|
||||
* @since 3.0.0
|
||||
*/
|
||||
boot: function ()
|
||||
{
|
||||
this.canvas = this.game.canvas;
|
||||
|
@ -71,6 +195,12 @@ var InputManager = new Class({
|
|||
this.gamepad.boot();
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.InputManager#updateBounds
|
||||
* @since 3.0.0
|
||||
*/
|
||||
updateBounds: function ()
|
||||
{
|
||||
var clientRect = this.canvas.getBoundingClientRect();
|
||||
|
@ -82,6 +212,14 @@ var InputManager = new Class({
|
|||
bounds.height = clientRect.height;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.InputManager#update
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} time - [description]
|
||||
*/
|
||||
update: function (time)
|
||||
{
|
||||
this.keyboard.update();
|
||||
|
@ -156,12 +294,23 @@ var InputManager = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
// Will always return an array.
|
||||
// Array contains matching Interactive Objects.
|
||||
// Array will be empty if no objects were matched.
|
||||
|
||||
// x/y = pointer x/y (un-translated)
|
||||
|
||||
/**
|
||||
* Will always return an array.
|
||||
* Array contains matching Interactive Objects.
|
||||
* Array will be empty if no objects were matched.
|
||||
* x/y = pointer x/y (un-translated)
|
||||
*
|
||||
* @method Phaser.Input.InputManager#hitTest
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} x - [description]
|
||||
* @param {[type]} y - [description]
|
||||
* @param {[type]} gameObjects - [description]
|
||||
* @param {[type]} camera - [description]
|
||||
* @param {[type]} output - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
hitTest: function (x, y, gameObjects, camera, output)
|
||||
{
|
||||
if (output === undefined) { output = this._tempHitTest; }
|
||||
|
@ -207,9 +356,19 @@ var InputManager = new Class({
|
|||
return output;
|
||||
},
|
||||
|
||||
// x/y MUST be translated before being passed to this function,
|
||||
// unless the gameObject is guaranteed to not be rotated or scaled in any way
|
||||
|
||||
/**
|
||||
* x/y MUST be translated before being passed to this function,
|
||||
* unless the gameObject is guaranteed to not be rotated or scaled in any way.
|
||||
*
|
||||
* @method Phaser.Input.InputManager#pointWithinHitArea
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} gameObject - [description]
|
||||
* @param {[type]} x - [description]
|
||||
* @param {[type]} y - [description]
|
||||
*
|
||||
* @return {boolean} [description]
|
||||
*/
|
||||
pointWithinHitArea: function (gameObject, x, y)
|
||||
{
|
||||
var input = gameObject.input;
|
||||
|
@ -231,9 +390,19 @@ var InputManager = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
// x/y MUST be translated before being passed to this function, unless the gameObject is guaranteed to
|
||||
// be not rotated or scaled in any way
|
||||
|
||||
/**
|
||||
* x/y MUST be translated before being passed to this function,
|
||||
* unless the gameObject is guaranteed to not be rotated or scaled in any way.
|
||||
*
|
||||
* @method Phaser.Input.InputManager#pointWithinInteractiveObject
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} object - [description]
|
||||
* @param {[type]} x - [description]
|
||||
* @param {[type]} y - [description]
|
||||
*
|
||||
* @return {boolean} [description]
|
||||
*/
|
||||
pointWithinInteractiveObject: function (object, x, y)
|
||||
{
|
||||
if (!object.hitArea)
|
||||
|
@ -251,32 +420,83 @@ var InputManager = new Class({
|
|||
return object.hitAreaCallback(object.hitArea, x, y, object);
|
||||
},
|
||||
|
||||
// Called by Pointer class
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.InputManager#transformX
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} pageX - [description]
|
||||
*
|
||||
* @return {number} [description]
|
||||
*/
|
||||
transformX: function (pageX)
|
||||
{
|
||||
return (pageX - this.bounds.left) * this.scale.x;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.InputManager#transformY
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} pageY - [description]
|
||||
*
|
||||
* @return {number} [description]
|
||||
*/
|
||||
transformY: function (pageY)
|
||||
{
|
||||
return (pageY - this.bounds.top) * this.scale.y;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.InputManager#getOffsetX
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return {number} [description]
|
||||
*/
|
||||
getOffsetX: function ()
|
||||
{
|
||||
return this.bounds.left;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.InputManager#getOffsetY
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return {number} [description]
|
||||
*/
|
||||
getOffsetY: function ()
|
||||
{
|
||||
return this.bounds.top;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.InputManager#getScaleX
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return {number} [description]
|
||||
*/
|
||||
getScaleX: function ()
|
||||
{
|
||||
return this.game.config.width / this.bounds.width;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.InputManager#getScaleY
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return {number} [description]
|
||||
*/
|
||||
getScaleY: function ()
|
||||
{
|
||||
return this.game.config.height / this.bounds.height;
|
||||
|
|
|
@ -1,21 +1,16 @@
|
|||
var Class = require('../utils/Class');
|
||||
var EventEmitter = require('eventemitter3');
|
||||
var DistanceBetween = require('../math/distance/DistanceBetween');
|
||||
var InteractiveObject = require('./InteractiveObject');
|
||||
var Circle = require('../geom/circle/Circle');
|
||||
var CircleContains = require('../geom/circle/Contains');
|
||||
var Class = require('../utils/Class');
|
||||
var DistanceBetween = require('../math/distance/DistanceBetween');
|
||||
var Ellipse = require('../geom/ellipse/Ellipse');
|
||||
var EllipseContains = require('../geom/ellipse/Contains');
|
||||
var EventEmitter = require('eventemitter3');
|
||||
var InteractiveObject = require('./InteractiveObject');
|
||||
var PluginManager = require('../plugins/PluginManager');
|
||||
var Rectangle = require('../geom/rectangle/Rectangle');
|
||||
var RectangleContains = require('../geom/rectangle/Contains');
|
||||
var Triangle = require('../geom/triangle/Triangle');
|
||||
var TriangleContains = require('../geom/triangle/Contains');
|
||||
var PluginManager = require('../plugins/PluginManager');
|
||||
|
||||
// Drag Events
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API
|
||||
// Mouse Events
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent
|
||||
|
||||
var InputPlugin = new Class({
|
||||
|
||||
|
@ -23,13 +18,35 @@ var InputPlugin = new Class({
|
|||
|
||||
initialize:
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @class InputPlugin
|
||||
* @extends EventEmitter
|
||||
* @memberOf Phaser.Input
|
||||
* @constructor
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.Scene} scene - The Scene that owns this plugin.
|
||||
*/
|
||||
function InputPlugin (scene)
|
||||
{
|
||||
EventEmitter.call(this);
|
||||
|
||||
// The Scene that owns this plugin
|
||||
/**
|
||||
* The Scene that owns this plugin.
|
||||
*
|
||||
* @property {Phaser.Scene} scene
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.scene = scene;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {[type]} systems
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.systems = scene.sys;
|
||||
|
||||
if (!scene.sys.settings.isBooted)
|
||||
|
@ -37,64 +54,189 @@ var InputPlugin = new Class({
|
|||
scene.sys.events.once('boot', this.boot, this);
|
||||
}
|
||||
|
||||
// InputManager
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {Phaser.Input.InputManager} manager
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.manager = scene.sys.game.input;
|
||||
|
||||
// A reference to this.scene.sys.displayList (set in boot)
|
||||
/**
|
||||
* A reference to this.scene.sys.displayList (set in boot)
|
||||
*
|
||||
* @property {null} displayList
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.displayList;
|
||||
|
||||
// A reference to the this.scene.sys.cameras (set in boot)
|
||||
/**
|
||||
* A reference to the this.scene.sys.cameras (set in boot)
|
||||
*
|
||||
* @property {null} cameras
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.cameras;
|
||||
|
||||
// Proxy references available via the Scene
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {Phaser.Input.Keyboard.KeyboardManager} keyboard
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.keyboard = this.manager.keyboard;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {Phaser.Input.Mouse.MouseManager} mouse
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.mouse = this.manager.mouse;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {Phaser.Input.Gamepad.GamepadManager} gamepad
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.gamepad = this.manager.gamepad;
|
||||
|
||||
// Only fire callbacks and events on the top-most Game Object in the display list (emulating DOM behavior)
|
||||
// and ignore any GOs below it, or call them all?
|
||||
/**
|
||||
* Only fire callbacks and events on the top-most Game Object in the display list (emulating DOM behavior)
|
||||
* and ignore any GOs below it, or call them all?
|
||||
*
|
||||
* @property {boolean} topOnly
|
||||
* @default true
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.topOnly = true;
|
||||
|
||||
// How often should the pointer input be checked?
|
||||
// Time given in ms
|
||||
// Pointer will *always* be checked if it has been moved by the user.
|
||||
// This controls how often it will be polled if it hasn't been moved.
|
||||
// Set to 0 to poll constantly. Set to -1 to only poll on user movement.
|
||||
/**
|
||||
* How often should the pointer input be checked?
|
||||
* Time given in ms
|
||||
* Pointer will *always* be checked if it has been moved by the user.
|
||||
* This controls how often it will be polled if it hasn't been moved.
|
||||
* Set to 0 to poll constantly. Set to -1 to only poll on user movement.
|
||||
*
|
||||
* @property {integer} pollRate
|
||||
* @default -1
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.pollRate = -1;
|
||||
|
||||
// Internal counter
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {number} _pollTimer
|
||||
* @private
|
||||
* @default 0
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this._pollTimer = 0;
|
||||
|
||||
// The distance, in pixels, the pointer has to move while being held down, before it thinks it is being dragged.
|
||||
/**
|
||||
* The distance, in pixels, the pointer has to move while being held down, before it thinks it is being dragged.
|
||||
*
|
||||
* @property {number} dragDistanceThreshold
|
||||
* @default 0
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.dragDistanceThreshold = 0;
|
||||
|
||||
// The amount of time, in ms, the pointer has to be held down before it thinks it is dragging.
|
||||
/**
|
||||
* The amount of time, in ms, the pointer has to be held down before it thinks it is dragging.
|
||||
*
|
||||
* @property {number} dragTimeThreshold
|
||||
* @default 0
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.dragTimeThreshold = 0;
|
||||
|
||||
// Used to temporarily store the results of the Hit Test
|
||||
/**
|
||||
* Used to temporarily store the results of the Hit Test
|
||||
*
|
||||
* @property {array} _temp
|
||||
* @private
|
||||
* @default []
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this._temp = [];
|
||||
|
||||
// list: A list of all Game Objects that have been set to be interactive
|
||||
/**
|
||||
* A list of all Game Objects that have been set to be interactive.
|
||||
*
|
||||
* @property {array} _list
|
||||
* @private
|
||||
* @default []
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this._list = [];
|
||||
|
||||
// pendingInsertion: Objects waiting to be inserted to the list on the next call to 'begin'
|
||||
/**
|
||||
* Objects waiting to be inserted to the list on the next call to 'begin'.
|
||||
*
|
||||
* @property {array} _pendingInsertion
|
||||
* @private
|
||||
* @default []
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this._pendingInsertion = [];
|
||||
|
||||
// pendingRemoval: Objects waiting to be removed from the list on the next call to 'begin'
|
||||
/**
|
||||
* Objects waiting to be removed from the list on the next call to 'begin'.
|
||||
*
|
||||
* @property {array} _pendingRemoval
|
||||
* @private
|
||||
* @default []
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this._pendingRemoval = [];
|
||||
|
||||
// draggable: A list of all Game Objects that have been enabled for dragging
|
||||
/**
|
||||
* A list of all Game Objects that have been enabled for dragging.
|
||||
*
|
||||
* @property {array} _draggable
|
||||
* @private
|
||||
* @default []
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this._draggable = [];
|
||||
|
||||
// drag: A list of all Interactive Objects currently considered as being 'draggable' by any pointer, indexed by pointer ID
|
||||
/**
|
||||
* A list of all Interactive Objects currently considered as being 'draggable' by any pointer, indexed by pointer ID.
|
||||
*
|
||||
* @property {[type]} _drag
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this._drag = { 0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [] };
|
||||
|
||||
// over: A list of all Interactive Objects currently considered as being 'over' by any pointer, indexed by pointer ID
|
||||
/**
|
||||
* A list of all Interactive Objects currently considered as being 'over' by any pointer, indexed by pointer ID.
|
||||
*
|
||||
* @property {[type]} _over
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this._over = { 0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [] };
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {[type]} _validTypes
|
||||
* @private
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this._validTypes = [ 'onDown', 'onUp', 'onOver', 'onOut', 'onMove', 'onDragStart', 'onDrag', 'onDragEnd', 'onDragEnter', 'onDragLeave', 'onDragOver', 'onDrop' ];
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.InputPlugin#boot
|
||||
* @since 3.0.0
|
||||
*/
|
||||
boot: function ()
|
||||
{
|
||||
var eventEmitter = this.systems.events;
|
||||
|
@ -109,6 +251,14 @@ var InputPlugin = new Class({
|
|||
this.displayList = this.systems.displayList;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.InputPlugin#preUpdate
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
preUpdate: function ()
|
||||
{
|
||||
var removeList = this._pendingRemoval;
|
||||
|
@ -149,6 +299,16 @@ var InputPlugin = new Class({
|
|||
this._list = current.concat(insertList.splice(0));
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.InputPlugin#clear
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} gameObject - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
clear: function (gameObject)
|
||||
{
|
||||
var input = gameObject.input;
|
||||
|
@ -164,11 +324,31 @@ var InputPlugin = new Class({
|
|||
return gameObject;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.InputPlugin#disable
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} gameObject - [description]
|
||||
*/
|
||||
disable: function (gameObject)
|
||||
{
|
||||
gameObject.input.enabled = false;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.InputPlugin#enable
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} gameObject - [description]
|
||||
* @param {[type]} shape - [description]
|
||||
* @param {[type]} callback - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
enable: function (gameObject, shape, callback)
|
||||
{
|
||||
if (gameObject.input)
|
||||
|
@ -185,6 +365,16 @@ var InputPlugin = new Class({
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.InputPlugin#hitTestPointer
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} pointer - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
hitTestPointer: function (pointer)
|
||||
{
|
||||
var camera = this.cameras.getCameraBelowPointer(pointer);
|
||||
|
@ -203,6 +393,16 @@ var InputPlugin = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.InputPlugin#processDownEvents
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} pointer - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
processDownEvents: function (pointer)
|
||||
{
|
||||
var currentlyOver = this._temp;
|
||||
|
@ -232,6 +432,17 @@ var InputPlugin = new Class({
|
|||
return total;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.InputPlugin#processDragEvents
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} pointer - [description]
|
||||
* @param {[type]} time - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
processDragEvents: function (pointer, time)
|
||||
{
|
||||
if (this._draggable.length === 0)
|
||||
|
@ -491,6 +702,16 @@ var InputPlugin = new Class({
|
|||
return (pointer.dragState > 0);
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.InputPlugin#processMoveEvents
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} pointer - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
processMoveEvents: function (pointer)
|
||||
{
|
||||
var currentlyOver = this._temp;
|
||||
|
@ -524,6 +745,16 @@ var InputPlugin = new Class({
|
|||
return total;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.InputPlugin#processOverOutEvents
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} pointer - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
processOverOutEvents: function (pointer)
|
||||
{
|
||||
var currentlyOver = this._temp;
|
||||
|
@ -629,6 +860,14 @@ var InputPlugin = new Class({
|
|||
return previouslyOver.length;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.InputPlugin#processUpEvents
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} pointer - [description]
|
||||
*/
|
||||
processUpEvents: function (pointer)
|
||||
{
|
||||
var currentlyOver = this._temp;
|
||||
|
@ -652,7 +891,16 @@ var InputPlugin = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
// Queues a Game Object for insertion into this Input Manager on the next update.
|
||||
/**
|
||||
* Queues a Game Object for insertion into this Input Manager on the next update.
|
||||
*
|
||||
* @method Phaser.Input.InputPlugin#queueForInsertion
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} child - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
queueForInsertion: function (child)
|
||||
{
|
||||
if (this._pendingInsertion.indexOf(child) === -1 && this._list.indexOf(child) === -1)
|
||||
|
@ -663,7 +911,16 @@ var InputPlugin = new Class({
|
|||
return this;
|
||||
},
|
||||
|
||||
// Queues a Game Object for removal from this Input Manager on the next update.
|
||||
/**
|
||||
* Queues a Game Object for removal from this Input Manager on the next update.
|
||||
*
|
||||
* @method Phaser.Input.InputPlugin#queueForRemoval
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} child - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
queueForRemoval: function (child)
|
||||
{
|
||||
this._pendingRemoval.push(child);
|
||||
|
@ -671,6 +928,17 @@ var InputPlugin = new Class({
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.InputPlugin#setDraggable
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} gameObjects - [description]
|
||||
* @param {[type]} value - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
setDraggable: function (gameObjects, value)
|
||||
{
|
||||
if (value === undefined) { value = true; }
|
||||
|
@ -701,6 +969,18 @@ var InputPlugin = new Class({
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.InputPlugin#setHitArea
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} gameObjects - [description]
|
||||
* @param {[type]} shape - [description]
|
||||
* @param {[type]} callback - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
setHitArea: function (gameObjects, shape, callback)
|
||||
{
|
||||
if (shape === undefined)
|
||||
|
@ -725,6 +1005,20 @@ var InputPlugin = new Class({
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.InputPlugin#setHitAreaCircle
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} gameObjects - [description]
|
||||
* @param {[type]} x - [description]
|
||||
* @param {[type]} y - [description]
|
||||
* @param {[type]} radius - [description]
|
||||
* @param {[type]} callback - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
setHitAreaCircle: function (gameObjects, x, y, radius, callback)
|
||||
{
|
||||
if (callback === undefined) { callback = CircleContains; }
|
||||
|
@ -734,6 +1028,21 @@ var InputPlugin = new Class({
|
|||
return this.setHitArea(gameObjects, shape, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.InputPlugin#setHitAreaEllipse
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} gameObjects - [description]
|
||||
* @param {[type]} x - [description]
|
||||
* @param {[type]} y - [description]
|
||||
* @param {[type]} width - [description]
|
||||
* @param {[type]} height - [description]
|
||||
* @param {[type]} callback - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
setHitAreaEllipse: function (gameObjects, x, y, width, height, callback)
|
||||
{
|
||||
if (callback === undefined) { callback = EllipseContains; }
|
||||
|
@ -743,6 +1052,17 @@ var InputPlugin = new Class({
|
|||
return this.setHitArea(gameObjects, shape, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.InputPlugin#setHitAreaFromTexture
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} gameObjects - [description]
|
||||
* @param {[type]} callback - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
setHitAreaFromTexture: function (gameObjects, callback)
|
||||
{
|
||||
if (callback === undefined) { callback = RectangleContains; }
|
||||
|
@ -782,6 +1102,21 @@ var InputPlugin = new Class({
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.InputPlugin#setHitAreaRectangle
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} gameObjects - [description]
|
||||
* @param {[type]} x - [description]
|
||||
* @param {[type]} y - [description]
|
||||
* @param {[type]} width - [description]
|
||||
* @param {[type]} height - [description]
|
||||
* @param {[type]} callback - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
setHitAreaRectangle: function (gameObjects, x, y, width, height, callback)
|
||||
{
|
||||
if (callback === undefined) { callback = RectangleContains; }
|
||||
|
@ -791,6 +1126,23 @@ var InputPlugin = new Class({
|
|||
return this.setHitArea(gameObjects, shape, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.InputPlugin#setHitAreaTriangle
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} gameObjects - [description]
|
||||
* @param {[type]} x1 - [description]
|
||||
* @param {[type]} y1 - [description]
|
||||
* @param {[type]} x2 - [description]
|
||||
* @param {[type]} y2 - [description]
|
||||
* @param {[type]} x3 - [description]
|
||||
* @param {[type]} y3 - [description]
|
||||
* @param {[type]} callback - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
setHitAreaTriangle: function (gameObjects, x1, y1, x2, y2, x3, y3, callback)
|
||||
{
|
||||
if (callback === undefined) { callback = TriangleContains; }
|
||||
|
@ -800,6 +1152,14 @@ var InputPlugin = new Class({
|
|||
return this.setHitArea(gameObjects, shape, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.InputPlugin#setPollAlways
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
setPollAlways: function ()
|
||||
{
|
||||
this.pollRate = 0;
|
||||
|
@ -808,6 +1168,14 @@ var InputPlugin = new Class({
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.InputPlugin#setPollOnMove
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
setPollOnMove: function ()
|
||||
{
|
||||
this.pollRate = -1;
|
||||
|
@ -816,6 +1184,16 @@ var InputPlugin = new Class({
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.InputPlugin#setPollRate
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} value - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
setPollRate: function (value)
|
||||
{
|
||||
this.pollRate = value;
|
||||
|
@ -824,6 +1202,16 @@ var InputPlugin = new Class({
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.InputPlugin#setGlobalTopOnly
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} value - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
setGlobalTopOnly: function (value)
|
||||
{
|
||||
this.manager.globalTopOnly = value;
|
||||
|
@ -831,6 +1219,16 @@ var InputPlugin = new Class({
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.InputPlugin#setTopOnly
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} value - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
setTopOnly: function (value)
|
||||
{
|
||||
this.topOnly = value;
|
||||
|
@ -838,8 +1236,17 @@ var InputPlugin = new Class({
|
|||
return this;
|
||||
},
|
||||
|
||||
// Given an array of Game Objects, sort the array and return it,
|
||||
// so that the objects are in index order with the lowest at the bottom.
|
||||
/**
|
||||
* Given an array of Game Objects, sort the array and return it,
|
||||
* so that the objects are in index order with the lowest at the bottom.
|
||||
*
|
||||
* @method Phaser.Input.InputPlugin#sortGameObjects
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} gameObjects - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
sortGameObjects: function (gameObjects)
|
||||
{
|
||||
if (gameObjects.length < 2)
|
||||
|
@ -852,7 +1259,17 @@ var InputPlugin = new Class({
|
|||
return gameObjects.sort(this.sortHandlerGO.bind(this));
|
||||
},
|
||||
|
||||
// Return the child lowest down the display list (with the smallest index)
|
||||
/**
|
||||
* Return the child lowest down the display list (with the smallest index)
|
||||
*
|
||||
* @method Phaser.Input.InputPlugin#sortHandlerGO
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} childA - [description]
|
||||
* @param {[type]} childB - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
sortHandlerGO: function (childA, childB)
|
||||
{
|
||||
// The higher the index, the lower down the display list they are.
|
||||
|
@ -874,7 +1291,17 @@ var InputPlugin = new Class({
|
|||
return 0;
|
||||
},
|
||||
|
||||
// Return the child lowest down the display list (with the smallest index)
|
||||
/**
|
||||
* Return the child lowest down the display list (with the smallest index)
|
||||
*
|
||||
* @method Phaser.Input.InputPlugin#sortHandlerIO
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} childA - [description]
|
||||
* @param {[type]} childB - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
sortHandlerIO: function (childA, childB)
|
||||
{
|
||||
// The higher the index, the lower down the display list they are.
|
||||
|
@ -896,8 +1323,17 @@ var InputPlugin = new Class({
|
|||
return 0;
|
||||
},
|
||||
|
||||
// Given an array of Interactive Objects, sort the array and return it,
|
||||
// so that the objects are in index order with the lowest at the bottom.
|
||||
/**
|
||||
* Given an array of Interactive Objects, sort the array and return it,
|
||||
* so that the objects are in index order with the lowest at the bottom.
|
||||
*
|
||||
* @method Phaser.Input.InputPlugin#sortInteractiveObjects
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} interactiveObjects - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
sortInteractiveObjects: function (interactiveObjects)
|
||||
{
|
||||
if (interactiveObjects.length < 2)
|
||||
|
@ -910,6 +1346,14 @@ var InputPlugin = new Class({
|
|||
return interactiveObjects.sort(this.sortHandlerIO.bind(this));
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.InputPlugin#stopPropagation
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
stopPropagation: function ()
|
||||
{
|
||||
if (this.manager.globalTopOnly)
|
||||
|
@ -920,6 +1364,17 @@ var InputPlugin = new Class({
|
|||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.InputPlugin#update
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} time - [description]
|
||||
* @param {[type]} delta - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
update: function (time, delta)
|
||||
{
|
||||
var manager = this.manager;
|
||||
|
@ -991,7 +1446,12 @@ var InputPlugin = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
// Scene that owns this is shutting down
|
||||
/**
|
||||
* The Scene that owns this plugin is shutting down.
|
||||
*
|
||||
* @method Phaser.Input.InputPlugin#shutdown
|
||||
* @since 3.0.0
|
||||
*/
|
||||
shutdown: function ()
|
||||
{
|
||||
this._temp.length = 0;
|
||||
|
@ -1009,7 +1469,12 @@ var InputPlugin = new Class({
|
|||
this.removeAllListeners();
|
||||
},
|
||||
|
||||
// Game level nuke
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.InputPlugin#destroy
|
||||
* @since 3.0.0
|
||||
*/
|
||||
destroy: function ()
|
||||
{
|
||||
this.shutdown();
|
||||
|
@ -1023,6 +1488,13 @@ var InputPlugin = new Class({
|
|||
this.gamepad = undefined;
|
||||
},
|
||||
|
||||
/**
|
||||
* The current active input Pointer.
|
||||
*
|
||||
* @name Phaser.Input.InputPlugin#activePointer
|
||||
* @property {Phaser.Input.Pointer} activePointer
|
||||
* @since 3.0.0
|
||||
*/
|
||||
activePointer: {
|
||||
|
||||
get: function ()
|
||||
|
@ -1032,8 +1504,14 @@ var InputPlugin = new Class({
|
|||
|
||||
},
|
||||
|
||||
// The x/y coordinates of the ActivePointer based on the first camera in the camera list.
|
||||
// This is only safe to use if your game has just 1 non-transformed camera and doesn't use multi-touch.
|
||||
/**
|
||||
* The x coordinates of the ActivePointer based on the first camera in the camera list.
|
||||
* This is only safe to use if your game has just 1 non-transformed camera and doesn't use multi-touch.
|
||||
*
|
||||
* @name Phaser.Input.InputPlugin#x
|
||||
* @property {number} x
|
||||
* @since 3.0.0
|
||||
*/
|
||||
x: {
|
||||
|
||||
get: function ()
|
||||
|
@ -1043,6 +1521,14 @@ var InputPlugin = new Class({
|
|||
|
||||
},
|
||||
|
||||
/**
|
||||
* The y coordinates of the ActivePointer based on the first camera in the camera list.
|
||||
* This is only safe to use if your game has just 1 non-transformed camera and doesn't use multi-touch.
|
||||
*
|
||||
* @name Phaser.Input.InputPlugin#y
|
||||
* @property {number} y
|
||||
* @since 3.0.0
|
||||
*/
|
||||
y: {
|
||||
|
||||
get: function ()
|
||||
|
@ -1050,7 +1536,7 @@ var InputPlugin = new Class({
|
|||
return this.manager.activePointer.y;
|
||||
}
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
|
|
@ -6,26 +6,76 @@ var Axis = new Class({
|
|||
|
||||
initialize:
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @class Axis
|
||||
* @memberOf Phaser.Input.Gamepad
|
||||
* @constructor
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} pad - [description]
|
||||
* @param {integer} index - [description]
|
||||
*/
|
||||
function Axis (pad, index)
|
||||
{
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {[type]} pad
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.pad = pad;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {[type]} events
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.events = pad.events;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {integer} index
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.index = index;
|
||||
|
||||
// Between -1 and 1 with 0 being dead center
|
||||
/**
|
||||
* Between -1 and 1 with 0 being dead center.
|
||||
*
|
||||
* @property {float} value
|
||||
* @default 0
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.value = 0;
|
||||
|
||||
this.threshold = 0.05;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.Gamepad.Axis#update
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} value - [description]
|
||||
*/
|
||||
update: function (value)
|
||||
{
|
||||
this.value = value;
|
||||
},
|
||||
|
||||
// Applies threshold to the value and returns it
|
||||
/**
|
||||
* Applies threshold to the value and returns it.
|
||||
*
|
||||
* @method Phaser.Input.Gamepad.Axis#getValue
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
getValue: function ()
|
||||
{
|
||||
var percentage = (Math.abs(this.value) - this.threshold) / (1 - this.threshold);
|
||||
|
|
|
@ -6,23 +6,79 @@ var Button = new Class({
|
|||
|
||||
initialize:
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @class Button
|
||||
* @memberOf Phaser.Input.Gamepad
|
||||
* @constructor
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} pad - [description]
|
||||
* @param {integer} index - [description]
|
||||
*/
|
||||
function Button (pad, index)
|
||||
{
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {[type]} pad
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.pad = pad;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {[type]} events
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.events = pad.events;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {integer} index
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.index = index;
|
||||
|
||||
// Between 0 and 1
|
||||
/**
|
||||
* Between 0 and 1.
|
||||
*
|
||||
* @property {float} value
|
||||
* @default 0
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.value = 0;
|
||||
|
||||
// Can be set for Analogue buttons to enable a 'pressure' threshold before considered as 'pressed'
|
||||
/**
|
||||
* Can be set for Analogue buttons to enable a 'pressure' threshold before considered as 'pressed'.
|
||||
*
|
||||
* @property {float} threshold
|
||||
* @default 0
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.threshold = 0;
|
||||
|
||||
/**
|
||||
* Is the Button being pressed down or not?
|
||||
*
|
||||
* @property {boolean} pressed
|
||||
* @default false
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.pressed = false;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.Gamepad.Button#update
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} data - [description]
|
||||
*/
|
||||
update: function (data)
|
||||
{
|
||||
this.value = data.value;
|
||||
|
|
|
@ -8,54 +8,130 @@ var Gamepad = new Class({
|
|||
|
||||
initialize:
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @class Gamepad
|
||||
* @memberOf Phaser.Input.Gamepad
|
||||
* @constructor
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.Input.Gamepad.GamepadManager} manager - [description]
|
||||
* @param {[type]} id - [description]
|
||||
* @param {[type]} index - [description]
|
||||
*/
|
||||
function Gamepad (manager, id, index)
|
||||
{
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {Phaser.Input.Gamepad.GamepadManager} manager
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.manager = manager;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {[type]} events
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.events = manager.events;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {[type]} id
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.id = id;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {[type]} index
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.index = index;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {boolean} connected
|
||||
* @default true
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.connected = true;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {number} timestamp
|
||||
* @default 0
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.timestamp = 0;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {array} buttons
|
||||
* @default []
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.buttons = [];
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {array} axes
|
||||
* @default []
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.axes = [];
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.Gamepad.Gamepad#update
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} data - [description]
|
||||
*/
|
||||
update: function (data)
|
||||
{
|
||||
this.timestamp = data.timestamp;
|
||||
this.connected = data.connected;
|
||||
|
||||
// Buttons
|
||||
var i;
|
||||
|
||||
for (var i = 0; i < data.buttons.length; i++)
|
||||
var axes = this.axes;
|
||||
var buttons = this.buttons;
|
||||
|
||||
for (i = 0; i < data.buttons.length; i++)
|
||||
{
|
||||
var buttonData = data.buttons[i];
|
||||
|
||||
if (this.buttons[i] === undefined)
|
||||
if (buttons[i] === undefined)
|
||||
{
|
||||
this.buttons[i] = new Button(this, i);
|
||||
buttons[i] = new Button(this, i);
|
||||
}
|
||||
|
||||
this.buttons[i].update(buttonData);
|
||||
buttons[i].update(buttonData);
|
||||
}
|
||||
|
||||
// Axes
|
||||
for (var i = 0; i < data.axes.length; i++)
|
||||
for (i = 0; i < data.axes.length; i++)
|
||||
{
|
||||
var axisData = data.axes[i];
|
||||
|
||||
if (this.axes[i] === undefined)
|
||||
if (axes[i] === undefined)
|
||||
{
|
||||
this.axes[i] = new Axis(this, i);
|
||||
axes[i] = new Axis(this, i);
|
||||
}
|
||||
|
||||
this.axes[i].update(axisData);
|
||||
axes[i].update(axisData);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,24 +12,84 @@ var GamepadManager = new Class({
|
|||
|
||||
initialize:
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @class GamepadManager
|
||||
* @memberOf Phaser.Input.Gamepad
|
||||
* @constructor
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.Input.InputManager} inputManager - [description]
|
||||
*/
|
||||
function GamepadManager (inputManager)
|
||||
{
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {Phaser.Input.InputManager} manager
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.manager = inputManager;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {[type]} events
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.events = inputManager.events;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {boolean} enabled
|
||||
* @default false
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.enabled = false;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {null} target
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.target;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {null} handler
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.handler;
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @property {array} gamepads
|
||||
* @default []
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.gamepads = [];
|
||||
|
||||
// Standard FIFO queue
|
||||
/**
|
||||
* Standard FIFO queue.
|
||||
*
|
||||
* @property {array} queue
|
||||
* @default []
|
||||
* @since 3.0.0
|
||||
*/
|
||||
this.queue = [];
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.Gamepad.GamepadManager#boot
|
||||
* @since 3.0.0
|
||||
*/
|
||||
boot: function ()
|
||||
{
|
||||
var config = this.manager.config;
|
||||
|
@ -44,11 +104,19 @@ var GamepadManager = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.Gamepad.GamepadManager#startListeners
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
startListeners: function ()
|
||||
{
|
||||
var queue = this.queue;
|
||||
|
||||
var handler = function (event)
|
||||
var handler = function handler (event)
|
||||
{
|
||||
if (event.defaultPrevented)
|
||||
{
|
||||
|
@ -61,25 +129,42 @@ var GamepadManager = new Class({
|
|||
|
||||
this.handler = handler;
|
||||
|
||||
this.target.addEventListener('gamepadconnected', handler, false);
|
||||
this.target.addEventListener('gamepaddisconnected', handler, false);
|
||||
var target = this.target;
|
||||
|
||||
target.addEventListener('gamepadconnected', handler, false);
|
||||
target.addEventListener('gamepaddisconnected', handler, false);
|
||||
|
||||
// FF only for now:
|
||||
this.target.addEventListener('gamepadbuttondown', handler, false);
|
||||
this.target.addEventListener('gamepadbuttonup', handler, false);
|
||||
this.target.addEventListener('gamepadaxismove', handler, false);
|
||||
target.addEventListener('gamepadbuttondown', handler, false);
|
||||
target.addEventListener('gamepadbuttonup', handler, false);
|
||||
target.addEventListener('gamepadaxismove', handler, false);
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.Gamepad.GamepadManager#stopListeners
|
||||
* @since 3.0.0
|
||||
*/
|
||||
stopListeners: function ()
|
||||
{
|
||||
this.target.removeEventListener('gamepadconnected', this.handler);
|
||||
this.target.removeEventListener('gamepaddisconnected', this.handler);
|
||||
var target = this.target;
|
||||
var handler = this.handler;
|
||||
|
||||
this.target.removeEventListener('gamepadbuttondown', this.handler);
|
||||
this.target.removeEventListener('gamepadbuttonup', this.handler);
|
||||
this.target.removeEventListener('gamepadaxismove', this.handler);
|
||||
target.removeEventListener('gamepadconnected', handler);
|
||||
target.removeEventListener('gamepaddisconnected', handler);
|
||||
|
||||
target.removeEventListener('gamepadbuttondown', handler);
|
||||
target.removeEventListener('gamepadbuttonup', handler);
|
||||
target.removeEventListener('gamepadaxismove', handler);
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.Gamepad.GamepadManager#disconnectAll
|
||||
* @since 3.0.0
|
||||
*/
|
||||
disconnectAll: function ()
|
||||
{
|
||||
for (var i = 0; i < this.gamepads.length; i++)
|
||||
|
@ -88,6 +173,16 @@ var GamepadManager = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.Gamepad.GamepadManager#addPad
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} pad - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
addPad: function (pad)
|
||||
{
|
||||
var gamepad = new Gamepad(this, pad.id, pad.index);
|
||||
|
@ -97,10 +192,28 @@ var GamepadManager = new Class({
|
|||
return gamepad;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.Gamepad.GamepadManager#removePad
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} index - [description]
|
||||
* @param {[type]} pad - [description]
|
||||
*/
|
||||
removePad: function (index, pad)
|
||||
{
|
||||
// TODO
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.Gamepad.GamepadManager#refreshPads
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} pads - [description]
|
||||
*/
|
||||
refreshPads: function (pads)
|
||||
{
|
||||
if (!pads)
|
||||
|
@ -129,6 +242,14 @@ var GamepadManager = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.Gamepad.GamepadManager#getAll
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
getAll: function ()
|
||||
{
|
||||
var out = [];
|
||||
|
@ -144,6 +265,16 @@ var GamepadManager = new Class({
|
|||
return out;
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.Gamepad.GamepadManager#getPad
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {[type]} index - [description]
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
getPad: function (index)
|
||||
{
|
||||
for (var i = 0; i < this.gamepads.length; i++)
|
||||
|
@ -155,6 +286,14 @@ var GamepadManager = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* [description]
|
||||
*
|
||||
* @method Phaser.Input.Gamepad.GamepadManager#update
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return {[type]} [description]
|
||||
*/
|
||||
update: function ()
|
||||
{
|
||||
if (!this.enabled)
|
||||
|
@ -200,6 +339,13 @@ var GamepadManager = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* The total number of connected game pads.
|
||||
*
|
||||
* @name Phaser.Input.Gamepad.GamepadManager#total
|
||||
* @property {number} total
|
||||
* @since 3.0.0
|
||||
*/
|
||||
total: {
|
||||
|
||||
get: function ()
|
||||
|
|
Loading…
Reference in a new issue