Merge pull request #2047 from Garbanas/feature/p2-remove-collision-group

Convenience function to remove a collision group from a P2 Body
This commit is contained in:
Richard Davey 2015-08-31 13:12:13 +03:00
commit adcc5d3afb
3 changed files with 74 additions and 0 deletions

View file

@ -368,6 +368,70 @@ Phaser.Physics.P2.Body.prototype = {
},
/**
* Removes the given CollisionGroup, or array of CollisionGroups, from the list of groups that this body will collide with and updates the collision masks.
*
* @method Phaser.Physics.P2.Body#removeCollisionGroup
* @param {Phaser.Physics.CollisionGroup|array} group - The Collision Group or Array of Collision Groups that this Bodies shapes should not collide with anymore.
* @param {boolean} [clearCallback=true] - Clear the callback that will be triggered when this Body impacts with the given Group?
* @param {p2.Shape} [shape] - An optional Shape. If not provided the updated collision mask will be added to all Shapes in this Body.
*/
removeCollisionGroup: function (group, clearCallback, shape) {
if (clearCallback === undefined) { clearCallback = true; }
var index;
if (Array.isArray(group))
{
for (var i = 0; i < group.length; i++)
{
index = this.collidesWith.indexOf(group[i]);
if (index > -1)
{
this.collidesWith.splice(index, 1);
if (clearCallback)
{
delete (this._groupCallbacks[group.mask]);
delete (this._groupCallbackContext[group.mask]);
}
}
}
}
else
{
index = this.collidesWith.indexOf(group);
if (index > -1)
{
this.collidesWith.splice(index, 1);
if (clearCallback)
{
delete (this._groupCallbacks[group.mask]);
delete (this._groupCallbackContext[group.mask]);
}
}
}
var mask = this.getCollisionMask();
if (shape === undefined)
{
for (var i = this.data.shapes.length - 1; i >= 0; i--)
{
this.data.shapes[i].collisionMask = mask;
}
}
else
{
shape.collisionMask = mask;
}
},
/**
* Adds the given CollisionGroup, or array of CollisionGroups, to the list of groups that this body will collide with and updates the collision masks.
*

View file

@ -17974,6 +17974,15 @@ declare module Phaser {
*/
postUpdate(): void;
/**
* Removes the given CollisionGroup, or array of CollisionGroups, from the list of groups that this body will collide with and updates the collision masks.
*
* @param group The Collision Group or Array of Collision Groups that this Bodies shapes should not collide with anymore.
* @param clearCallback Clear the callback that will be triggered when this Body impacts with the given Group? - Default: true
* @param shape An optional Shape. If not provided the updated collision mask will be added to all Shapes in this Body.
*/
removeCollisionGroup(group: any, clearCallback?: boolean, shape?: p2.Shape): void;
/**
* Removes this physics body from the world.
*/

View file

@ -3188,6 +3188,7 @@ declare module Phaser {
moveUp(speed: number): void;
preUpdate(): void;
postUpdate(): void;
removeCollisionGroup(group: any, clearCallback?: boolean, shape?: p2.Shape): void;
removeFromWorld(): void;
removeShape(shape: p2.Shape): boolean;
reverse(speed: number): void;