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}
|
|
|
|
*/
|
|
|
|
|
2017-11-09 17:03:58 +00:00
|
|
|
var Class = require('../../utils/Class');
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
|
|
|
* @classdesc
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @class Collider
|
|
|
|
* @memberOf Phaser.Physics.Arcade
|
|
|
|
* @constructor
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {Phaser.Physics.Arcade.World} world - [description]
|
|
|
|
* @param {boolean} overlapOnly - [description]
|
2018-05-31 14:52:35 +00:00
|
|
|
* @param {ArcadeColliderType} object1 - The first object to check for collision.
|
|
|
|
* @param {ArcadeColliderType} object2 - The second object to check for collision.
|
2018-03-19 20:42:07 +00:00
|
|
|
* @param {ArcadePhysicsCallback} collideCallback - The callback to invoke when the two objects collide.
|
|
|
|
* @param {ArcadePhysicsCallback} processCallback - The callback to invoke when the two objects collide. Must return a boolean.
|
2018-05-31 14:52:35 +00:00
|
|
|
* @param {any} callbackContext - The scope in which to call the callbacks.
|
2018-02-09 03:44:23 +00:00
|
|
|
*/
|
2017-11-09 17:03:58 +00:00
|
|
|
var Collider = new Class({
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
|
|
|
function Collider (world, overlapOnly, object1, object2, collideCallback, processCallback, callbackContext)
|
|
|
|
{
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.Collider#world
|
|
|
|
* @type {Phaser.Physics.Arcade.World}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 17:03:58 +00:00
|
|
|
this.world = world;
|
|
|
|
|
2018-02-14 19:33:33 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.Collider#name
|
|
|
|
* @type {string}
|
2018-02-15 14:31:15 +00:00
|
|
|
* @since 3.1.0
|
2018-02-14 19:33:33 +00:00
|
|
|
*/
|
|
|
|
this.name = '';
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.Collider#active
|
|
|
|
* @type {boolean}
|
|
|
|
* @default true
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 17:10:33 +00:00
|
|
|
this.active = true;
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.Collider#overlapOnly
|
|
|
|
* @type {boolean}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 17:03:58 +00:00
|
|
|
this.overlapOnly = overlapOnly;
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.Collider#object1
|
2018-05-31 14:52:35 +00:00
|
|
|
* @type {ArcadeColliderType}
|
2018-02-09 03:44:23 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 17:03:58 +00:00
|
|
|
this.object1 = object1;
|
2018-02-09 03:44:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.Collider#object2
|
2018-05-31 14:52:35 +00:00
|
|
|
* @type {ArcadeColliderType}
|
2018-02-09 03:44:23 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 17:03:58 +00:00
|
|
|
this.object2 = object2;
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.Collider#collideCallback
|
2018-03-19 20:42:07 +00:00
|
|
|
* @type {ArcadePhysicsCallback}
|
2018-02-09 03:44:23 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 17:03:58 +00:00
|
|
|
this.collideCallback = collideCallback;
|
2018-02-09 03:44:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.Collider#processCallback
|
2018-03-19 20:42:07 +00:00
|
|
|
* @type {ArcadePhysicsCallback}
|
2018-02-09 03:44:23 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 17:03:58 +00:00
|
|
|
this.processCallback = processCallback;
|
2018-02-09 03:44:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.Physics.Arcade.Collider#callbackContext
|
|
|
|
* @type {object}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 17:03:58 +00:00
|
|
|
this.callbackContext = callbackContext;
|
|
|
|
},
|
|
|
|
|
2018-02-14 19:33:33 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Arcade.Collider#setName
|
2018-02-15 14:31:15 +00:00
|
|
|
* @since 3.1.0
|
2018-02-14 19:33:33 +00:00
|
|
|
*
|
|
|
|
* @param {string} name - [description]
|
|
|
|
*
|
|
|
|
* @return {Phaser.Physics.Arcade.Collider} [description]
|
|
|
|
*/
|
|
|
|
setName: function (name)
|
|
|
|
{
|
|
|
|
this.name = name;
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Arcade.Collider#update
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 17:03:58 +00:00
|
|
|
update: function ()
|
|
|
|
{
|
|
|
|
this.world.collideObjects(
|
|
|
|
this.object1,
|
|
|
|
this.object2,
|
|
|
|
this.collideCallback,
|
|
|
|
this.processCallback,
|
|
|
|
this.callbackContext,
|
|
|
|
this.overlapOnly
|
|
|
|
);
|
2017-11-09 17:10:33 +00:00
|
|
|
},
|
|
|
|
|
2018-02-09 03:44:23 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Physics.Arcade.Collider#destroy
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-11-09 17:10:33 +00:00
|
|
|
destroy: function ()
|
|
|
|
{
|
|
|
|
this.world.removeCollider(this);
|
|
|
|
|
2017-11-09 23:56:28 +00:00
|
|
|
this.active = false;
|
|
|
|
|
2017-11-09 17:10:33 +00:00
|
|
|
this.world = null;
|
|
|
|
|
|
|
|
this.object1 = null;
|
|
|
|
this.object2 = null;
|
|
|
|
|
|
|
|
this.collideCallback = null;
|
|
|
|
this.processCallback = null;
|
|
|
|
this.callbackContext = null;
|
2017-11-09 17:03:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = Collider;
|