Skip to content

Commit cc1b96a

Browse files
committed
The Body.setCollideWorldBounds method has two new optional arguments bounceX and bounceY which, if given, will set the World Bounce values for the body.
1 parent 2b4568c commit cc1b96a

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Notes:
1616
* `collideTiles` is a new method that allows you to check for collision between a physics enabled Game Object and an array of Tiles. The Tiles don't have to have been enable for collision, or even be on the same layer, for the collision to work. You can provide your own process callback and/or overlap callback. There are some limitations in using this method, please consult the API Docs for details, but on the whole, it allows for dynamic collision on small sets of Tile instances. This is available via `this.physics.collideTiles` and the World instance.
1717
* `overlapRect` is a new method that allows you to return an array of all physics bodies within the given rectangular region of the World. It can return dynamic or static bodies and will use the RTree for super-fast searching, if enabled (which it is by default)
1818
* `debugShowBlocked`, `sleepDebugColor`, `blockedDebugColor`
19+
* The `Body.setCollideWorldBounds` method has two new optional arguments `bounceX` and `bounceY` which, if given, will set the World Bounce values for the body.
1920

2021
#### Updates
2122

src/physics/arcade/Body.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1629,20 +1629,45 @@ var Body = new Class({
16291629

16301630
/**
16311631
* Sets whether this Body collides with the world boundary.
1632+
*
1633+
* Optionally also sets the World Bounce values. If the `Body.worldBounce` is null, it's set to a new Vec2 first.
16321634
*
16331635
* @method Phaser.Physics.Arcade.Body#setCollideWorldBounds
16341636
* @since 3.0.0
16351637
*
16361638
* @param {boolean} [value=true] - True (collisions) or false (no collisions).
1639+
* @param {number} [bounceX] - If given this will be replace the `worldBounce.x` value.
1640+
* @param {number} [bounceY] - If given this will be replace the `worldBounce.y` value.
16371641
*
16381642
* @return {Phaser.Physics.Arcade.Body} This Body object.
16391643
*/
1640-
setCollideWorldBounds: function (value)
1644+
setCollideWorldBounds: function (value, bounceX, bounceY)
16411645
{
16421646
if (value === undefined) { value = true; }
16431647

16441648
this.collideWorldBounds = value;
16451649

1650+
var setBounceX = (bounceX !== undefined);
1651+
var setBounceY = (bounceY !== undefined);
1652+
1653+
if (setBounceX || setBounceY)
1654+
{
1655+
if (!this.worldBounce)
1656+
{
1657+
this.worldBounce = new Vector2();
1658+
}
1659+
1660+
if (setBounceX)
1661+
{
1662+
this.worldBounce.x = bounceX;
1663+
}
1664+
1665+
if (setBounceY)
1666+
{
1667+
this.worldBounce.y = bounceY;
1668+
}
1669+
}
1670+
16461671
return this;
16471672
},
16481673

0 commit comments

Comments
 (0)