mirror of
https://github.com/photonstorm/phaser
synced 2024-11-27 23:20:59 +00:00
ArcadePhysics.separate doesn't pass over to seperateX/Y if overlapOnly is true (fix #604)
ArcadePhysics.collideSpriteVsSprite checks if both objects have bodies before processing. ArcadePhysics.Body now checks the ArcadePhysics.World bounds, not the game bounds. ArcadePhysics.Body has reverted to the 1.1.3 method of preUpdate, so you can now position sprites with x/y, drag them, etc, regardless of the Body.moves flag (issue #606) ArcadePhysics.World now has setBounds and setBoundsToWorld methods, which are called automatically on world resizing. ArcadePhysics.Body no longer sets the offset to match the anchor.
This commit is contained in:
parent
9490041c79
commit
79ffda3f18
4 changed files with 57 additions and 58 deletions
|
@ -90,6 +90,10 @@ Updated:
|
|||
* Group.replace will now return the old child, the one that was replaced in the Group.
|
||||
* Group.destroy has a new parameter: `soft`. A soft destruction won't remove the Group from its parent or null game references. Default is `false`.
|
||||
* InputHandler.validForInput is a new method that checks if the handler and its owner should be considered for Pointer input handling or not.
|
||||
* ArcadePhysics.Body now checks the ArcadePhysics.World bounds, not the game bounds.
|
||||
* ArcadePhysics.Body has reverted to the 1.1.3 method of preUpdate, so you can now position sprites with x/y, drag them, etc, regardless of the Body.moves flag (issue #606)
|
||||
* ArcadePhysics.World now has setBounds and setBoundsToWorld methods, which are called automatically on world resizing.
|
||||
* ArcadePhysics.Body no longer sets the offset to match the anchor.
|
||||
|
||||
|
||||
New Features:
|
||||
|
|
|
@ -234,6 +234,11 @@ Phaser.Physics.prototype = {
|
|||
*/
|
||||
setBoundsToWorld: function () {
|
||||
|
||||
if (this.arcade)
|
||||
{
|
||||
this.arcade.setBoundsToWorld();
|
||||
}
|
||||
|
||||
if (this.ninja)
|
||||
{
|
||||
this.ninja.setBoundsToWorld();
|
||||
|
|
|
@ -35,16 +35,6 @@ Phaser.Physics.Arcade.Body = function (sprite) {
|
|||
*/
|
||||
this.offset = new Phaser.Point();
|
||||
|
||||
if (sprite.anchor.x !== 0)
|
||||
{
|
||||
this.offset.x = (sprite.anchor.x * sprite.width);
|
||||
}
|
||||
|
||||
if (sprite.anchor.y !== 0)
|
||||
{
|
||||
this.offset.y = (sprite.anchor.y * sprite.height);
|
||||
}
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} position - The position of the physics body.
|
||||
* @readonly
|
||||
|
@ -329,7 +319,7 @@ Phaser.Physics.Arcade.Body.prototype = {
|
|||
this.halfHeight = Math.floor(this.height / 2);
|
||||
this._sx = scaleX;
|
||||
this._sy = scaleY;
|
||||
this.center.setTo(this.x + this.halfWidth, this.y + this.halfHeight);
|
||||
this.center.setTo(this.position.x + this.halfWidth, this.position.y + this.halfHeight);
|
||||
}
|
||||
|
||||
},
|
||||
|
@ -362,6 +352,14 @@ Phaser.Physics.Arcade.Body.prototype = {
|
|||
this.blocked.left = false;
|
||||
this.blocked.right = false;
|
||||
|
||||
this.position.x = (this.sprite.world.x - (this.sprite.anchor.x * this.width)) + this.offset.x;
|
||||
this.position.y = (this.sprite.world.y - (this.sprite.anchor.y * this.height)) + this.offset.y;
|
||||
this.rotation = this.sprite.angle;
|
||||
|
||||
this.prev.x = this.position.x;
|
||||
this.prev.y = this.position.y;
|
||||
this.preRotation = this.rotation;
|
||||
|
||||
if (this.moves)
|
||||
{
|
||||
this.game.physics.arcade.updateMotion(this);
|
||||
|
@ -385,12 +383,6 @@ Phaser.Physics.Arcade.Body.prototype = {
|
|||
this.checkWorldBounds();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// If the body doesn't move (i.e. is in a moving Group) then we need its position
|
||||
this.position.x = (this.sprite.world.x - (this.sprite.anchor.x * this.width)) + this.offset.x;
|
||||
this.position.y = (this.sprite.world.y - (this.sprite.anchor.y * this.height)) + this.offset.y;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
@ -422,20 +414,17 @@ Phaser.Physics.Arcade.Body.prototype = {
|
|||
|
||||
if (this.moves)
|
||||
{
|
||||
this.sprite.x = this.position.x + this.offset.x;
|
||||
this.sprite.y = this.position.y + this.offset.y;
|
||||
this.sprite.x += this.deltaX();
|
||||
this.sprite.y += this.deltaY();
|
||||
}
|
||||
|
||||
this.center.setTo(this.x + this.halfWidth, this.y + this.halfHeight);
|
||||
this.center.setTo(this.position.x + this.halfWidth, this.position.y + this.halfHeight);
|
||||
|
||||
if (this.allowRotation)
|
||||
{
|
||||
this.sprite.angle += this.deltaZ();
|
||||
}
|
||||
|
||||
this.prev.set(this.position.x, this.position.y);
|
||||
this.preRotation = this.rotation;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -457,28 +446,28 @@ Phaser.Physics.Arcade.Body.prototype = {
|
|||
*/
|
||||
checkWorldBounds: function () {
|
||||
|
||||
if (this.x < this.game.world.bounds.x)
|
||||
if (this.position.x < this.game.physics.arcade.bounds.x)
|
||||
{
|
||||
this.x = this.game.world.bounds.x;
|
||||
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.world.bounds.right)
|
||||
else if (this.right > this.game.physics.arcade.bounds.right)
|
||||
{
|
||||
this.x = this.game.world.bounds.right - this.width;
|
||||
this.position.x = this.game.physics.arcade.bounds.right - this.width;
|
||||
this.velocity.x *= -this.bounce.x;
|
||||
this.blocked.right = true;
|
||||
}
|
||||
|
||||
if (this.y < this.game.world.bounds.y)
|
||||
if (this.position.y < this.game.physics.arcade.bounds.y)
|
||||
{
|
||||
this.y = this.game.world.bounds.y;
|
||||
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.world.bounds.bottom)
|
||||
else if (this.bottom > this.game.physics.arcade.bounds.bottom)
|
||||
{
|
||||
this.y = this.game.world.bounds.bottom - this.height;
|
||||
this.position.y = this.game.physics.arcade.bounds.bottom - this.height;
|
||||
this.velocity.y *= -this.bounce.y;
|
||||
this.blocked.down = true;
|
||||
}
|
||||
|
@ -509,7 +498,7 @@ Phaser.Physics.Arcade.Body.prototype = {
|
|||
this.halfHeight = Math.floor(this.height / 2);
|
||||
this.offset.setTo(offsetX, offsetY);
|
||||
|
||||
this.center.setTo(this.x + this.halfWidth, this.y + this.halfHeight);
|
||||
this.center.setTo(this.position.x + this.halfWidth, this.position.y + this.halfHeight);
|
||||
|
||||
},
|
||||
|
||||
|
@ -533,7 +522,7 @@ Phaser.Physics.Arcade.Body.prototype = {
|
|||
this.rotation = this.sprite.rotation;
|
||||
this.preRotation = this.rotation;
|
||||
|
||||
this.center.setTo(this.x + this.halfWidth, this.y + this.halfHeight);
|
||||
this.center.setTo(this.position.x + this.halfWidth, this.position.y + this.halfHeight);
|
||||
|
||||
},
|
||||
|
||||
|
|
|
@ -56,18 +56,6 @@ Phaser.Physics.Arcade = function (game) {
|
|||
|
||||
// Avoid gc spikes by caching these values for re-use
|
||||
|
||||
/**
|
||||
* @property {Phaser.Rectangle} _bounds1 - Internal cache var.
|
||||
* @private
|
||||
*/
|
||||
this._bounds1 = new Phaser.Rectangle();
|
||||
|
||||
/**
|
||||
* @property {Phaser.Rectangle} _bounds2 - Internal cache var.
|
||||
* @private
|
||||
*/
|
||||
this._bounds2 = new Phaser.Rectangle();
|
||||
|
||||
/**
|
||||
* @property {number} _overlap - Internal cache var.
|
||||
* @private
|
||||
|
@ -116,12 +104,6 @@ Phaser.Physics.Arcade = function (game) {
|
|||
*/
|
||||
this._mapData = [];
|
||||
|
||||
/**
|
||||
* @property {number} _mapTiles - Internal cache var.
|
||||
* @private
|
||||
*/
|
||||
this._mapTiles = 0;
|
||||
|
||||
/**
|
||||
* @property {boolean} _result - Internal cache var.
|
||||
* @private
|
||||
|
@ -152,19 +134,38 @@ Phaser.Physics.Arcade = function (game) {
|
|||
*/
|
||||
this._dy = 0;
|
||||
|
||||
/**
|
||||
* @property {number} _intersection - Internal cache var.
|
||||
* @private
|
||||
*/
|
||||
// this._intersection = [0,0,0,0];
|
||||
this._intersection = new Phaser.Rectangle();
|
||||
|
||||
};
|
||||
|
||||
Phaser.Physics.Arcade.prototype.constructor = Phaser.Physics.Arcade;
|
||||
|
||||
Phaser.Physics.Arcade.prototype = {
|
||||
|
||||
/**
|
||||
* Updates the size of this physics world.
|
||||
*
|
||||
* @method Phaser.Physics.Arcade#setBounds
|
||||
* @param {number} x - Top left most corner of the world.
|
||||
* @param {number} y - Top left most corner of the world.
|
||||
* @param {number} width - New width of the world. Can never be smaller than the Game.width.
|
||||
* @param {number} height - New height of the world. Can never be smaller than the Game.height.
|
||||
*/
|
||||
setBounds: function (x, y, width, height) {
|
||||
|
||||
this.bounds.setTo(x, y, width, height);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Updates the size of this physics world to match the size of the game world.
|
||||
*
|
||||
* @method Phaser.Physics.Arcade#setBoundsToWorld
|
||||
*/
|
||||
setBoundsToWorld: function () {
|
||||
|
||||
this.bounds.setTo(this.game.world.bounds.x, this.game.world.bounds.y, this.game.world.bounds.width, this.game.world.bounds.height);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* This will create an Arcade Physics body on the given game object or array of game objects.
|
||||
* A game object can only have 1 physics body active at any one time, and it can't be changed until the object is destroyed.
|
||||
|
|
Loading…
Reference in a new issue