mirror of
https://github.com/photonstorm/phaser
synced 2024-12-25 04:23:30 +00:00
Use a custom bounds rectangle for the Arcade Body to overwrite the world bounds
This commit is contained in:
parent
83f3f9cdeb
commit
7033297aa3
1 changed files with 42 additions and 1 deletions
|
@ -392,6 +392,17 @@ var Body = new Class({
|
||||||
*/
|
*/
|
||||||
this.worldBounce = null;
|
this.worldBounce = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The custom boundary rectangle to use instead of the world boundary.
|
||||||
|
* If null, the world boundaries are used instead.
|
||||||
|
*
|
||||||
|
* @name Phaser.Physics.Arcade.Body#customBoundsRectangle
|
||||||
|
* @type {?Phaser.Geom.Rectangle}
|
||||||
|
* @default null
|
||||||
|
* @since 3.16.1
|
||||||
|
*/
|
||||||
|
this.customBoundsRectangle = null;
|
||||||
|
|
||||||
// If true this Body will dispatch events
|
// If true this Body will dispatch events
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1026,6 +1037,36 @@ var Body = new Class({
|
||||||
this.prev.y = this.position.y;
|
this.prev.y = this.position.y;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the collision boundary rectangle. Either a custom one, which was
|
||||||
|
* set with setBoundsRectangle or the default world's bounds.
|
||||||
|
*
|
||||||
|
* @method Phaser.Physics.Arcade.Body#getBoundsRectangle
|
||||||
|
* @since 3.16.1
|
||||||
|
*
|
||||||
|
* @return {Phaser.Geom.Rectangle}
|
||||||
|
*/
|
||||||
|
getBoundsRectangle: function ()
|
||||||
|
{
|
||||||
|
return (this.customBoundsRectangle || this.world.bounds);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a custom collision boundary rectangle. Use if you want to have a custom
|
||||||
|
* boundary instead of the world boundaries.
|
||||||
|
*
|
||||||
|
* @method Phaser.Physics.Arcade.Body#setBoundsRectangle
|
||||||
|
* @since 3.16.1
|
||||||
|
*
|
||||||
|
* @param {Phaser.Geom.Rectangle} rect - The new boundary rectangle. Pass null to use the default world bounds again.
|
||||||
|
* @return {Phaser.Physics.Arcade.Body} This Body object.
|
||||||
|
*/
|
||||||
|
setBoundsRectangle: function (rect)
|
||||||
|
{
|
||||||
|
this.customBoundsRectangle = rect;
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks for collisions between this Body and the world boundary and separates them.
|
* Checks for collisions between this Body and the world boundary and separates them.
|
||||||
*
|
*
|
||||||
|
@ -1037,7 +1078,7 @@ var Body = new Class({
|
||||||
checkWorldBounds: function ()
|
checkWorldBounds: function ()
|
||||||
{
|
{
|
||||||
var pos = this.position;
|
var pos = this.position;
|
||||||
var bounds = this.world.bounds;
|
var bounds = this.getBoundsRectangle();
|
||||||
var check = this.world.checkCollision;
|
var check = this.world.checkCollision;
|
||||||
|
|
||||||
var bx = (this.worldBounce) ? -this.worldBounce.x : -this.bounce.x;
|
var bx = (this.worldBounce) ? -this.worldBounce.x : -this.bounce.x;
|
||||||
|
|
Loading…
Reference in a new issue