Skip to content

Commit 0a42ac3

Browse files
committed
ArcadePhysics.World now has a checkCollision object which can be used to toggle collision against the 4 walls of its bounds.
1 parent 2cc1a45 commit 0a42ac3

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ New Features:
101101

102102
* Device.getUserMedia boolean added, useful if you need access to the webcam or microphone.
103103
* Math.removeRandom allows you to remove (and return) a random object from an array.
104+
* ArcadePhysics.World now has a checkCollision object which can be used to toggle collision against the 4 walls of its bounds.
104105

105106

106107
TODO:

src/physics/arcade/Body.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,26 +446,26 @@ Phaser.Physics.Arcade.Body.prototype = {
446446
*/
447447
checkWorldBounds: function () {
448448

449-
if (this.position.x < this.game.physics.arcade.bounds.x)
449+
if (this.position.x < this.game.physics.arcade.bounds.x && this.game.physics.arcade.checkCollision.left)
450450
{
451451
this.position.x = this.game.physics.arcade.bounds.x;
452452
this.velocity.x *= -this.bounce.x;
453453
this.blocked.left = true;
454454
}
455-
else if (this.right > this.game.physics.arcade.bounds.right)
455+
else if (this.right > this.game.physics.arcade.bounds.right && this.game.physics.arcade.checkCollision.right)
456456
{
457457
this.position.x = this.game.physics.arcade.bounds.right - this.width;
458458
this.velocity.x *= -this.bounce.x;
459459
this.blocked.right = true;
460460
}
461461

462-
if (this.position.y < this.game.physics.arcade.bounds.y)
462+
if (this.position.y < this.game.physics.arcade.bounds.y && this.game.physics.arcade.checkCollision.up)
463463
{
464464
this.position.y = this.game.physics.arcade.bounds.y;
465465
this.velocity.y *= -this.bounce.y;
466466
this.blocked.up = true;
467467
}
468-
else if (this.bottom > this.game.physics.arcade.bounds.bottom)
468+
else if (this.bottom > this.game.physics.arcade.bounds.bottom && this.game.physics.arcade.checkCollision.down)
469469
{
470470
this.position.y = this.game.physics.arcade.bounds.bottom - this.height;
471471
this.velocity.y *= -this.bounce.y;

src/physics/arcade/World.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ Phaser.Physics.Arcade = function (game) {
2929
*/
3030
this.bounds = new Phaser.Rectangle(0, 0, game.world.width, game.world.height);
3131

32+
/**
33+
* Set the checkCollision properties to control for which bounds collision is processed.
34+
* For example checkCollision.down = false means Bodies cannot collide with the World.bounds.bottom.
35+
* @property {object} checkCollision - An object containing allowed collision flags.
36+
*/
37+
this.checkCollision = { up: true, down: true, left: true, right: true };
38+
3239
/**
3340
* @property {number} maxObjects - Used by the QuadTree to set the maximum number of objects per quad.
3441
*/

0 commit comments

Comments
 (0)