mirror of
https://github.com/photonstorm/phaser
synced 2024-11-10 23:24:41 +00:00
Added helper methods for setting body collision callbacks
This commit is contained in:
parent
f64d3e59d0
commit
efcbd1e4e5
1 changed files with 91 additions and 0 deletions
|
@ -81,6 +81,97 @@ var Collision = {
|
|||
|
||||
this.body.collisionFilter.mask = flags;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* The callback is sent a `Phaser.Types.Physics.Matter.MatterCollisionData` object.
|
||||
*
|
||||
* This does not change the bodies collision category, group or filter. Those must be set in addition
|
||||
* to the callback.
|
||||
*
|
||||
* @method Phaser.Physics.Matter.Components.Collision#setOnCollide
|
||||
* @since 3.22.0
|
||||
*
|
||||
* @param {function} callback - The callback to invoke when this body starts colliding with another.
|
||||
*
|
||||
* @return {Phaser.GameObjects.GameObject} This Game Object.
|
||||
*/
|
||||
setOnCollide: function (callback)
|
||||
{
|
||||
this.body.onCollideCallback = callback;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* The callback is sent a `Phaser.Types.Physics.Matter.MatterCollisionData` object.
|
||||
*
|
||||
* This does not change the bodies collision category, group or filter. Those must be set in addition
|
||||
* to the callback.
|
||||
*
|
||||
* @method Phaser.Physics.Matter.Components.Collision#setOnCollideEnd
|
||||
* @since 3.22.0
|
||||
*
|
||||
* @param {function} callback - The callback to invoke when this body stops colliding with another.
|
||||
*
|
||||
* @return {Phaser.GameObjects.GameObject} This Game Object.
|
||||
*/
|
||||
setOnCollideEnd: function (callback)
|
||||
{
|
||||
this.body.onCollideEndCallback = callback;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* The callback is sent a `Phaser.Types.Physics.Matter.MatterCollisionData` object.
|
||||
*
|
||||
* This does not change the bodies collision category, group or filter. Those must be set in addition
|
||||
* to the callback.
|
||||
*
|
||||
* @method Phaser.Physics.Matter.Components.Collision#setOnCollideActive
|
||||
* @since 3.22.0
|
||||
*
|
||||
* @param {function} callback - The callback to invoke for the duration of this body colliding with another.
|
||||
*
|
||||
* @return {Phaser.GameObjects.GameObject} This Game Object.
|
||||
*/
|
||||
setOnCollideActive: function (callback)
|
||||
{
|
||||
this.body.onCollideActiveCallback = callback;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* The callback is sent a reference to the other body, along with a `Phaser.Types.Physics.Matter.MatterCollisionData` object.
|
||||
*
|
||||
* This does not change the bodies collision category, group or filter. Those must be set in addition
|
||||
* to the callback.
|
||||
*
|
||||
* @method Phaser.Physics.Matter.Components.Collision#setOnCollideWith
|
||||
* @since 3.22.0
|
||||
*
|
||||
* @param {(MatterJS.Body|MatterJS.Body[])} body - The body, or an array of bodies, to test for collisions with.
|
||||
* @param {function} callback - The callback to invoke when this body collides with the given body or bodies.
|
||||
*
|
||||
* @return {Phaser.GameObjects.GameObject} This Game Object.
|
||||
*/
|
||||
setOnCollideWith: function (body, callback)
|
||||
{
|
||||
if (!Array.isArray(body))
|
||||
{
|
||||
body = [ body ];
|
||||
}
|
||||
|
||||
for (var i = 0; i < body.length; i++)
|
||||
{
|
||||
var src = (body[i].hasOwnProperty('body')) ? body[i].body : body[i];
|
||||
|
||||
this.body.setOnCollideWith(src, callback);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue