2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
|
|
|
* @copyright 2018 Photon Storm Ltd.
|
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2018-03-19 21:12:11 +00:00
|
|
|
/**
|
|
|
|
* @callback HitAreaCallback
|
|
|
|
*
|
2018-06-04 16:11:53 +00:00
|
|
|
* @param {any} hitArea - The hit area object.
|
|
|
|
* @param {number} x - The translated x coordinate of the hit test event.
|
|
|
|
* @param {number} y - The translated y coordinate of the hit test event.
|
|
|
|
* @param {Phaser.GameObjects.GameObject} gameObject - The Game Object that invoked the hit test.
|
2018-03-19 21:27:16 +00:00
|
|
|
*
|
2018-06-04 16:11:53 +00:00
|
|
|
* @return {boolean} `true` if the coordinates fall within the space of the hitArea, otherwise `false`.
|
2018-03-19 21:12:11 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2018-03-28 14:03:54 +00:00
|
|
|
* @typedef {object} Phaser.Input.InteractiveObject
|
2018-03-19 21:12:11 +00:00
|
|
|
*
|
2018-06-04 16:11:53 +00:00
|
|
|
* @property {Phaser.GameObjects.GameObject} gameObject - The Game Object to which this Interactive Object is bound.
|
|
|
|
* @property {boolean} enabled - Is this Interactive Object currently enabled for input events?
|
|
|
|
* @property {boolean} draggable - Is this Interactive Object draggable? Enable with `InputPlugin.setDraggable`.
|
|
|
|
* @property {boolean} dropZone - Is this Interactive Object a drag-targets drop zone? Set when the object is created.
|
2018-06-06 22:03:44 +00:00
|
|
|
* @property {?Phaser.GameObjects.GameObject} target - An optional drop target for a draggable Interactive Object.
|
2018-06-04 16:11:53 +00:00
|
|
|
* @property {Phaser.Cameras.Scene2D.Camera} camera - The most recent Camera to be tested against this Interactive Object.
|
|
|
|
* @property {any} hitArea - The hit area for this Interactive Object. Typically a geometry shape, like a Rectangle or Circle.
|
|
|
|
* @property {HitAreaCallback} hitAreaCallback - The 'contains' check callback that the hit area shape will use for all hit tests.
|
|
|
|
* @property {number} localX - The x coordinate that the Pointer interacted with this object on, relative to the Game Object's top-left position.
|
|
|
|
* @property {number} localY - The y coordinate that the Pointer interacted with this object on, relative to the Game Object's top-left position.
|
|
|
|
* @property {(0|1|2)} dragState - The current drag state of this Interactive Object. 0 = Not being dragged, 1 = being checked for drag, or 2 = being actively dragged.
|
|
|
|
* @property {number} dragStartX - The x coordinate that the Pointer started dragging this Interactive Object from.
|
|
|
|
* @property {number} dragStartY - The y coordinate that the Pointer started dragging this Interactive Object from.
|
|
|
|
* @property {number} dragX - The x coordinate that this Interactive Object is currently being dragged to.
|
|
|
|
* @property {number} dragY - The y coordinate that this Interactive Object is currently being dragged to.
|
2018-03-19 21:12:11 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2018-06-04 16:11:53 +00:00
|
|
|
* Creates a new Interactive Object.
|
|
|
|
*
|
|
|
|
* This is called automatically by the Input Manager when you enable a Game Object for input.
|
|
|
|
*
|
|
|
|
* The resulting Interactive Object is mapped to the Game Object's `input` property.
|
2018-03-19 21:12:11 +00:00
|
|
|
*
|
2018-03-28 14:03:54 +00:00
|
|
|
* @function Phaser.Input.CreateInteractiveObject
|
2018-03-19 21:12:11 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-04 16:11:53 +00:00
|
|
|
* @param {Phaser.GameObjects.GameObject} gameObject - The Game Object to which this Interactive Object is bound.
|
|
|
|
* @param {any} hitArea - The hit area for this Interactive Object. Typically a geometry shape, like a Rectangle or Circle.
|
|
|
|
* @param {HitAreaCallback} hitAreaCallback - The 'contains' check callback that the hit area shape will use for all hit tests.
|
2018-03-19 21:12:11 +00:00
|
|
|
*
|
2018-06-04 16:11:53 +00:00
|
|
|
* @return {Phaser.Input.InteractiveObject} The new Interactive Object.
|
2018-03-19 21:12:11 +00:00
|
|
|
*/
|
2018-03-28 14:03:54 +00:00
|
|
|
var CreateInteractiveObject = function (gameObject, hitArea, hitAreaCallback)
|
2017-07-27 13:22:44 +00:00
|
|
|
{
|
|
|
|
return {
|
2017-07-25 03:10:50 +00:00
|
|
|
|
2017-07-27 13:22:44 +00:00
|
|
|
gameObject: gameObject,
|
2017-07-25 03:10:50 +00:00
|
|
|
|
2017-07-27 13:22:44 +00:00
|
|
|
enabled: true,
|
|
|
|
draggable: false,
|
2017-07-27 17:24:04 +00:00
|
|
|
dropZone: false,
|
2017-07-25 03:10:50 +00:00
|
|
|
|
2017-07-27 23:29:04 +00:00
|
|
|
target: null,
|
|
|
|
|
2017-07-28 17:22:57 +00:00
|
|
|
camera: null,
|
|
|
|
|
2017-07-27 13:22:44 +00:00
|
|
|
hitArea: hitArea,
|
|
|
|
hitAreaCallback: hitAreaCallback,
|
2017-07-25 03:10:50 +00:00
|
|
|
|
2017-07-27 13:22:44 +00:00
|
|
|
localX: 0,
|
|
|
|
localY: 0,
|
2017-07-25 03:10:50 +00:00
|
|
|
|
2017-07-27 02:40:58 +00:00
|
|
|
// 0 = Not being dragged
|
|
|
|
// 1 = Being checked for dragging
|
|
|
|
// 2 = Being dragged
|
2017-07-27 13:22:44 +00:00
|
|
|
dragState: 0,
|
|
|
|
|
2017-07-27 23:46:37 +00:00
|
|
|
dragStartX: 0,
|
|
|
|
dragStartY: 0,
|
|
|
|
|
2017-07-27 13:22:44 +00:00
|
|
|
dragX: 0,
|
2018-01-12 17:07:39 +00:00
|
|
|
dragY: 0
|
2017-07-27 13:22:44 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
};
|
2017-07-18 01:36:45 +00:00
|
|
|
|
2018-03-28 14:03:54 +00:00
|
|
|
module.exports = CreateInteractiveObject;
|