mirror of
https://github.com/photonstorm/phaser
synced 2024-11-24 05:33:35 +00:00
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:
commit
adcc5d3afb
3 changed files with 74 additions and 0 deletions
|
@ -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.
|
||||
*
|
||||
|
|
9
typescript/phaser.comments.d.ts
vendored
9
typescript/phaser.comments.d.ts
vendored
|
@ -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.
|
||||
*/
|
||||
|
|
1
typescript/phaser.d.ts
vendored
1
typescript/phaser.d.ts
vendored
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue