2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2015-02-25 03:36:23 +00:00
|
|
|
* @copyright 2015 Photon Storm Ltd.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2013-11-25 03:13:04 +00:00
|
|
|
* The Input Handler is bound to a specific Sprite and is responsible for managing all Input events on that Sprite.
|
2014-10-11 03:52:06 +00:00
|
|
|
*
|
2013-10-01 12:54:29 +00:00
|
|
|
* @class Phaser.InputHandler
|
|
|
|
* @constructor
|
2013-11-25 03:13:04 +00:00
|
|
|
* @param {Phaser.Sprite} sprite - The Sprite object to which this Input Handler belongs.
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2013-09-08 10:24:41 +00:00
|
|
|
Phaser.InputHandler = function (sprite) {
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
|
|
|
* @property {Phaser.Sprite} sprite - The Sprite object to which this Input Handler belongs.
|
|
|
|
*/
|
|
|
|
this.sprite = sprite;
|
2013-09-08 10:24:41 +00:00
|
|
|
|
2013-10-02 14:05:55 +00:00
|
|
|
/**
|
2014-03-23 07:59:28 +00:00
|
|
|
* @property {Phaser.Game} game - A reference to the currently running game.
|
2013-10-02 14:05:55 +00:00
|
|
|
*/
|
|
|
|
this.game = sprite.game;
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
|
|
|
* @property {boolean} enabled - If enabled the Input Handler will process input requests and monitor pointer activity.
|
|
|
|
* @default
|
|
|
|
*/
|
2013-09-08 10:24:41 +00:00
|
|
|
this.enabled = false;
|
|
|
|
|
2014-07-15 10:20:43 +00:00
|
|
|
/**
|
|
|
|
* @property {boolean} checked - A disposable flag used by the Pointer class when performing priority checks.
|
|
|
|
* @protected
|
|
|
|
*/
|
|
|
|
this.checked = false;
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2014-04-16 17:46:25 +00:00
|
|
|
* The priorityID is used to determine which game objects should get priority when input events occur. For example if you have
|
|
|
|
* several Sprites that overlap, by default the one at the top of the display list is given priority for input events. You can
|
|
|
|
* stop this from happening by controlling the priorityID value. The higher the value, the more important they are considered to the Input events.
|
|
|
|
* @property {number} priorityID
|
2013-11-25 03:13:04 +00:00
|
|
|
* @default
|
|
|
|
*/
|
2013-09-08 10:24:41 +00:00
|
|
|
this.priorityID = 0;
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
|
|
|
* @property {boolean} useHandCursor - On a desktop browser you can set the 'hand' cursor to appear when moving over the Sprite.
|
|
|
|
* @default
|
|
|
|
*/
|
2013-09-11 15:25:46 +00:00
|
|
|
this.useHandCursor = false;
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2014-03-19 00:54:49 +00:00
|
|
|
/**
|
|
|
|
* @property {boolean} _setHandCursor - Did this Sprite trigger the hand cursor?
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._setHandCursor = false;
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
|
|
|
* @property {boolean} isDragged - true if the Sprite is being currently dragged.
|
|
|
|
* @default
|
|
|
|
*/
|
2013-09-08 10:24:41 +00:00
|
|
|
this.isDragged = false;
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
|
|
|
* @property {boolean} allowHorizontalDrag - Controls if the Sprite is allowed to be dragged horizontally.
|
|
|
|
* @default
|
|
|
|
*/
|
2013-09-08 10:24:41 +00:00
|
|
|
this.allowHorizontalDrag = true;
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
|
|
|
* @property {boolean} allowVerticalDrag - Controls if the Sprite is allowed to be dragged vertically.
|
|
|
|
* @default
|
|
|
|
*/
|
2013-09-08 10:24:41 +00:00
|
|
|
this.allowVerticalDrag = true;
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
|
|
|
* @property {boolean} bringToTop - If true when this Sprite is clicked or dragged it will automatically be bought to the top of the Group it is within.
|
|
|
|
* @default
|
|
|
|
*/
|
2013-09-08 10:24:41 +00:00
|
|
|
this.bringToTop = false;
|
2013-09-11 15:25:46 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
|
|
|
* @property {Phaser.Point} snapOffset - A Point object that contains by how far the Sprite snap is offset.
|
|
|
|
* @default
|
|
|
|
*/
|
2013-09-11 15:25:46 +00:00
|
|
|
this.snapOffset = null;
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
|
|
|
* @property {boolean} snapOnDrag - When the Sprite is dragged this controls if the center of the Sprite will snap to the pointer on drag or not.
|
|
|
|
* @default
|
|
|
|
*/
|
2013-09-08 10:24:41 +00:00
|
|
|
this.snapOnDrag = false;
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
|
|
|
* @property {boolean} snapOnRelease - When the Sprite is dragged this controls if the Sprite will be snapped on release.
|
|
|
|
* @default
|
|
|
|
*/
|
2013-09-08 10:24:41 +00:00
|
|
|
this.snapOnRelease = false;
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
|
|
|
* @property {number} snapX - When a Sprite has snapping enabled this holds the width of the snap grid.
|
|
|
|
* @default
|
|
|
|
*/
|
2013-09-08 10:24:41 +00:00
|
|
|
this.snapX = 0;
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
|
|
|
* @property {number} snapY - When a Sprite has snapping enabled this holds the height of the snap grid.
|
|
|
|
* @default
|
|
|
|
*/
|
2013-09-08 10:24:41 +00:00
|
|
|
this.snapY = 0;
|
|
|
|
|
2013-12-31 17:03:09 +00:00
|
|
|
/**
|
|
|
|
* @property {number} snapOffsetX - This defines the top-left X coordinate of the snap grid.
|
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.snapOffsetX = 0;
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2013-12-31 17:03:09 +00:00
|
|
|
/**
|
|
|
|
* @property {number} snapOffsetY - This defines the top-left Y coordinate of the snap grid..
|
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.snapOffsetY = 0;
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2014-02-11 13:23:54 +00:00
|
|
|
* Set to true to use pixel perfect hit detection when checking if the pointer is over this Sprite.
|
|
|
|
* The x/y coordinates of the pointer are tested against the image in combination with the InputHandler.pixelPerfectAlpha value.
|
2015-03-23 08:13:35 +00:00
|
|
|
* This feature only works for display objects with image based textures such as Sprites. It won't work on BitmapText or Rope.
|
2014-02-11 13:23:54 +00:00
|
|
|
* Warning: This is expensive, especially on mobile (where it's not even needed!) so only enable if required. Also see the less-expensive InputHandler.pixelPerfectClick.
|
2015-02-03 21:32:09 +00:00
|
|
|
* @property {boolean} pixelPerfectOver - Use a pixel perfect check when testing for pointer over.
|
2013-11-25 03:13:04 +00:00
|
|
|
* @default
|
|
|
|
*/
|
2014-02-11 13:23:54 +00:00
|
|
|
this.pixelPerfectOver = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set to true to use pixel perfect hit detection when checking if the pointer is over this Sprite when it's clicked or touched.
|
|
|
|
* The x/y coordinates of the pointer are tested against the image in combination with the InputHandler.pixelPerfectAlpha value.
|
2015-03-23 08:13:35 +00:00
|
|
|
* This feature only works for display objects with image based textures such as Sprites. It won't work on BitmapText or Rope.
|
2014-02-11 13:23:54 +00:00
|
|
|
* Warning: This is expensive so only enable if you really need it.
|
2015-02-03 21:32:09 +00:00
|
|
|
* @property {boolean} pixelPerfectClick - Use a pixel perfect check when testing for clicks or touches on the Sprite.
|
2014-02-11 13:23:54 +00:00
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.pixelPerfectClick = false;
|
2013-09-11 15:25:46 +00:00
|
|
|
|
|
|
|
/**
|
2013-10-01 12:54:29 +00:00
|
|
|
* @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
|
2013-09-11 15:25:46 +00:00
|
|
|
*/
|
|
|
|
this.pixelPerfectAlpha = 255;
|
|
|
|
|
2013-09-08 10:24:41 +00:00
|
|
|
/**
|
2013-10-01 15:39:39 +00:00
|
|
|
* @property {boolean} draggable - Is this sprite allowed to be dragged by the mouse? true = yes, false = no
|
2014-03-23 07:59:28 +00:00
|
|
|
* @default
|
2013-09-08 10:24:41 +00:00
|
|
|
*/
|
|
|
|
this.draggable = false;
|
|
|
|
|
|
|
|
/**
|
2013-11-25 03:13:04 +00:00
|
|
|
* @property {Phaser.Rectangle} boundsRect - A region of the game world within which the sprite is restricted during drag.
|
2014-03-23 07:59:28 +00:00
|
|
|
* @default
|
2013-09-08 10:24:41 +00:00
|
|
|
*/
|
|
|
|
this.boundsRect = null;
|
|
|
|
|
|
|
|
/**
|
2013-11-25 03:13:04 +00:00
|
|
|
* @property {Phaser.Sprite} boundsSprite - A Sprite the bounds of which this sprite is restricted during drag.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @default
|
2013-09-08 10:24:41 +00:00
|
|
|
*/
|
|
|
|
this.boundsSprite = null;
|
|
|
|
|
|
|
|
/**
|
2015-02-03 19:49:48 +00:00
|
|
|
* If this object is set to consume the pointer event then it will stop all propagation from this object on.
|
2013-09-08 10:24:41 +00:00
|
|
|
* 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.
|
2013-10-01 15:39:39 +00:00
|
|
|
* @property {boolean} consumePointerEvent
|
2013-10-01 12:54:29 +00:00
|
|
|
* @default
|
2013-09-08 10:24:41 +00:00
|
|
|
*/
|
|
|
|
this.consumePointerEvent = false;
|
|
|
|
|
2014-09-25 16:01:27 +00:00
|
|
|
/**
|
|
|
|
* @property {boolean} scaleLayer - EXPERIMENTAL: Please do not use this property unless you know what it does. Likely to change in the future.
|
|
|
|
*/
|
|
|
|
this.scaleLayer = false;
|
|
|
|
|
2015-02-03 19:49:48 +00:00
|
|
|
/**
|
|
|
|
* @property {Phaser.Point} dragOffset - The offset from the Sprites position that dragging takes place from.
|
|
|
|
*/
|
|
|
|
this.dragOffset = new Phaser.Point();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {boolean} dragFromCenter - Is the Sprite dragged from its center, or the point at which the Pointer was pressed down upon it?
|
|
|
|
*/
|
|
|
|
this.dragFromCenter = false;
|
|
|
|
|
2015-03-19 00:51:01 +00:00
|
|
|
/**
|
|
|
|
* @property {Phaser.Point} dragStartPoint - The Point from which the most recent drag started from. Useful if you need to return an object to its starting position.
|
|
|
|
*/
|
|
|
|
this.dragStartPoint = new Phaser.Point();
|
|
|
|
|
2015-05-26 19:01:52 +00:00
|
|
|
/**
|
|
|
|
* @property {Phaser.Point} snapPoint - If the sprite is set to snap while dragging this holds the point of the most recent 'snap' event.
|
|
|
|
*/
|
|
|
|
this.snapPoint = new Phaser.Point();
|
|
|
|
|
2015-02-03 19:49:48 +00:00
|
|
|
/**
|
|
|
|
* @property {Phaser.Point} _dragPoint - Internal cache var.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._dragPoint = new Phaser.Point();
|
|
|
|
|
2014-05-14 01:42:44 +00:00
|
|
|
/**
|
|
|
|
* @property {boolean} _dragPhase - Internal cache var.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._dragPhase = false;
|
|
|
|
|
2014-04-10 23:06:22 +00:00
|
|
|
/**
|
|
|
|
* @property {boolean} _wasEnabled - Internal cache var.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._wasEnabled = false;
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2014-02-10 02:14:59 +00:00
|
|
|
* @property {Phaser.Point} _tempPoint - Internal cache var.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2013-11-25 03:13:04 +00:00
|
|
|
this._tempPoint = new Phaser.Point();
|
2013-09-08 16:39:23 +00:00
|
|
|
|
2014-02-10 02:14:59 +00:00
|
|
|
/**
|
|
|
|
* @property {array} _pointerData - Internal cache var.
|
|
|
|
* @private
|
|
|
|
*/
|
2013-09-30 16:12:22 +00:00
|
|
|
this._pointerData = [];
|
|
|
|
|
|
|
|
this._pointerData.push({
|
|
|
|
id: 0,
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
isDown: false,
|
|
|
|
isUp: false,
|
|
|
|
isOver: false,
|
|
|
|
isOut: false,
|
|
|
|
timeOver: 0,
|
|
|
|
timeOut: 0,
|
|
|
|
timeDown: 0,
|
|
|
|
timeUp: 0,
|
|
|
|
downDuration: 0,
|
|
|
|
isDragged: false
|
|
|
|
});
|
|
|
|
|
2013-09-08 10:24:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Phaser.InputHandler.prototype = {
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
|
|
|
* Starts the Input Handler running. This is called automatically when you enable input on a Sprite, or can be called directly if you need to set a specific priority.
|
|
|
|
* @method Phaser.InputHandler#start
|
|
|
|
* @param {number} priority - Higher priority sprites take click priority over low-priority sprites when they are stacked on-top of each other.
|
|
|
|
* @param {boolean} useHandCursor - If true the Sprite will show the hand cursor on mouse-over (doesn't apply to mobile browsers)
|
|
|
|
* @return {Phaser.Sprite} The Sprite object to which the Input Handler is bound.
|
|
|
|
*/
|
|
|
|
start: function (priority, useHandCursor) {
|
2013-09-08 12:23:21 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
priority = priority || 0;
|
2014-04-25 14:11:54 +00:00
|
|
|
if (typeof useHandCursor === 'undefined') { useHandCursor = false; }
|
2013-09-08 12:23:21 +00:00
|
|
|
|
|
|
|
// Turning on
|
2013-11-25 03:13:04 +00:00
|
|
|
if (this.enabled === false)
|
2013-09-08 12:23:21 +00:00
|
|
|
{
|
|
|
|
// Register, etc
|
2013-11-25 03:13:04 +00:00
|
|
|
this.game.input.interactiveItems.add(this);
|
2013-09-08 12:23:21 +00:00
|
|
|
this.useHandCursor = useHandCursor;
|
|
|
|
this.priorityID = priority;
|
|
|
|
|
|
|
|
for (var i = 0; i < 10; i++)
|
|
|
|
{
|
2013-09-30 16:12:22 +00:00
|
|
|
this._pointerData[i] = {
|
2013-09-08 12:23:21 +00:00
|
|
|
id: i,
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
isDown: false,
|
|
|
|
isUp: false,
|
|
|
|
isOver: false,
|
|
|
|
isOut: false,
|
|
|
|
timeOver: 0,
|
|
|
|
timeOut: 0,
|
|
|
|
timeDown: 0,
|
|
|
|
timeUp: 0,
|
|
|
|
downDuration: 0,
|
|
|
|
isDragged: false
|
2013-09-30 16:12:22 +00:00
|
|
|
};
|
2013-09-08 12:23:21 +00:00
|
|
|
}
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
this.snapOffset = new Phaser.Point();
|
2013-09-08 12:23:21 +00:00
|
|
|
this.enabled = true;
|
2014-04-10 23:06:22 +00:00
|
|
|
this._wasEnabled = true;
|
2013-09-08 12:23:21 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-04-10 23:06:22 +00:00
|
|
|
this.sprite.events.onAddedToGroup.add(this.addedToGroup, this);
|
|
|
|
this.sprite.events.onRemovedFromGroup.add(this.removedFromGroup, this);
|
|
|
|
|
2014-07-15 10:20:43 +00:00
|
|
|
this.flagged = false;
|
|
|
|
|
2013-09-08 12:23:21 +00:00
|
|
|
return this.sprite;
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
},
|
2013-09-08 12:23:21 +00:00
|
|
|
|
2014-04-10 23:06:22 +00:00
|
|
|
/**
|
|
|
|
* Handles when the parent Sprite is added to a new Group.
|
|
|
|
*
|
|
|
|
* @method Phaser.InputHandler#addedToGroup
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
addedToGroup: function () {
|
|
|
|
|
2014-05-14 01:42:44 +00:00
|
|
|
if (this._dragPhase)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-10 23:06:22 +00:00
|
|
|
if (this._wasEnabled && !this.enabled)
|
|
|
|
{
|
|
|
|
this.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles when the parent Sprite is removed from a Group.
|
|
|
|
*
|
|
|
|
* @method Phaser.InputHandler#removedFromGroup
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
removedFromGroup: function () {
|
|
|
|
|
2014-05-14 01:42:44 +00:00
|
|
|
if (this._dragPhase)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-10 23:06:22 +00:00
|
|
|
if (this.enabled)
|
|
|
|
{
|
|
|
|
this._wasEnabled = true;
|
|
|
|
this.stop();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this._wasEnabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
|
|
|
* Resets the Input Handler and disables it.
|
|
|
|
* @method Phaser.InputHandler#reset
|
|
|
|
*/
|
2013-09-08 12:23:21 +00:00
|
|
|
reset: function () {
|
|
|
|
|
|
|
|
this.enabled = false;
|
2014-07-15 10:20:43 +00:00
|
|
|
this.flagged = false;
|
2013-09-08 12:23:21 +00:00
|
|
|
|
|
|
|
for (var i = 0; i < 10; i++)
|
|
|
|
{
|
|
|
|
this._pointerData[i] = {
|
|
|
|
id: i,
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
isDown: false,
|
|
|
|
isUp: false,
|
|
|
|
isOver: false,
|
|
|
|
isOut: false,
|
|
|
|
timeOver: 0,
|
|
|
|
timeOut: 0,
|
|
|
|
timeDown: 0,
|
|
|
|
timeUp: 0,
|
|
|
|
downDuration: 0,
|
|
|
|
isDragged: false
|
|
|
|
};
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
|
|
|
* Stops the Input Handler from running.
|
|
|
|
* @method Phaser.InputHandler#stop
|
|
|
|
*/
|
|
|
|
stop: function () {
|
2013-09-08 12:23:21 +00:00
|
|
|
|
|
|
|
// Turning off
|
2013-11-25 03:13:04 +00:00
|
|
|
if (this.enabled === false)
|
2013-09-08 12:23:21 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// De-register, etc
|
|
|
|
this.enabled = false;
|
2013-11-25 03:13:04 +00:00
|
|
|
this.game.input.interactiveItems.remove(this);
|
2013-09-08 12:23:21 +00:00
|
|
|
}
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
},
|
2013-09-08 10:24:41 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
|
|
|
* Clean up memory.
|
|
|
|
* @method Phaser.InputHandler#destroy
|
|
|
|
*/
|
2013-09-08 12:23:21 +00:00
|
|
|
destroy: function () {
|
|
|
|
|
2014-04-22 00:43:22 +00:00
|
|
|
if (this.sprite)
|
2013-09-08 12:23:21 +00:00
|
|
|
{
|
2014-03-19 00:54:49 +00:00
|
|
|
if (this._setHandCursor)
|
|
|
|
{
|
|
|
|
this.game.canvas.style.cursor = "default";
|
|
|
|
this._setHandCursor = false;
|
|
|
|
}
|
|
|
|
|
2013-10-24 03:27:28 +00:00
|
|
|
this.enabled = false;
|
|
|
|
|
|
|
|
this.game.input.interactiveItems.remove(this);
|
|
|
|
|
2014-02-10 02:14:59 +00:00
|
|
|
this._pointerData.length = 0;
|
|
|
|
this.boundsRect = null;
|
|
|
|
this.boundsSprite = null;
|
2013-11-25 03:13:04 +00:00
|
|
|
this.sprite = null;
|
2013-09-08 12:23:21 +00:00
|
|
|
}
|
2014-02-10 02:14:59 +00:00
|
|
|
|
2013-09-08 12:23:21 +00:00
|
|
|
},
|
|
|
|
|
2014-03-19 00:54:49 +00:00
|
|
|
/**
|
|
|
|
* Checks if the object this InputHandler is bound to is valid for consideration in the Pointer move event.
|
|
|
|
* This is called by Phaser.Pointer and shouldn't typically be called directly.
|
|
|
|
*
|
|
|
|
* @method Phaser.InputHandler#validForInput
|
|
|
|
* @protected
|
|
|
|
* @param {number} highestID - The highest ID currently processed by the Pointer.
|
|
|
|
* @param {number} highestRenderID - The highest Render Order ID currently processed by the Pointer.
|
2014-07-15 10:20:43 +00:00
|
|
|
* @param {boolean} [includePixelPerfect=true] - If this object has `pixelPerfectClick` or `pixelPerfectOver` set should it be considered as valid?
|
2014-03-19 00:54:49 +00:00
|
|
|
* @return {boolean} True if the object this InputHandler is bound to should be considered as valid for input detection.
|
|
|
|
*/
|
2014-07-15 10:20:43 +00:00
|
|
|
validForInput: function (highestID, highestRenderID, includePixelPerfect) {
|
|
|
|
|
|
|
|
if (typeof includePixelPerfect === 'undefined') { includePixelPerfect = true; }
|
2014-03-19 00:54:49 +00:00
|
|
|
|
2014-05-06 23:11:28 +00:00
|
|
|
if (this.sprite.scale.x === 0 || this.sprite.scale.y === 0 || this.priorityID < this.game.input.minPriorityID)
|
2014-03-19 00:54:49 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-15 10:20:43 +00:00
|
|
|
// If we're trying to specifically IGNORE pixel perfect objects, then set includePixelPerfect to false and skip it
|
|
|
|
if (!includePixelPerfect && (this.pixelPerfectClick || this.pixelPerfectOver))
|
2014-03-19 00:54:49 +00:00
|
|
|
{
|
2014-07-15 10:20:43 +00:00
|
|
|
return false;
|
2014-03-19 00:54:49 +00:00
|
|
|
}
|
|
|
|
|
2015-02-16 17:22:51 +00:00
|
|
|
if (this.priorityID > highestID || (this.priorityID === highestID && this.sprite.renderOrderID < highestRenderID))
|
2014-03-19 00:54:49 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-07-15 10:20:43 +00:00
|
|
|
/**
|
|
|
|
* Is this object using pixel perfect checking?
|
|
|
|
*
|
|
|
|
* @method Phaser.InputHandler#isPixelPerfect
|
|
|
|
* @return {boolean} True if the this InputHandler has either `pixelPerfectClick` or `pixelPerfectOver` set to `true`.
|
|
|
|
*/
|
|
|
|
isPixelPerfect: function () {
|
|
|
|
|
|
|
|
return (this.pixelPerfectClick || this.pixelPerfectOver);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2013-09-08 12:23:21 +00:00
|
|
|
* 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.
|
2014-10-11 03:52:06 +00:00
|
|
|
*
|
2013-10-02 14:05:55 +00:00
|
|
|
* @method Phaser.InputHandler#pointerX
|
2014-08-28 03:07:24 +00:00
|
|
|
* @param {number} pointer - The index of the pointer to check. You can get this from Phaser.Pointer.id.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @return {number} The x coordinate of the Input pointer.
|
2013-11-25 03:13:04 +00:00
|
|
|
*/
|
2013-09-08 12:23:21 +00:00
|
|
|
pointerX: function (pointer) {
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
pointer = pointer || 0;
|
2013-09-08 12:23:21 +00:00
|
|
|
|
|
|
|
return this._pointerData[pointer].x;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2013-09-08 12:23:21 +00:00
|
|
|
* 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.
|
2014-10-11 03:52:06 +00:00
|
|
|
*
|
2013-10-02 14:05:55 +00:00
|
|
|
* @method Phaser.InputHandler#pointerY
|
2014-08-28 03:07:24 +00:00
|
|
|
* @param {number} pointer - The index of the pointer to check. You can get this from Phaser.Pointer.id.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @return {number} The y coordinate of the Input pointer.
|
2013-09-08 12:23:21 +00:00
|
|
|
*/
|
|
|
|
pointerY: function (pointer) {
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
pointer = pointer || 0;
|
2013-09-08 12:23:21 +00:00
|
|
|
|
|
|
|
return this._pointerData[pointer].y;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2014-08-28 03:07:24 +00:00
|
|
|
* If the Pointer is down this returns true. Please note that it only checks if the Pointer is down, not if it's down over any specific Sprite.
|
2014-10-11 03:52:06 +00:00
|
|
|
*
|
2013-10-02 14:05:55 +00:00
|
|
|
* @method Phaser.InputHandler#pointerDown
|
2014-08-28 03:07:24 +00:00
|
|
|
* @param {number} pointer - The index of the pointer to check. You can get this from Phaser.Pointer.id.
|
|
|
|
* @return {boolean} - True if the given pointer is down, otherwise false.
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2013-09-08 12:23:21 +00:00
|
|
|
pointerDown: function (pointer) {
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
pointer = pointer || 0;
|
2013-09-08 12:23:21 +00:00
|
|
|
|
|
|
|
return this._pointerData[pointer].isDown;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2014-08-28 03:07:24 +00:00
|
|
|
* If the Pointer is up this returns true. Please note that it only checks if the Pointer is up, not if it's up over any specific Sprite.
|
2014-10-11 03:52:06 +00:00
|
|
|
*
|
2013-10-02 14:05:55 +00:00
|
|
|
* @method Phaser.InputHandler#pointerUp
|
2014-08-28 03:07:24 +00:00
|
|
|
* @param {number} pointer - The index of the pointer to check. You can get this from Phaser.Pointer.id.
|
|
|
|
* @return {boolean} - True if the given pointer is up, otherwise false.
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2013-09-08 12:23:21 +00:00
|
|
|
pointerUp: function (pointer) {
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
pointer = pointer || 0;
|
2013-09-08 12:23:21 +00:00
|
|
|
|
|
|
|
return this._pointerData[pointer].isUp;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2013-09-08 12:23:21 +00:00
|
|
|
* A timestamp representing when the Pointer first touched the touchscreen.
|
2014-10-11 03:52:06 +00:00
|
|
|
*
|
2013-10-02 14:05:55 +00:00
|
|
|
* @method Phaser.InputHandler#pointerTimeDown
|
2014-08-28 03:07:24 +00:00
|
|
|
* @param {number} pointer - The index of the pointer to check. You can get this from Phaser.Pointer.id.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @return {number}
|
|
|
|
*/
|
2013-09-08 12:23:21 +00:00
|
|
|
pointerTimeDown: function (pointer) {
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
pointer = pointer || 0;
|
2013-09-08 12:23:21 +00:00
|
|
|
|
|
|
|
return this._pointerData[pointer].timeDown;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2013-09-08 12:23:21 +00:00
|
|
|
* A timestamp representing when the Pointer left the touchscreen.
|
2013-10-02 14:05:55 +00:00
|
|
|
* @method Phaser.InputHandler#pointerTimeUp
|
2013-11-25 03:13:04 +00:00
|
|
|
* @param {Phaser.Pointer} pointer
|
2013-10-01 12:54:29 +00:00
|
|
|
* @return {number}
|
|
|
|
*/
|
2013-09-08 12:23:21 +00:00
|
|
|
pointerTimeUp: function (pointer) {
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
pointer = pointer || 0;
|
2013-09-08 12:23:21 +00:00
|
|
|
|
|
|
|
return this._pointerData[pointer].timeUp;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2013-10-01 12:54:29 +00:00
|
|
|
* Is the Pointer over this Sprite?
|
2014-10-11 03:52:06 +00:00
|
|
|
*
|
2013-10-02 14:05:55 +00:00
|
|
|
* @method Phaser.InputHandler#pointerOver
|
2013-11-04 03:16:17 +00:00
|
|
|
* @param {number} [index] - The ID number of a Pointer to check. If you don't provide a number it will check all Pointers.
|
2014-08-28 03:07:24 +00:00
|
|
|
* @return {boolean} - True if the given pointer (if a index was given, or any pointer if not) is over this object.
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2013-11-04 03:16:17 +00:00
|
|
|
pointerOver: function (index) {
|
2013-09-08 12:23:21 +00:00
|
|
|
|
2013-11-04 20:43:59 +00:00
|
|
|
if (this.enabled)
|
2013-11-04 03:16:17 +00:00
|
|
|
{
|
2013-11-04 20:43:59 +00:00
|
|
|
if (typeof index === 'undefined')
|
2013-11-04 03:16:17 +00:00
|
|
|
{
|
2013-11-04 20:43:59 +00:00
|
|
|
for (var i = 0; i < 10; i++)
|
2013-11-04 03:16:17 +00:00
|
|
|
{
|
2013-11-04 20:43:59 +00:00
|
|
|
if (this._pointerData[i].isOver)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2013-11-04 03:16:17 +00:00
|
|
|
}
|
|
|
|
}
|
2013-11-04 20:43:59 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return this._pointerData[index].isOver;
|
|
|
|
}
|
2013-11-04 03:16:17 +00:00
|
|
|
}
|
2013-09-08 12:23:21 +00:00
|
|
|
|
2013-11-04 20:43:59 +00:00
|
|
|
return false;
|
|
|
|
|
2013-09-08 12:23:21 +00:00
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2013-10-01 12:54:29 +00:00
|
|
|
* Is the Pointer outside of this Sprite?
|
2013-10-02 14:05:55 +00:00
|
|
|
* @method Phaser.InputHandler#pointerOut
|
2013-11-04 03:16:17 +00:00
|
|
|
* @param {number} [index] - The ID number of a Pointer to check. If you don't provide a number it will check all Pointers.
|
|
|
|
* @return {boolean} True if the given pointer (if a index was given, or any pointer if not) is out of this object.
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2013-11-25 03:13:04 +00:00
|
|
|
pointerOut: function (index) {
|
2013-09-08 12:23:21 +00:00
|
|
|
|
2013-11-04 20:43:59 +00:00
|
|
|
if (this.enabled)
|
2013-11-04 03:16:17 +00:00
|
|
|
{
|
2013-11-04 20:43:59 +00:00
|
|
|
if (typeof index === 'undefined')
|
2013-11-04 03:16:17 +00:00
|
|
|
{
|
2013-11-04 20:43:59 +00:00
|
|
|
for (var i = 0; i < 10; i++)
|
2013-11-04 03:16:17 +00:00
|
|
|
{
|
2013-11-04 20:43:59 +00:00
|
|
|
if (this._pointerData[i].isOut)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2013-11-04 03:16:17 +00:00
|
|
|
}
|
|
|
|
}
|
2013-11-04 20:43:59 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return this._pointerData[index].isOut;
|
|
|
|
}
|
2013-11-04 03:16:17 +00:00
|
|
|
}
|
2013-09-08 12:23:21 +00:00
|
|
|
|
2013-11-04 20:43:59 +00:00
|
|
|
return false;
|
|
|
|
|
2013-09-08 12:23:21 +00:00
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2013-09-08 12:23:21 +00:00
|
|
|
* A timestamp representing when the Pointer first touched the touchscreen.
|
2013-10-02 14:05:55 +00:00
|
|
|
* @method Phaser.InputHandler#pointerTimeOver
|
2013-11-25 03:13:04 +00:00
|
|
|
* @param {Phaser.Pointer} pointer
|
2013-10-01 12:54:29 +00:00
|
|
|
* @return {number}
|
|
|
|
*/
|
2013-09-08 12:23:21 +00:00
|
|
|
pointerTimeOver: function (pointer) {
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
pointer = pointer || 0;
|
2013-09-08 12:23:21 +00:00
|
|
|
|
|
|
|
return this._pointerData[pointer].timeOver;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2013-09-08 12:23:21 +00:00
|
|
|
* A timestamp representing when the Pointer left the touchscreen.
|
2013-10-02 14:05:55 +00:00
|
|
|
* @method Phaser.InputHandler#pointerTimeOut
|
2013-11-25 03:13:04 +00:00
|
|
|
* @param {Phaser.Pointer} pointer
|
2013-10-01 12:54:29 +00:00
|
|
|
* @return {number}
|
|
|
|
*/
|
2013-09-08 12:23:21 +00:00
|
|
|
pointerTimeOut: function (pointer) {
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
pointer = pointer || 0;
|
2013-09-08 12:23:21 +00:00
|
|
|
|
|
|
|
return this._pointerData[pointer].timeOut;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2013-09-08 12:23:21 +00:00
|
|
|
* Is this sprite being dragged by the mouse or not?
|
2014-02-19 19:05:54 +00:00
|
|
|
* @method Phaser.InputHandler#pointerDragged
|
2013-11-25 03:13:04 +00:00
|
|
|
* @param {Phaser.Pointer} pointer
|
2014-02-19 19:05:54 +00:00
|
|
|
* @return {boolean} True if the pointer is dragging an object, otherwise false.
|
2013-09-08 12:23:21 +00:00
|
|
|
*/
|
|
|
|
pointerDragged: function (pointer) {
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
pointer = pointer || 0;
|
2013-09-08 12:23:21 +00:00
|
|
|
|
|
|
|
return this._pointerData[pointer].isDragged;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-02-12 01:25:36 +00:00
|
|
|
/**
|
2014-07-15 10:20:43 +00:00
|
|
|
* Checks if the given pointer is both down and over the Sprite this InputHandler belongs to.
|
|
|
|
* Use the `fastTest` flag is to quickly check just the bounding hit area even if `InputHandler.pixelPerfectOver` is `true`.
|
2014-10-11 03:52:06 +00:00
|
|
|
*
|
2014-02-12 01:25:36 +00:00
|
|
|
* @method Phaser.InputHandler#checkPointerDown
|
|
|
|
* @param {Phaser.Pointer} pointer
|
2014-07-15 10:20:43 +00:00
|
|
|
* @param {boolean} [fastTest=false] - Force a simple hit area check even if `pixelPerfectOver` is true for this object?
|
2014-02-19 19:05:54 +00:00
|
|
|
* @return {boolean} True if the pointer is down, otherwise false.
|
2014-02-12 01:25:36 +00:00
|
|
|
*/
|
2014-07-15 10:20:43 +00:00
|
|
|
checkPointerDown: function (pointer, fastTest) {
|
2014-02-12 01:25:36 +00:00
|
|
|
|
2014-06-22 22:03:15 +00:00
|
|
|
if (!pointer.isDown || !this.enabled || !this.sprite || !this.sprite.parent || !this.sprite.visible || !this.sprite.parent.visible)
|
2014-02-12 01:25:36 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Need to pass it a temp point, in case we need it again for the pixel check
|
|
|
|
if (this.game.input.hitTest(this.sprite, pointer, this._tempPoint))
|
|
|
|
{
|
2014-07-15 10:20:43 +00:00
|
|
|
if (typeof fastTest === 'undefined') { fastTest = false; }
|
|
|
|
|
2014-07-15 10:49:05 +00:00
|
|
|
if (!fastTest && this.pixelPerfectClick)
|
2014-02-12 01:25:36 +00:00
|
|
|
{
|
|
|
|
return this.checkPixel(this._tempPoint.x, this._tempPoint.y);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2014-07-15 10:20:43 +00:00
|
|
|
* Checks if the given pointer is over the Sprite this InputHandler belongs to.
|
|
|
|
* Use the `fastTest` flag is to quickly check just the bounding hit area even if `InputHandler.pixelPerfectOver` is `true`.
|
2014-10-11 03:52:06 +00:00
|
|
|
*
|
2013-10-02 14:05:55 +00:00
|
|
|
* @method Phaser.InputHandler#checkPointerOver
|
2013-11-25 03:13:04 +00:00
|
|
|
* @param {Phaser.Pointer} pointer
|
2014-07-15 10:20:43 +00:00
|
|
|
* @param {boolean} [fastTest=false] - Force a simple hit area check even if `pixelPerfectOver` is true for this object?
|
2013-10-01 15:39:39 +00:00
|
|
|
* @return {boolean}
|
2013-09-08 12:23:21 +00:00
|
|
|
*/
|
2014-07-15 10:20:43 +00:00
|
|
|
checkPointerOver: function (pointer, fastTest) {
|
2013-09-08 12:23:21 +00:00
|
|
|
|
2014-04-10 23:06:22 +00:00
|
|
|
if (!this.enabled || !this.sprite || !this.sprite.parent || !this.sprite.visible || !this.sprite.parent.visible)
|
2013-09-08 12:23:21 +00:00
|
|
|
{
|
2013-11-26 05:13:56 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-07 17:14:10 +00:00
|
|
|
// Need to pass it a temp point, in case we need it again for the pixel check
|
2014-02-07 18:01:58 +00:00
|
|
|
if (this.game.input.hitTest(this.sprite, pointer, this._tempPoint))
|
2013-11-26 05:13:56 +00:00
|
|
|
{
|
2014-07-15 10:20:43 +00:00
|
|
|
if (typeof fastTest === 'undefined') { fastTest = false; }
|
|
|
|
|
2014-07-15 10:49:05 +00:00
|
|
|
if (!fastTest && this.pixelPerfectOver)
|
2013-10-24 20:21:00 +00:00
|
|
|
{
|
2013-11-26 05:13:56 +00:00
|
|
|
return this.checkPixel(this._tempPoint.x, this._tempPoint.y);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return true;
|
2013-09-08 16:39:23 +00:00
|
|
|
}
|
2013-09-08 12:23:21 +00:00
|
|
|
}
|
2014-02-07 17:14:10 +00:00
|
|
|
|
|
|
|
return false;
|
2013-09-30 16:12:22 +00:00
|
|
|
|
2013-09-11 15:25:46 +00:00
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2013-11-05 16:14:24 +00:00
|
|
|
* Runs a pixel perfect check against the given x/y coordinates of the Sprite this InputHandler is bound to.
|
|
|
|
* It compares the alpha value of the pixel and if >= InputHandler.pixelPerfectAlpha it returns true.
|
|
|
|
* @method Phaser.InputHandler#checkPixel
|
|
|
|
* @param {number} x - The x coordinate to check.
|
|
|
|
* @param {number} y - The y coordinate to check.
|
2014-02-11 13:23:54 +00:00
|
|
|
* @param {Phaser.Pointer} [pointer] - The pointer to get the x/y coordinate from if not passed as the first two parameters.
|
2013-11-05 16:14:24 +00:00
|
|
|
* @return {boolean} true if there is the alpha of the pixel is >= InputHandler.pixelPerfectAlpha
|
|
|
|
*/
|
2014-02-11 13:23:54 +00:00
|
|
|
checkPixel: function (x, y, pointer) {
|
2013-09-11 15:25:46 +00:00
|
|
|
|
|
|
|
// Grab a pixel from our image into the hitCanvas and then test it
|
|
|
|
if (this.sprite.texture.baseTexture.source)
|
|
|
|
{
|
2014-02-11 13:23:54 +00:00
|
|
|
if (x === null && y === null)
|
|
|
|
{
|
|
|
|
// Use the pointer parameter
|
|
|
|
this.game.input.getLocalPosition(this.sprite, pointer, this._tempPoint);
|
|
|
|
|
|
|
|
var x = this._tempPoint.x;
|
|
|
|
var y = this._tempPoint.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.sprite.anchor.x !== 0)
|
|
|
|
{
|
|
|
|
x -= -this.sprite.texture.frame.width * this.sprite.anchor.x;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.sprite.anchor.y !== 0)
|
|
|
|
{
|
|
|
|
y -= -this.sprite.texture.frame.height * this.sprite.anchor.y;
|
|
|
|
}
|
|
|
|
|
2013-10-25 04:40:46 +00:00
|
|
|
x += this.sprite.texture.frame.x;
|
|
|
|
y += this.sprite.texture.frame.y;
|
|
|
|
|
2014-08-01 16:46:39 +00:00
|
|
|
if (this.sprite.texture.trim)
|
|
|
|
{
|
|
|
|
x -= this.sprite.texture.trim.x;
|
|
|
|
y -= this.sprite.texture.trim.y;
|
|
|
|
|
|
|
|
// If the coordinates are outside the trim area we return false immediately, to save doing a draw call
|
|
|
|
if (x < this.sprite.texture.crop.x || x > this.sprite.texture.crop.right || y < this.sprite.texture.crop.y || y > this.sprite.texture.crop.bottom)
|
|
|
|
{
|
|
|
|
this._dx = x;
|
|
|
|
this._dy = y;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this._dx = x;
|
|
|
|
this._dy = y;
|
|
|
|
|
|
|
|
this.game.input.hitContext.clearRect(0, 0, 1, 1);
|
2013-09-11 15:25:46 +00:00
|
|
|
this.game.input.hitContext.drawImage(this.sprite.texture.baseTexture.source, x, y, 1, 1, 0, 0, 1, 1);
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2013-09-11 15:25:46 +00:00
|
|
|
var rgb = this.game.input.hitContext.getImageData(0, 0, 1, 1);
|
|
|
|
|
|
|
|
if (rgb.data[3] >= this.pixelPerfectAlpha)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
2013-09-08 12:23:21 +00:00
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2013-10-01 12:54:29 +00:00
|
|
|
* Update.
|
2014-10-21 21:43:42 +00:00
|
|
|
*
|
2013-10-02 14:05:55 +00:00
|
|
|
* @method Phaser.InputHandler#update
|
2014-02-10 02:14:59 +00:00
|
|
|
* @protected
|
2013-11-25 03:13:04 +00:00
|
|
|
* @param {Phaser.Pointer} pointer
|
2013-09-08 12:23:21 +00:00
|
|
|
*/
|
|
|
|
update: function (pointer) {
|
|
|
|
|
2014-04-10 23:06:22 +00:00
|
|
|
if (this.sprite === null || this.sprite.parent === undefined)
|
2014-02-10 02:14:59 +00:00
|
|
|
{
|
|
|
|
// Abort. We've been destroyed.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-21 10:06:53 +00:00
|
|
|
if (!this.enabled || !this.sprite.visible || !this.sprite.parent.visible)
|
2013-09-08 12:23:21 +00:00
|
|
|
{
|
|
|
|
this._pointerOutHandler(pointer);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-10-21 21:43:42 +00:00
|
|
|
if (this.draggable && this._draggedPointerID === pointer.id)
|
2013-09-08 12:23:21 +00:00
|
|
|
{
|
|
|
|
return this.updateDrag(pointer);
|
|
|
|
}
|
2014-10-21 21:43:42 +00:00
|
|
|
else if (this._pointerData[pointer.id].isOver)
|
2013-09-08 12:23:21 +00:00
|
|
|
{
|
2013-09-08 21:38:19 +00:00
|
|
|
if (this.checkPointerOver(pointer))
|
2013-09-08 12:23:21 +00:00
|
|
|
{
|
|
|
|
this._pointerData[pointer.id].x = pointer.x - this.sprite.x;
|
|
|
|
this._pointerData[pointer.id].y = pointer.y - this.sprite.y;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this._pointerOutHandler(pointer);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
|
|
|
* Internal method handling the pointer over event.
|
2014-10-21 21:43:42 +00:00
|
|
|
*
|
2013-11-25 03:13:04 +00:00
|
|
|
* @method Phaser.InputHandler#_pointerOverHandler
|
|
|
|
* @private
|
2015-07-20 11:38:41 +00:00
|
|
|
* @param {Phaser.Pointer} pointer - The pointer that triggered the event
|
2013-11-25 03:13:04 +00:00
|
|
|
*/
|
2013-09-08 12:23:21 +00:00
|
|
|
_pointerOverHandler: function (pointer) {
|
|
|
|
|
2014-02-10 02:14:59 +00:00
|
|
|
if (this.sprite === null)
|
|
|
|
{
|
|
|
|
// Abort. We've been destroyed.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-28 23:47:49 +00:00
|
|
|
if (this._pointerData[pointer.id].isOver === false || pointer.dirty)
|
2013-09-08 12:23:21 +00:00
|
|
|
{
|
|
|
|
this._pointerData[pointer.id].isOver = true;
|
|
|
|
this._pointerData[pointer.id].isOut = false;
|
2014-11-08 20:01:10 +00:00
|
|
|
this._pointerData[pointer.id].timeOver = this.game.time.time;
|
2013-09-08 12:23:21 +00:00
|
|
|
this._pointerData[pointer.id].x = pointer.x - this.sprite.x;
|
|
|
|
this._pointerData[pointer.id].y = pointer.y - this.sprite.y;
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
if (this.useHandCursor && this._pointerData[pointer.id].isDragged === false)
|
2013-09-08 12:23:21 +00:00
|
|
|
{
|
2013-12-26 00:52:01 +00:00
|
|
|
this.game.canvas.style.cursor = "pointer";
|
2014-04-22 00:43:22 +00:00
|
|
|
this._setHandCursor = true;
|
2013-09-08 12:23:21 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 00:43:22 +00:00
|
|
|
if (this.sprite && this.sprite.events)
|
|
|
|
{
|
2014-12-01 03:49:15 +00:00
|
|
|
this.sprite.events.onInputOver$dispatch(this.sprite, pointer);
|
2014-04-22 00:43:22 +00:00
|
|
|
}
|
2013-09-08 12:23:21 +00:00
|
|
|
}
|
2014-02-10 02:14:59 +00:00
|
|
|
|
2013-09-08 12:23:21 +00:00
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
|
|
|
* Internal method handling the pointer out event.
|
2014-10-21 21:43:42 +00:00
|
|
|
*
|
2013-11-25 03:13:04 +00:00
|
|
|
* @method Phaser.InputHandler#_pointerOutHandler
|
|
|
|
* @private
|
2015-07-20 11:38:41 +00:00
|
|
|
* @param {Phaser.Pointer} pointer - The pointer that triggered the event.
|
2013-11-25 03:13:04 +00:00
|
|
|
*/
|
2013-09-08 12:23:21 +00:00
|
|
|
_pointerOutHandler: function (pointer) {
|
|
|
|
|
2014-02-10 02:14:59 +00:00
|
|
|
if (this.sprite === null)
|
|
|
|
{
|
|
|
|
// Abort. We've been destroyed.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-08 12:23:21 +00:00
|
|
|
this._pointerData[pointer.id].isOver = false;
|
|
|
|
this._pointerData[pointer.id].isOut = true;
|
2014-11-08 20:01:10 +00:00
|
|
|
this._pointerData[pointer.id].timeOut = this.game.time.time;
|
2013-09-08 12:23:21 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
if (this.useHandCursor && this._pointerData[pointer.id].isDragged === false)
|
2013-09-08 12:23:21 +00:00
|
|
|
{
|
2013-12-26 00:52:01 +00:00
|
|
|
this.game.canvas.style.cursor = "default";
|
2014-03-19 00:54:49 +00:00
|
|
|
this._setHandCursor = false;
|
2013-09-08 12:23:21 +00:00
|
|
|
}
|
|
|
|
|
2013-10-24 03:27:28 +00:00
|
|
|
if (this.sprite && this.sprite.events)
|
|
|
|
{
|
2014-12-01 03:49:15 +00:00
|
|
|
this.sprite.events.onInputOut$dispatch(this.sprite, pointer);
|
2013-10-24 03:27:28 +00:00
|
|
|
}
|
2013-09-08 12:23:21 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2015-07-20 11:38:41 +00:00
|
|
|
* Internal method handling the touched / clicked event.
|
|
|
|
*
|
2013-11-25 03:13:04 +00:00
|
|
|
* @method Phaser.InputHandler#_touchedHandler
|
|
|
|
* @private
|
2015-07-20 11:38:41 +00:00
|
|
|
* @param {Phaser.Pointer} pointer - The pointer that triggered the event.
|
2013-11-25 03:13:04 +00:00
|
|
|
*/
|
2013-09-08 12:23:21 +00:00
|
|
|
_touchedHandler: function (pointer) {
|
|
|
|
|
2014-02-10 02:14:59 +00:00
|
|
|
if (this.sprite === null)
|
|
|
|
{
|
|
|
|
// Abort. We've been destroyed.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-12 15:19:23 +00:00
|
|
|
if (!this._pointerData[pointer.id].isDown && this._pointerData[pointer.id].isOver)
|
2013-09-08 12:23:21 +00:00
|
|
|
{
|
2014-02-11 13:23:54 +00:00
|
|
|
if (this.pixelPerfectClick && !this.checkPixel(null, null, pointer))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-08 12:23:21 +00:00
|
|
|
this._pointerData[pointer.id].isDown = true;
|
|
|
|
this._pointerData[pointer.id].isUp = false;
|
2014-11-08 20:01:10 +00:00
|
|
|
this._pointerData[pointer.id].timeDown = this.game.time.time;
|
2014-10-11 03:52:06 +00:00
|
|
|
|
2014-04-22 00:43:22 +00:00
|
|
|
if (this.sprite && this.sprite.events)
|
|
|
|
{
|
2014-12-01 03:49:15 +00:00
|
|
|
this.sprite.events.onInputDown$dispatch(this.sprite, pointer);
|
2014-04-22 00:43:22 +00:00
|
|
|
}
|
2013-09-08 12:23:21 +00:00
|
|
|
|
2014-08-28 23:47:49 +00:00
|
|
|
// It's possible the onInputDown event created a new Sprite that is on-top of this one, so we ought to force a Pointer update
|
|
|
|
pointer.dirty = true;
|
|
|
|
|
2013-09-08 12:23:21 +00:00
|
|
|
// Start drag
|
2013-11-25 03:13:04 +00:00
|
|
|
if (this.draggable && this.isDragged === false)
|
2013-09-08 12:23:21 +00:00
|
|
|
{
|
|
|
|
this.startDrag(pointer);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.bringToTop)
|
|
|
|
{
|
|
|
|
this.sprite.bringToTop();
|
2013-11-25 03:13:04 +00:00
|
|
|
}
|
2013-09-08 12:23:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Consume the event?
|
|
|
|
return this.consumePointerEvent;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
|
|
|
* Internal method handling the pointer released event.
|
|
|
|
* @method Phaser.InputHandler#_releasedHandler
|
|
|
|
* @private
|
|
|
|
* @param {Phaser.Pointer} pointer
|
|
|
|
*/
|
2013-09-08 12:23:21 +00:00
|
|
|
_releasedHandler: function (pointer) {
|
|
|
|
|
2014-02-10 02:14:59 +00:00
|
|
|
if (this.sprite === null)
|
|
|
|
{
|
|
|
|
// Abort. We've been destroyed.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-08 12:23:21 +00:00
|
|
|
// If was previously touched by this Pointer, check if still is AND still over this item
|
|
|
|
if (this._pointerData[pointer.id].isDown && pointer.isUp)
|
|
|
|
{
|
|
|
|
this._pointerData[pointer.id].isDown = false;
|
|
|
|
this._pointerData[pointer.id].isUp = true;
|
2014-11-08 20:01:10 +00:00
|
|
|
this._pointerData[pointer.id].timeUp = this.game.time.time;
|
2013-09-08 12:23:21 +00:00
|
|
|
this._pointerData[pointer.id].downDuration = this._pointerData[pointer.id].timeUp - this._pointerData[pointer.id].timeDown;
|
|
|
|
|
|
|
|
// Only release the InputUp signal if the pointer is still over this sprite
|
2013-09-08 21:38:19 +00:00
|
|
|
if (this.checkPointerOver(pointer))
|
2013-09-08 12:23:21 +00:00
|
|
|
{
|
2013-12-31 17:03:09 +00:00
|
|
|
// Release the inputUp signal and provide optional parameter if pointer is still over the sprite or not
|
2014-04-22 00:43:22 +00:00
|
|
|
if (this.sprite && this.sprite.events)
|
|
|
|
{
|
2014-12-01 03:49:15 +00:00
|
|
|
this.sprite.events.onInputUp$dispatch(this.sprite, pointer, true);
|
2014-04-22 00:43:22 +00:00
|
|
|
}
|
2013-09-08 12:23:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-31 17:03:09 +00:00
|
|
|
// Release the inputUp signal and provide optional parameter if pointer is still over the sprite or not
|
2014-04-22 00:43:22 +00:00
|
|
|
if (this.sprite && this.sprite.events)
|
|
|
|
{
|
2014-12-01 03:49:15 +00:00
|
|
|
this.sprite.events.onInputUp$dispatch(this.sprite, pointer, false);
|
2014-04-22 00:43:22 +00:00
|
|
|
}
|
2013-12-31 17:03:09 +00:00
|
|
|
|
2013-09-08 12:23:21 +00:00
|
|
|
// Pointer outside the sprite? Reset the cursor
|
|
|
|
if (this.useHandCursor)
|
|
|
|
{
|
2013-12-26 00:52:01 +00:00
|
|
|
this.game.canvas.style.cursor = "default";
|
2014-03-19 00:54:49 +00:00
|
|
|
this._setHandCursor = false;
|
2013-09-08 12:23:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-28 23:47:49 +00:00
|
|
|
// It's possible the onInputUp event created a new Sprite that is on-top of this one, so we ought to force a Pointer update
|
|
|
|
pointer.dirty = true;
|
|
|
|
|
2013-09-08 12:23:21 +00:00
|
|
|
// Stop drag
|
2014-05-14 01:42:44 +00:00
|
|
|
if (this.draggable && this.isDragged && this._draggedPointerID === pointer.id)
|
2013-09-08 12:23:21 +00:00
|
|
|
{
|
|
|
|
this.stopDrag(pointer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2013-09-08 12:23:21 +00:00
|
|
|
* Updates the Pointer drag on this Sprite.
|
2013-10-02 14:05:55 +00:00
|
|
|
* @method Phaser.InputHandler#updateDrag
|
2013-11-25 03:13:04 +00:00
|
|
|
* @param {Phaser.Pointer} pointer
|
2013-10-01 15:39:39 +00:00
|
|
|
* @return {boolean}
|
2013-09-08 12:23:21 +00:00
|
|
|
*/
|
|
|
|
updateDrag: function (pointer) {
|
|
|
|
|
|
|
|
if (pointer.isUp)
|
|
|
|
{
|
|
|
|
this.stopDrag(pointer);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-09-25 16:01:27 +00:00
|
|
|
var px = this.globalToLocalX(pointer.x) + this._dragPoint.x + this.dragOffset.x;
|
|
|
|
var py = this.globalToLocalY(pointer.y) + this._dragPoint.y + this.dragOffset.y;
|
|
|
|
|
2013-12-22 03:46:08 +00:00
|
|
|
if (this.sprite.fixedToCamera)
|
2013-09-08 12:23:21 +00:00
|
|
|
{
|
2013-12-22 03:46:08 +00:00
|
|
|
if (this.allowHorizontalDrag)
|
|
|
|
{
|
2014-09-25 16:01:27 +00:00
|
|
|
this.sprite.cameraOffset.x = px;
|
2013-12-22 03:46:08 +00:00
|
|
|
}
|
2013-09-08 12:23:21 +00:00
|
|
|
|
2013-12-22 03:46:08 +00:00
|
|
|
if (this.allowVerticalDrag)
|
|
|
|
{
|
2014-09-25 16:01:27 +00:00
|
|
|
this.sprite.cameraOffset.y = py;
|
2013-12-22 03:46:08 +00:00
|
|
|
}
|
2013-09-08 12:23:21 +00:00
|
|
|
|
2013-12-22 03:46:08 +00:00
|
|
|
if (this.boundsRect)
|
|
|
|
{
|
|
|
|
this.checkBoundsRect();
|
|
|
|
}
|
2013-09-08 12:23:21 +00:00
|
|
|
|
2013-12-22 03:46:08 +00:00
|
|
|
if (this.boundsSprite)
|
|
|
|
{
|
|
|
|
this.checkBoundsSprite();
|
|
|
|
}
|
2013-09-08 12:23:21 +00:00
|
|
|
|
2013-12-22 03:46:08 +00:00
|
|
|
if (this.snapOnDrag)
|
|
|
|
{
|
2013-12-31 17:03:09 +00:00
|
|
|
this.sprite.cameraOffset.x = Math.round((this.sprite.cameraOffset.x - (this.snapOffsetX % this.snapX)) / this.snapX) * this.snapX + (this.snapOffsetX % this.snapX);
|
|
|
|
this.sprite.cameraOffset.y = Math.round((this.sprite.cameraOffset.y - (this.snapOffsetY % this.snapY)) / this.snapY) * this.snapY + (this.snapOffsetY % this.snapY);
|
2015-06-04 19:58:00 +00:00
|
|
|
this.snapPoint.set(this.sprite.cameraOffset.x, this.sprite.cameraOffset.y);
|
2013-12-22 03:46:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2013-09-08 12:23:21 +00:00
|
|
|
{
|
2013-12-22 03:46:08 +00:00
|
|
|
if (this.allowHorizontalDrag)
|
|
|
|
{
|
2014-09-25 16:01:27 +00:00
|
|
|
this.sprite.x = px;
|
2013-12-22 03:46:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.allowVerticalDrag)
|
|
|
|
{
|
2014-09-25 16:01:27 +00:00
|
|
|
this.sprite.y = py;
|
2013-12-22 03:46:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.boundsRect)
|
|
|
|
{
|
|
|
|
this.checkBoundsRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.boundsSprite)
|
|
|
|
{
|
|
|
|
this.checkBoundsSprite();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.snapOnDrag)
|
|
|
|
{
|
2013-12-31 17:03:09 +00:00
|
|
|
this.sprite.x = Math.round((this.sprite.x - (this.snapOffsetX % this.snapX)) / this.snapX) * this.snapX + (this.snapOffsetX % this.snapX);
|
|
|
|
this.sprite.y = Math.round((this.sprite.y - (this.snapOffsetY % this.snapY)) / this.snapY) * this.snapY + (this.snapOffsetY % this.snapY);
|
2015-06-04 19:58:00 +00:00
|
|
|
this.snapPoint.set(this.sprite.x, this.sprite.y);
|
2013-12-22 03:46:08 +00:00
|
|
|
}
|
2013-09-08 12:23:21 +00:00
|
|
|
}
|
|
|
|
|
2015-06-04 19:58:00 +00:00
|
|
|
this.sprite.events.onDragUpdate.dispatch(this.sprite, pointer, px, py, this.snapPoint);
|
|
|
|
|
2013-09-08 12:23:21 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2013-09-08 12:23:21 +00:00
|
|
|
* Returns true if the pointer has entered the Sprite within the specified delay time (defaults to 500ms, half a second)
|
2013-10-02 14:05:55 +00:00
|
|
|
* @method Phaser.InputHandler#justOver
|
2013-11-25 03:13:04 +00:00
|
|
|
* @param {Phaser.Pointer} pointer
|
2013-10-01 12:54:29 +00:00
|
|
|
* @param {number} delay - The time below which the pointer is considered as just over.
|
2013-10-01 15:39:39 +00:00
|
|
|
* @return {boolean}
|
2013-09-08 12:23:21 +00:00
|
|
|
*/
|
|
|
|
justOver: function (pointer, delay) {
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
pointer = pointer || 0;
|
|
|
|
delay = delay || 500;
|
2013-09-08 12:23:21 +00:00
|
|
|
|
|
|
|
return (this._pointerData[pointer].isOver && this.overDuration(pointer) < delay);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2013-09-08 12:23:21 +00:00
|
|
|
* Returns true if the pointer has left the Sprite within the specified delay time (defaults to 500ms, half a second)
|
2013-10-02 14:05:55 +00:00
|
|
|
* @method Phaser.InputHandler#justOut
|
2013-11-25 03:13:04 +00:00
|
|
|
* @param {Phaser.Pointer} pointer
|
2013-10-01 12:54:29 +00:00
|
|
|
* @param {number} delay - The time below which the pointer is considered as just out.
|
2013-10-01 15:39:39 +00:00
|
|
|
* @return {boolean}
|
2013-09-08 12:23:21 +00:00
|
|
|
*/
|
|
|
|
justOut: function (pointer, delay) {
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
pointer = pointer || 0;
|
|
|
|
delay = delay || 500;
|
2013-09-08 12:23:21 +00:00
|
|
|
|
2014-11-08 20:01:10 +00:00
|
|
|
return (this._pointerData[pointer].isOut && (this.game.time.time - this._pointerData[pointer].timeOut < delay));
|
2013-09-08 12:23:21 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2014-02-11 13:23:54 +00:00
|
|
|
* Returns true if the pointer has touched or clicked on the Sprite within the specified delay time (defaults to 500ms, half a second)
|
2013-10-02 14:05:55 +00:00
|
|
|
* @method Phaser.InputHandler#justPressed
|
2013-11-25 03:13:04 +00:00
|
|
|
* @param {Phaser.Pointer} pointer
|
2013-10-01 12:54:29 +00:00
|
|
|
* @param {number} delay - The time below which the pointer is considered as just over.
|
2013-10-01 15:39:39 +00:00
|
|
|
* @return {boolean}
|
2013-09-08 12:23:21 +00:00
|
|
|
*/
|
|
|
|
justPressed: function (pointer, delay) {
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
pointer = pointer || 0;
|
|
|
|
delay = delay || 500;
|
2013-09-08 12:23:21 +00:00
|
|
|
|
|
|
|
return (this._pointerData[pointer].isDown && this.downDuration(pointer) < delay);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2014-02-11 13:23:54 +00:00
|
|
|
* Returns true if the pointer was touching this Sprite, but has been released within the specified delay time (defaults to 500ms, half a second)
|
2013-10-02 14:05:55 +00:00
|
|
|
* @method Phaser.InputHandler#justReleased
|
2013-11-25 03:13:04 +00:00
|
|
|
* @param {Phaser.Pointer} pointer
|
2013-10-01 12:54:29 +00:00
|
|
|
* @param {number} delay - The time below which the pointer is considered as just out.
|
2013-10-01 15:39:39 +00:00
|
|
|
* @return {boolean}
|
2013-09-08 12:23:21 +00:00
|
|
|
*/
|
|
|
|
justReleased: function (pointer, delay) {
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
pointer = pointer || 0;
|
|
|
|
delay = delay || 500;
|
2013-09-08 12:23:21 +00:00
|
|
|
|
2014-11-08 20:01:10 +00:00
|
|
|
return (this._pointerData[pointer].isUp && (this.game.time.time - this._pointerData[pointer].timeUp < delay));
|
2013-09-08 12:23:21 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2013-09-08 12:23:21 +00:00
|
|
|
* If the pointer is currently over this Sprite this returns how long it has been there for in milliseconds.
|
2013-10-02 14:05:55 +00:00
|
|
|
* @method Phaser.InputHandler#overDuration
|
2013-11-25 03:13:04 +00:00
|
|
|
* @param {Phaser.Pointer} pointer
|
2013-10-01 12:54:29 +00:00
|
|
|
* @return {number} The number of milliseconds the pointer has been over the Sprite, or -1 if not over.
|
2013-09-08 12:23:21 +00:00
|
|
|
*/
|
|
|
|
overDuration: function (pointer) {
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
pointer = pointer || 0;
|
2013-09-08 12:23:21 +00:00
|
|
|
|
|
|
|
if (this._pointerData[pointer].isOver)
|
|
|
|
{
|
2014-11-08 20:01:10 +00:00
|
|
|
return this.game.time.time - this._pointerData[pointer].timeOver;
|
2013-09-08 12:23:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2013-09-08 12:23:21 +00:00
|
|
|
* If the pointer is currently over this Sprite this returns how long it has been there for in milliseconds.
|
2013-10-02 14:05:55 +00:00
|
|
|
* @method Phaser.InputHandler#downDuration
|
2013-11-25 03:13:04 +00:00
|
|
|
* @param {Phaser.Pointer} pointer
|
2013-10-01 12:54:29 +00:00
|
|
|
* @return {number} The number of milliseconds the pointer has been pressed down on the Sprite, or -1 if not over.
|
2013-09-08 12:23:21 +00:00
|
|
|
*/
|
|
|
|
downDuration: function (pointer) {
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
pointer = pointer || 0;
|
2013-09-08 12:23:21 +00:00
|
|
|
|
|
|
|
if (this._pointerData[pointer].isDown)
|
|
|
|
{
|
2014-11-08 20:01:10 +00:00
|
|
|
return this.game.time.time - this._pointerData[pointer].timeDown;
|
2013-09-08 12:23:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2015-06-04 19:58:00 +00:00
|
|
|
* Allow this Sprite to be dragged by any valid pointer.
|
|
|
|
*
|
|
|
|
* When the drag begins the Sprite.events.onDragStart event will be dispatched.
|
|
|
|
*
|
|
|
|
* When the drag completes by way of the user letting go of the pointer that was dragging the sprite, the Sprite.events.onDragStop event is dispatched.
|
|
|
|
*
|
|
|
|
* For the duration of the drag the Sprite.events.onDragUpdate event is dispatched. This event is only dispatched when the pointer actually
|
|
|
|
* changes position and moves. The event sends 5 parameters: `sprite`, `pointer`, `dragX`, `dragY` and `snapPoint`.
|
|
|
|
*
|
2013-10-02 14:05:55 +00:00
|
|
|
* @method Phaser.InputHandler#enableDrag
|
2013-11-25 03:13:04 +00:00
|
|
|
* @param {boolean} [lockCenter=false] - 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 {boolean} [bringToTop=false] - If true the Sprite will be bought to the top of the rendering list in its current Group.
|
|
|
|
* @param {boolean} [pixelPerfect=false] - If true it will use a pixel perfect test to see if you clicked the Sprite. False uses the bounding box.
|
|
|
|
* @param {boolean} [alphaThreshold=255] - If using pixel perfect collision this specifies the alpha level from 0 to 255 above which a collision is processed.
|
|
|
|
* @param {Phaser.Rectangle} [boundsRect=null] - If you want to restrict the drag of this sprite to a specific Rectangle, pass the Phaser.Rectangle here, otherwise it's free to drag anywhere.
|
|
|
|
* @param {Phaser.Sprite} [boundsSprite=null] - If you want to restrict the drag of this sprite to within the bounding box of another sprite, pass it here.
|
2013-09-08 12:23:21 +00:00
|
|
|
*/
|
|
|
|
enableDrag: function (lockCenter, bringToTop, pixelPerfect, alphaThreshold, boundsRect, boundsSprite) {
|
|
|
|
|
2014-10-11 03:52:06 +00:00
|
|
|
if (typeof lockCenter === 'undefined') { lockCenter = false; }
|
|
|
|
if (typeof bringToTop === 'undefined') { bringToTop = false; }
|
|
|
|
if (typeof pixelPerfect === 'undefined') { pixelPerfect = false; }
|
|
|
|
if (typeof alphaThreshold === 'undefined') { alphaThreshold = 255; }
|
|
|
|
if (typeof boundsRect === 'undefined') { boundsRect = null; }
|
|
|
|
if (typeof boundsSprite === 'undefined') { boundsSprite = null; }
|
2013-09-08 12:23:21 +00:00
|
|
|
|
|
|
|
this._dragPoint = new Phaser.Point();
|
|
|
|
this.draggable = true;
|
|
|
|
this.bringToTop = bringToTop;
|
|
|
|
this.dragOffset = new Phaser.Point();
|
|
|
|
this.dragFromCenter = lockCenter;
|
2013-09-11 15:25:46 +00:00
|
|
|
|
2014-07-11 07:58:38 +00:00
|
|
|
this.pixelPerfectClick = pixelPerfect;
|
2013-09-11 15:25:46 +00:00
|
|
|
this.pixelPerfectAlpha = alphaThreshold;
|
2013-09-21 12:07:06 +00:00
|
|
|
|
2013-09-08 12:23:21 +00:00
|
|
|
if (boundsRect)
|
|
|
|
{
|
|
|
|
this.boundsRect = boundsRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (boundsSprite)
|
|
|
|
{
|
|
|
|
this.boundsSprite = boundsSprite;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2013-09-08 12:23:21 +00:00
|
|
|
* 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.
|
2013-10-02 14:05:55 +00:00
|
|
|
* @method Phaser.InputHandler#disableDrag
|
2013-09-08 12:23:21 +00:00
|
|
|
*/
|
|
|
|
disableDrag: function () {
|
|
|
|
|
|
|
|
if (this._pointerData)
|
|
|
|
{
|
|
|
|
for (var i = 0; i < 10; i++)
|
|
|
|
{
|
|
|
|
this._pointerData[i].isDragged = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.draggable = false;
|
|
|
|
this.isDragged = false;
|
|
|
|
this._draggedPointerID = -1;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2013-09-08 12:23:21 +00:00
|
|
|
* Called by Pointer when drag starts on this Sprite. Should not usually be called directly.
|
2013-10-02 14:05:55 +00:00
|
|
|
* @method Phaser.InputHandler#startDrag
|
2013-11-25 03:13:04 +00:00
|
|
|
* @param {Phaser.Pointer} pointer
|
2013-09-08 12:23:21 +00:00
|
|
|
*/
|
|
|
|
startDrag: function (pointer) {
|
|
|
|
|
2015-02-03 21:11:30 +00:00
|
|
|
var x = this.sprite.x;
|
|
|
|
var y = this.sprite.y;
|
|
|
|
|
2013-09-08 12:23:21 +00:00
|
|
|
this.isDragged = true;
|
|
|
|
this._draggedPointerID = pointer.id;
|
|
|
|
this._pointerData[pointer.id].isDragged = true;
|
|
|
|
|
2013-12-22 03:46:08 +00:00
|
|
|
if (this.sprite.fixedToCamera)
|
2013-09-08 12:23:21 +00:00
|
|
|
{
|
2013-12-22 03:46:08 +00:00
|
|
|
if (this.dragFromCenter)
|
|
|
|
{
|
|
|
|
this.sprite.centerOn(pointer.x, pointer.y);
|
|
|
|
this._dragPoint.setTo(this.sprite.cameraOffset.x - pointer.x, this.sprite.cameraOffset.y - pointer.y);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this._dragPoint.setTo(this.sprite.cameraOffset.x - pointer.x, this.sprite.cameraOffset.y - pointer.y);
|
|
|
|
}
|
2013-09-08 12:23:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-22 03:46:08 +00:00
|
|
|
if (this.dragFromCenter)
|
|
|
|
{
|
2014-03-19 05:21:26 +00:00
|
|
|
var bounds = this.sprite.getBounds();
|
2014-09-29 11:26:20 +00:00
|
|
|
|
2014-09-25 16:01:27 +00:00
|
|
|
this.sprite.x = this.globalToLocalX(pointer.x) + (this.sprite.x - bounds.centerX);
|
|
|
|
this.sprite.y = this.globalToLocalY(pointer.y) + (this.sprite.y - bounds.centerY);
|
2013-12-22 03:46:08 +00:00
|
|
|
}
|
2014-10-11 03:52:06 +00:00
|
|
|
|
2014-09-29 11:26:20 +00:00
|
|
|
this._dragPoint.setTo(this.sprite.x - this.globalToLocalX(pointer.x), this.sprite.y - this.globalToLocalY(pointer.y));
|
2013-09-08 12:23:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.updateDrag(pointer);
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2013-09-08 12:23:21 +00:00
|
|
|
if (this.bringToTop)
|
|
|
|
{
|
2014-05-14 01:42:44 +00:00
|
|
|
this._dragPhase = true;
|
2013-09-08 12:23:21 +00:00
|
|
|
this.sprite.bringToTop();
|
|
|
|
}
|
|
|
|
|
2015-03-19 00:51:01 +00:00
|
|
|
this.dragStartPoint.set(x, y);
|
2015-02-03 21:11:30 +00:00
|
|
|
this.sprite.events.onDragStart$dispatch(this.sprite, pointer, x, y);
|
2013-09-08 12:23:21 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-09-25 16:01:27 +00:00
|
|
|
/**
|
|
|
|
* Warning: EXPERIMENTAL
|
|
|
|
* @method Phaser.InputHandler#globalToLocalX
|
|
|
|
* @param {number} x
|
|
|
|
*/
|
|
|
|
globalToLocalX: function (x) {
|
|
|
|
|
|
|
|
if (this.scaleLayer)
|
|
|
|
{
|
|
|
|
x -= this.game.scale.grid.boundsFluid.x;
|
|
|
|
x *= this.game.scale.grid.scaleFluidInversed.x;
|
|
|
|
}
|
|
|
|
|
|
|
|
return x;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Warning: EXPERIMENTAL
|
|
|
|
* @method Phaser.InputHandler#globalToLocalY
|
|
|
|
* @param {number} y
|
|
|
|
*/
|
|
|
|
globalToLocalY: function (y) {
|
|
|
|
|
|
|
|
if (this.scaleLayer)
|
|
|
|
{
|
|
|
|
y -= this.game.scale.grid.boundsFluid.y;
|
|
|
|
y *= this.game.scale.grid.scaleFluidInversed.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
return y;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2013-09-08 12:23:21 +00:00
|
|
|
* Called by Pointer when drag is stopped on this Sprite. Should not usually be called directly.
|
2013-10-02 14:05:55 +00:00
|
|
|
* @method Phaser.InputHandler#stopDrag
|
2013-11-25 03:13:04 +00:00
|
|
|
* @param {Phaser.Pointer} pointer
|
2013-09-08 12:23:21 +00:00
|
|
|
*/
|
|
|
|
stopDrag: function (pointer) {
|
|
|
|
|
|
|
|
this.isDragged = false;
|
|
|
|
this._draggedPointerID = -1;
|
|
|
|
this._pointerData[pointer.id].isDragged = false;
|
2014-05-14 01:42:44 +00:00
|
|
|
this._dragPhase = false;
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2013-09-08 12:23:21 +00:00
|
|
|
if (this.snapOnRelease)
|
|
|
|
{
|
2013-12-22 03:46:08 +00:00
|
|
|
if (this.sprite.fixedToCamera)
|
|
|
|
{
|
2013-12-31 17:03:09 +00:00
|
|
|
this.sprite.cameraOffset.x = Math.round((this.sprite.cameraOffset.x - (this.snapOffsetX % this.snapX)) / this.snapX) * this.snapX + (this.snapOffsetX % this.snapX);
|
|
|
|
this.sprite.cameraOffset.y = Math.round((this.sprite.cameraOffset.y - (this.snapOffsetY % this.snapY)) / this.snapY) * this.snapY + (this.snapOffsetY % this.snapY);
|
2013-12-22 03:46:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-31 17:03:09 +00:00
|
|
|
this.sprite.x = Math.round((this.sprite.x - (this.snapOffsetX % this.snapX)) / this.snapX) * this.snapX + (this.snapOffsetX % this.snapX);
|
|
|
|
this.sprite.y = Math.round((this.sprite.y - (this.snapOffsetY % this.snapY)) / this.snapY) * this.snapY + (this.snapOffsetY % this.snapY);
|
2013-12-22 03:46:08 +00:00
|
|
|
}
|
2013-09-08 12:23:21 +00:00
|
|
|
}
|
|
|
|
|
2014-12-01 03:49:15 +00:00
|
|
|
this.sprite.events.onDragStop$dispatch(this.sprite, pointer);
|
2013-09-08 12:23:21 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
if (this.checkPointerOver(pointer) === false)
|
2013-10-31 16:27:10 +00:00
|
|
|
{
|
|
|
|
this._pointerOutHandler(pointer);
|
|
|
|
}
|
|
|
|
|
2013-09-08 12:23:21 +00:00
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2013-09-08 12:23:21 +00:00
|
|
|
* Restricts this sprite to drag movement only on the given axis. Note: If both are set to false the sprite will never move!
|
2013-10-02 14:05:55 +00:00
|
|
|
* @method Phaser.InputHandler#setDragLock
|
2013-11-25 03:13:04 +00:00
|
|
|
* @param {boolean} [allowHorizontal=true] - To enable the sprite to be dragged horizontally set to true, otherwise false.
|
|
|
|
* @param {boolean} [allowVertical=true] - To enable the sprite to be dragged vertically set to true, otherwise false.
|
2013-09-08 12:23:21 +00:00
|
|
|
*/
|
|
|
|
setDragLock: function (allowHorizontal, allowVertical) {
|
|
|
|
|
2014-10-11 03:52:06 +00:00
|
|
|
if (typeof allowHorizontal === 'undefined') { allowHorizontal = true; }
|
|
|
|
if (typeof allowVertical === 'undefined') { allowVertical = true; }
|
2013-09-08 12:23:21 +00:00
|
|
|
|
|
|
|
this.allowHorizontalDrag = allowHorizontal;
|
|
|
|
this.allowVerticalDrag = allowVertical;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2013-09-08 12:23:21 +00:00
|
|
|
* 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.
|
2013-10-02 14:05:55 +00:00
|
|
|
* @method Phaser.InputHandler#enableSnap
|
2013-11-25 03:13:04 +00:00
|
|
|
* @param {number} snapX - The width of the grid cell to snap to.
|
|
|
|
* @param {number} snapY - The height of the grid cell to snap to.
|
|
|
|
* @param {boolean} [onDrag=true] - If true the sprite will snap to the grid while being dragged.
|
|
|
|
* @param {boolean} [onRelease=false] - If true the sprite will snap to the grid when released.
|
2013-12-31 17:03:09 +00:00
|
|
|
* @param {number} [snapOffsetX=0] - Used to offset the top-left starting point of the snap grid.
|
2015-03-27 10:47:25 +00:00
|
|
|
* @param {number} [snapOffsetY=0] - Used to offset the top-left starting point of the snap grid.
|
2013-09-08 12:23:21 +00:00
|
|
|
*/
|
2014-03-06 16:45:29 +00:00
|
|
|
enableSnap: function (snapX, snapY, onDrag, onRelease, snapOffsetX, snapOffsetY) {
|
2013-09-08 12:23:21 +00:00
|
|
|
|
2014-10-11 03:52:06 +00:00
|
|
|
if (typeof onDrag === 'undefined') { onDrag = true; }
|
|
|
|
if (typeof onRelease === 'undefined') { onRelease = false; }
|
|
|
|
if (typeof snapOffsetX === 'undefined') { snapOffsetX = 0; }
|
|
|
|
if (typeof snapOffsetY === 'undefined') { snapOffsetY = 0; }
|
2013-09-08 12:23:21 +00:00
|
|
|
|
|
|
|
this.snapX = snapX;
|
|
|
|
this.snapY = snapY;
|
2013-12-31 17:03:09 +00:00
|
|
|
this.snapOffsetX = snapOffsetX;
|
|
|
|
this.snapOffsetY = snapOffsetY;
|
2013-09-13 03:37:06 +00:00
|
|
|
this.snapOnDrag = onDrag;
|
|
|
|
this.snapOnRelease = onRelease;
|
2013-09-08 12:23:21 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2013-09-08 12:23:21 +00:00
|
|
|
* Stops the sprite from snapping to a grid during drag or release.
|
2013-10-02 14:05:55 +00:00
|
|
|
* @method Phaser.InputHandler#disableSnap
|
2013-09-08 12:23:21 +00:00
|
|
|
*/
|
|
|
|
disableSnap: function () {
|
|
|
|
|
|
|
|
this.snapOnDrag = false;
|
|
|
|
this.snapOnRelease = false;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2015-02-16 15:49:46 +00:00
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2013-09-08 12:23:21 +00:00
|
|
|
* Bounds Rect check for the sprite drag
|
2013-10-02 14:05:55 +00:00
|
|
|
* @method Phaser.InputHandler#checkBoundsRect
|
2013-09-08 12:23:21 +00:00
|
|
|
*/
|
|
|
|
checkBoundsRect: function () {
|
|
|
|
|
2013-12-31 17:03:09 +00:00
|
|
|
if (this.sprite.fixedToCamera)
|
2013-09-08 12:23:21 +00:00
|
|
|
{
|
2013-12-31 17:03:09 +00:00
|
|
|
if (this.sprite.cameraOffset.x < this.boundsRect.left)
|
|
|
|
{
|
2014-08-28 00:29:23 +00:00
|
|
|
this.sprite.cameraOffset.x = this.boundsRect.left;
|
2013-12-31 17:03:09 +00:00
|
|
|
}
|
|
|
|
else if ((this.sprite.cameraOffset.x + this.sprite.width) > this.boundsRect.right)
|
|
|
|
{
|
|
|
|
this.sprite.cameraOffset.x = this.boundsRect.right - this.sprite.width;
|
|
|
|
}
|
2013-09-08 12:23:21 +00:00
|
|
|
|
2013-12-31 17:03:09 +00:00
|
|
|
if (this.sprite.cameraOffset.y < this.boundsRect.top)
|
|
|
|
{
|
|
|
|
this.sprite.cameraOffset.y = this.boundsRect.top;
|
|
|
|
}
|
|
|
|
else if ((this.sprite.cameraOffset.y + this.sprite.height) > this.boundsRect.bottom)
|
|
|
|
{
|
|
|
|
this.sprite.cameraOffset.y = this.boundsRect.bottom - this.sprite.height;
|
|
|
|
}
|
2013-09-08 12:23:21 +00:00
|
|
|
}
|
2013-12-31 17:03:09 +00:00
|
|
|
else
|
2013-09-08 12:23:21 +00:00
|
|
|
{
|
2015-02-16 15:49:46 +00:00
|
|
|
if (this.sprite.left < this.boundsRect.left)
|
2013-12-31 17:03:09 +00:00
|
|
|
{
|
2015-02-16 15:49:46 +00:00
|
|
|
this.sprite.x = this.boundsRect.x + this.sprite.offsetX;
|
2013-12-31 17:03:09 +00:00
|
|
|
}
|
2015-02-16 15:49:46 +00:00
|
|
|
else if (this.sprite.right > this.boundsRect.right)
|
2013-12-31 17:03:09 +00:00
|
|
|
{
|
2015-02-16 15:49:46 +00:00
|
|
|
this.sprite.x = this.boundsRect.right - (this.sprite.width - this.sprite.offsetX);
|
2013-12-31 17:03:09 +00:00
|
|
|
}
|
|
|
|
|
2015-02-16 15:49:46 +00:00
|
|
|
if (this.sprite.top < this.boundsRect.top)
|
2013-12-31 17:03:09 +00:00
|
|
|
{
|
2015-02-16 15:49:46 +00:00
|
|
|
this.sprite.y = this.boundsRect.top + this.sprite.offsetY;
|
2013-12-31 17:03:09 +00:00
|
|
|
}
|
2015-02-16 15:49:46 +00:00
|
|
|
else if (this.sprite.bottom > this.boundsRect.bottom)
|
2013-12-31 17:03:09 +00:00
|
|
|
{
|
2015-02-16 15:49:46 +00:00
|
|
|
this.sprite.y = this.boundsRect.bottom - (this.sprite.height - this.sprite.offsetY);
|
2013-12-31 17:03:09 +00:00
|
|
|
}
|
2013-09-08 12:23:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-25 03:13:04 +00:00
|
|
|
/**
|
2013-10-01 12:54:29 +00:00
|
|
|
* Parent Sprite Bounds check for the sprite drag.
|
2013-10-02 14:05:55 +00:00
|
|
|
* @method Phaser.InputHandler#checkBoundsSprite
|
2013-09-08 12:23:21 +00:00
|
|
|
*/
|
|
|
|
checkBoundsSprite: function () {
|
|
|
|
|
2013-12-31 17:03:09 +00:00
|
|
|
if (this.sprite.fixedToCamera && this.boundsSprite.fixedToCamera)
|
2013-09-08 12:23:21 +00:00
|
|
|
{
|
2015-02-14 19:10:06 +00:00
|
|
|
if (this.sprite.cameraOffset.x < this.boundsSprite.cameraOffset.x)
|
2013-12-31 17:03:09 +00:00
|
|
|
{
|
2015-02-14 19:10:06 +00:00
|
|
|
this.sprite.cameraOffset.x = this.boundsSprite.cameraOffset.x;
|
2013-12-31 17:03:09 +00:00
|
|
|
}
|
2015-02-14 19:10:06 +00:00
|
|
|
else if ((this.sprite.cameraOffset.x + this.sprite.width) > (this.boundsSprite.cameraOffset.x + this.boundsSprite.width))
|
2013-12-31 17:03:09 +00:00
|
|
|
{
|
2015-02-14 19:10:06 +00:00
|
|
|
this.sprite.cameraOffset.x = (this.boundsSprite.cameraOffset.x + this.boundsSprite.width) - this.sprite.width;
|
2013-12-31 17:03:09 +00:00
|
|
|
}
|
2013-09-08 12:23:21 +00:00
|
|
|
|
2015-02-14 19:10:06 +00:00
|
|
|
if (this.sprite.cameraOffset.y < this.boundsSprite.cameraOffset.y)
|
2013-12-31 17:03:09 +00:00
|
|
|
{
|
2015-02-14 19:10:06 +00:00
|
|
|
this.sprite.cameraOffset.y = this.boundsSprite.cameraOffset.y;
|
2013-12-31 17:03:09 +00:00
|
|
|
}
|
2015-02-14 19:10:06 +00:00
|
|
|
else if ((this.sprite.cameraOffset.y + this.sprite.height) > (this.boundsSprite.cameraOffset.y + this.boundsSprite.height))
|
2013-12-31 17:03:09 +00:00
|
|
|
{
|
2015-02-14 19:10:06 +00:00
|
|
|
this.sprite.cameraOffset.y = (this.boundsSprite.cameraOffset.y + this.boundsSprite.height) - this.sprite.height;
|
2013-12-31 17:03:09 +00:00
|
|
|
}
|
2013-09-08 12:23:21 +00:00
|
|
|
}
|
2013-12-31 17:03:09 +00:00
|
|
|
else
|
2013-09-08 12:23:21 +00:00
|
|
|
{
|
2015-02-16 15:49:46 +00:00
|
|
|
if (this.sprite.left < this.boundsSprite.left)
|
2013-12-31 17:03:09 +00:00
|
|
|
{
|
2015-02-16 15:49:46 +00:00
|
|
|
this.sprite.x = this.boundsSprite.left + this.sprite.offsetX;
|
2013-12-31 17:03:09 +00:00
|
|
|
}
|
2015-02-16 15:49:46 +00:00
|
|
|
else if (this.sprite.right > this.boundsSprite.right)
|
2013-12-31 17:03:09 +00:00
|
|
|
{
|
2015-02-16 15:49:46 +00:00
|
|
|
this.sprite.x = this.boundsSprite.right - (this.sprite.width - this.sprite.offsetX);
|
2013-12-31 17:03:09 +00:00
|
|
|
}
|
|
|
|
|
2015-02-16 15:49:46 +00:00
|
|
|
if (this.sprite.top < this.boundsSprite.top)
|
2013-12-31 17:03:09 +00:00
|
|
|
{
|
2015-02-16 15:49:46 +00:00
|
|
|
this.sprite.y = this.boundsSprite.top + this.sprite.offsetY;
|
2013-12-31 17:03:09 +00:00
|
|
|
}
|
2015-02-16 15:49:46 +00:00
|
|
|
else if (this.sprite.bottom > this.boundsSprite.bottom)
|
2013-12-31 17:03:09 +00:00
|
|
|
{
|
2015-02-16 15:49:46 +00:00
|
|
|
this.sprite.y = this.boundsSprite.bottom - (this.sprite.height - this.sprite.offsetY);
|
2013-12-31 17:03:09 +00:00
|
|
|
}
|
2015-02-16 15:49:46 +00:00
|
|
|
|
|
|
|
// if (this.sprite.x < this.boundsSprite.x)
|
|
|
|
// {
|
|
|
|
// this.sprite.x = this.boundsSprite.x;
|
|
|
|
// }
|
|
|
|
// else if ((this.sprite.x + this.sprite.width) > (this.boundsSprite.x + this.boundsSprite.width))
|
|
|
|
// {
|
|
|
|
// this.sprite.x = (this.boundsSprite.x + this.boundsSprite.width) - this.sprite.width;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (this.sprite.y < this.boundsSprite.y)
|
|
|
|
// {
|
|
|
|
// this.sprite.y = this.boundsSprite.y;
|
|
|
|
// }
|
|
|
|
// else if ((this.sprite.y + this.sprite.height) > (this.boundsSprite.y + this.boundsSprite.height))
|
|
|
|
// {
|
|
|
|
// this.sprite.y = (this.boundsSprite.y + this.boundsSprite.height) - this.sprite.height;
|
|
|
|
// }
|
2013-09-08 12:23:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-12-30 16:54:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Phaser.InputHandler.prototype.constructor = Phaser.InputHandler;
|