mirror of
https://github.com/photonstorm/phaser
synced 2025-02-17 14:38:30 +00:00
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:
parent
2cc1a45f9a
commit
0a42ac39b9
3 changed files with 12 additions and 4 deletions
|
@ -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:
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue