Skip to content

Commit 7c0c3cd

Browse files
committed
Updated hitTest call and added jsdocs
1 parent 4115b10 commit 7c0c3cd

1 file changed

Lines changed: 106 additions & 4 deletions

File tree

src/input/InputPlugin.js

Lines changed: 106 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ var InputPlugin = new Class({
497497

498498
// Get a list of all objects that can be seen by the camera below the pointer in the scene and store in 'output' array.
499499
// All objects in this array are input enabled, as checked by the hitTest method, so we don't need to check later on as well.
500-
var over = this.manager.hitTest(pointer.x, pointer.y, this._list, camera);
500+
var over = this.manager.hitTest(pointer, this._list, camera);
501501

502502
// Filter out the drop zones
503503
for (var i = 0; i < over.length; i++)
@@ -1579,20 +1579,110 @@ var InputPlugin = new Class({
15791579
}
15801580
},
15811581

1582+
/**
1583+
* Adds a callback to be invoked whenever the native DOM `mouseup` or `touchend` events are received.
1584+
* By setting the `isOnce` argument you can control if the callback is called once,
1585+
* or every time the DOM event occurs.
1586+
*
1587+
* Callbacks passed to this method are invoked _immediately_ when the DOM event happens,
1588+
* within the scope of the DOM event handler. Therefore, they are considered as 'native'
1589+
* from the perspective of the browser. This means they can be used for tasks such as
1590+
* opening new browser windows, or anything which explicitly requires user input to activate.
1591+
* However, as a result of this, they come with their own risks, and as such should not be used
1592+
* for general game input, but instead be reserved for special circumstances.
1593+
*
1594+
* If all you're trying to do is execute a callback when a pointer is released, then
1595+
* please use the internal Input event system instead.
1596+
*
1597+
* Please understand that these callbacks are invoked when the browser feels like doing so,
1598+
* which may be entirely out of the normal flow of the Phaser Game Loop. Therefore, you should absolutely keep
1599+
* Phaser related operations to a minimum in these callbacks. For example, don't destroy Game Objects,
1600+
* change Scenes or manipulate internal systems, otherwise you run a very real risk of creating
1601+
* heisenbugs (https://en.wikipedia.org/wiki/Heisenbug) that prove a challenge to reproduce, never mind
1602+
* solve.
1603+
*
1604+
* @method Phaser.Input.InputPlugin#addUpCallback
1605+
* @since 3.10.0
1606+
*
1607+
* @param {function} callback - The callback to be invoked on this dom event.
1608+
* @param {boolean} [isOnce=true] - `true` if the callback will only be invoked once, `false` to call every time this event happens.
1609+
*
1610+
* @return {this} The Input Plugin.
1611+
*/
15821612
addUpCallback: function (callback, isOnce)
15831613
{
15841614
this.manager.addUpCallback(callback, isOnce);
15851615

15861616
return this;
15871617
},
15881618

1619+
/**
1620+
* Adds a callback to be invoked whenever the native DOM `mousedown` or `touchstart` events are received.
1621+
* By setting the `isOnce` argument you can control if the callback is called once,
1622+
* or every time the DOM event occurs.
1623+
*
1624+
* Callbacks passed to this method are invoked _immediately_ when the DOM event happens,
1625+
* within the scope of the DOM event handler. Therefore, they are considered as 'native'
1626+
* from the perspective of the browser. This means they can be used for tasks such as
1627+
* opening new browser windows, or anything which explicitly requires user input to activate.
1628+
* However, as a result of this, they come with their own risks, and as such should not be used
1629+
* for general game input, but instead be reserved for special circumstances.
1630+
*
1631+
* If all you're trying to do is execute a callback when a pointer is down, then
1632+
* please use the internal Input event system instead.
1633+
*
1634+
* Please understand that these callbacks are invoked when the browser feels like doing so,
1635+
* which may be entirely out of the normal flow of the Phaser Game Loop. Therefore, you should absolutely keep
1636+
* Phaser related operations to a minimum in these callbacks. For example, don't destroy Game Objects,
1637+
* change Scenes or manipulate internal systems, otherwise you run a very real risk of creating
1638+
* heisenbugs (https://en.wikipedia.org/wiki/Heisenbug) that prove a challenge to reproduce, never mind
1639+
* solve.
1640+
*
1641+
* @method Phaser.Input.InputPlugin#addDownCallback
1642+
* @since 3.10.0
1643+
*
1644+
* @param {function} callback - The callback to be invoked on this dom event.
1645+
* @param {boolean} [isOnce=true] - `true` if the callback will only be invoked once, `false` to call every time this event happens.
1646+
*
1647+
* @return {this} The Input Plugin.
1648+
*/
15891649
addDownCallback: function (callback, isOnce)
15901650
{
15911651
this.manager.addDownCallback(callback, isOnce);
15921652

15931653
return this;
15941654
},
15951655

1656+
/**
1657+
* Adds a callback to be invoked whenever the native DOM `mousemove` or `touchmove` events are received.
1658+
* By setting the `isOnce` argument you can control if the callback is called once,
1659+
* or every time the DOM event occurs.
1660+
*
1661+
* Callbacks passed to this method are invoked _immediately_ when the DOM event happens,
1662+
* within the scope of the DOM event handler. Therefore, they are considered as 'native'
1663+
* from the perspective of the browser. This means they can be used for tasks such as
1664+
* opening new browser windows, or anything which explicitly requires user input to activate.
1665+
* However, as a result of this, they come with their own risks, and as such should not be used
1666+
* for general game input, but instead be reserved for special circumstances.
1667+
*
1668+
* If all you're trying to do is execute a callback when a pointer is moved, then
1669+
* please use the internal Input event system instead.
1670+
*
1671+
* Please understand that these callbacks are invoked when the browser feels like doing so,
1672+
* which may be entirely out of the normal flow of the Phaser Game Loop. Therefore, you should absolutely keep
1673+
* Phaser related operations to a minimum in these callbacks. For example, don't destroy Game Objects,
1674+
* change Scenes or manipulate internal systems, otherwise you run a very real risk of creating
1675+
* heisenbugs (https://en.wikipedia.org/wiki/Heisenbug) that prove a challenge to reproduce, never mind
1676+
* solve.
1677+
*
1678+
* @method Phaser.Input.InputPlugin#addMoveCallback
1679+
* @since 3.10.0
1680+
*
1681+
* @param {function} callback - The callback to be invoked on this dom event.
1682+
* @param {boolean} [isOnce=false] - `true` if the callback will only be invoked once, `false` to call every time this event happens.
1683+
*
1684+
* @return {this} The Input Plugin.
1685+
*/
15961686
addMoveCallback: function (callback, isOnce)
15971687
{
15981688
this.manager.addMoveCallback(callback, isOnce);
@@ -1675,14 +1765,26 @@ var InputPlugin = new Class({
16751765
},
16761766

16771767
/**
1678-
* [description]
1768+
* Adds new Pointer objects to the Input Manager.
1769+
*
1770+
* By default Phaser creates 2 pointer objects: `mousePointer` and `pointer1`.
1771+
*
1772+
* You can create more either by calling this method, or by setting the `input.activePointers` property
1773+
* in the Game Config.
1774+
*
1775+
* The first 10 pointers are available via the `InputPlugin.pointerX` properties, once they have been added
1776+
* via this method.
16791777
*
16801778
* @method Phaser.Input.InputPlugin#addPointer
16811779
* @since 3.10.0
1780+
*
1781+
* @param {integer} [quantity=1] The number of new Pointers to create.
1782+
*
1783+
* @return {Phaser.Input.Pointer[]} An array containing all of the new Pointer objects that were created.
16821784
*/
1683-
addPointer: function ()
1785+
addPointer: function (quantity)
16841786
{
1685-
return this.manager.addPointer();
1787+
return this.manager.addPointer(quantity);
16861788
},
16871789

16881790
/**

0 commit comments

Comments
 (0)