phaser/src/physics/arcade/Collider.js

175 lines
4.2 KiB
JavaScript
Raw Normal View History

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}
*/
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]
* @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.
* @param {any} callbackContext - The scope in which to call the callbacks.
2018-02-09 03:44:23 +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
*/
this.world = world;
/**
* [description]
*
* @name Phaser.Physics.Arcade.Collider#name
* @type {string}
2018-02-15 14:31:15 +00:00
* @since 3.1.0
*/
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
*/
this.active = true;
2018-02-09 03:44:23 +00:00
/**
* [description]
*
* @name Phaser.Physics.Arcade.Collider#overlapOnly
* @type {boolean}
* @since 3.0.0
*/
this.overlapOnly = overlapOnly;
2018-02-09 03:44:23 +00:00
/**
* [description]
*
* @name Phaser.Physics.Arcade.Collider#object1
* @type {ArcadeColliderType}
2018-02-09 03:44:23 +00:00
* @since 3.0.0
*/
this.object1 = object1;
2018-02-09 03:44:23 +00:00
/**
* [description]
*
* @name Phaser.Physics.Arcade.Collider#object2
* @type {ArcadeColliderType}
2018-02-09 03:44:23 +00:00
* @since 3.0.0
*/
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
*/
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
*/
this.processCallback = processCallback;
2018-02-09 03:44:23 +00:00
/**
* [description]
*
* @name Phaser.Physics.Arcade.Collider#callbackContext
* @type {object}
* @since 3.0.0
*/
this.callbackContext = callbackContext;
},
/**
* [description]
*
* @method Phaser.Physics.Arcade.Collider#setName
2018-02-15 14:31:15 +00:00
* @since 3.1.0
*
* @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
*/
update: function ()
{
this.world.collideObjects(
this.object1,
this.object2,
this.collideCallback,
this.processCallback,
this.callbackContext,
this.overlapOnly
);
},
2018-02-09 03:44:23 +00:00
/**
* [description]
*
* @method Phaser.Physics.Arcade.Collider#destroy
* @since 3.0.0
*/
destroy: function ()
{
this.world.removeCollider(this);
this.active = false;
this.world = null;
this.object1 = null;
this.object2 = null;
this.collideCallback = null;
this.processCallback = null;
this.callbackContext = null;
}
});
module.exports = Collider;