ArcadePhysics.World now has a checkCollision object which can be used to toggle collision against the 4 walls of its bounds.

This commit is contained in:
photonstorm 2014-03-19 04:03:21 +00:00
parent 2cc1a45f9a
commit 0a42ac39b9
3 changed files with 12 additions and 4 deletions

View file

@ -101,6 +101,7 @@ New Features:
* Device.getUserMedia boolean added, useful if you need access to the webcam or microphone.
* Math.removeRandom allows you to remove (and return) a random object from an array.
* ArcadePhysics.World now has a checkCollision object which can be used to toggle collision against the 4 walls of its bounds.
TODO:

View file

@ -446,26 +446,26 @@ Phaser.Physics.Arcade.Body.prototype = {
*/
checkWorldBounds: function () {
if (this.position.x < this.game.physics.arcade.bounds.x)
if (this.position.x < this.game.physics.arcade.bounds.x && this.game.physics.arcade.checkCollision.left)
{
this.position.x = this.game.physics.arcade.bounds.x;
this.velocity.x *= -this.bounce.x;
this.blocked.left = true;
}
else if (this.right > this.game.physics.arcade.bounds.right)
else if (this.right > this.game.physics.arcade.bounds.right && this.game.physics.arcade.checkCollision.right)
{
this.position.x = this.game.physics.arcade.bounds.right - this.width;
this.velocity.x *= -this.bounce.x;
this.blocked.right = true;
}
if (this.position.y < this.game.physics.arcade.bounds.y)
if (this.position.y < this.game.physics.arcade.bounds.y && this.game.physics.arcade.checkCollision.up)
{
this.position.y = this.game.physics.arcade.bounds.y;
this.velocity.y *= -this.bounce.y;
this.blocked.up = true;
}
else if (this.bottom > this.game.physics.arcade.bounds.bottom)
else if (this.bottom > this.game.physics.arcade.bounds.bottom && this.game.physics.arcade.checkCollision.down)
{
this.position.y = this.game.physics.arcade.bounds.bottom - this.height;
this.velocity.y *= -this.bounce.y;

View file

@ -29,6 +29,13 @@ Phaser.Physics.Arcade = function (game) {
*/
this.bounds = new Phaser.Rectangle(0, 0, game.world.width, game.world.height);
/**
* Set the checkCollision properties to control for which bounds collision is processed.
* For example checkCollision.down = false means Bodies cannot collide with the World.bounds.bottom.
* @property {object} checkCollision - An object containing allowed collision flags.
*/
this.checkCollision = { up: true, down: true, left: true, right: true };
/**
* @property {number} maxObjects - Used by the QuadTree to set the maximum number of objects per quad.
*/