mirror of
https://github.com/wassname/phaser.git
synced 2026-07-25 13:20:14 +08:00
Fixing collision issues
This commit is contained in:
@@ -380,11 +380,11 @@ Phaser.Physics.Arcade.prototype = {
|
||||
|
||||
this._result = (this.separateX(body1, body2) || this.separateY(body1, body2));
|
||||
|
||||
if (this._result)
|
||||
{
|
||||
body1.postUpdate();
|
||||
body2.postUpdate();
|
||||
}
|
||||
// if (this._result)
|
||||
// {
|
||||
// body1.postUpdate();
|
||||
// body2.postUpdate();
|
||||
// }
|
||||
|
||||
},
|
||||
|
||||
|
||||
+54
-30
@@ -7,6 +7,8 @@ Phaser.Physics.Arcade.Body = function (sprite) {
|
||||
|
||||
this.x = sprite.x;
|
||||
this.y = sprite.y;
|
||||
this.preX = sprite.x;
|
||||
this.preY = sprite.y;
|
||||
this.lastX = sprite.x;
|
||||
this.lastY = sprite.y;
|
||||
|
||||
@@ -82,7 +84,7 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
|
||||
},
|
||||
|
||||
update: function () {
|
||||
preUpdate: function () {
|
||||
|
||||
// Store and reset collision flags
|
||||
this.wasTouching.none = this.touching.none;
|
||||
@@ -97,13 +99,16 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
this.touching.left = false;
|
||||
this.touching.right = false;
|
||||
|
||||
this.lastX = this.x;
|
||||
this.lastY = this.y;
|
||||
this.preX = (this.sprite.worldTransform[2] - (this.sprite.anchor.x * this.width)) + this.offset.x;
|
||||
this.preY = (this.sprite.worldTransform[5] - (this.sprite.anchor.y * this.height)) + this.offset.y;
|
||||
this.rotation = this.sprite.angle;
|
||||
|
||||
this.x = this.preX;
|
||||
this.y = this.preY;
|
||||
|
||||
// There is a bug here in that the worldTransform values are what should be used, otherwise the quadTree gets the wrong rect given to it
|
||||
this.x = (this.sprite.x - (this.sprite.anchor.x * this.width)) + this.offset.x;
|
||||
this.y = (this.sprite.y - (this.sprite.anchor.y * this.height)) + this.offset.y;
|
||||
// this.x = (this.sprite.x - (this.sprite.anchor.x * this.width)) + this.offset.x;
|
||||
// this.y = (this.sprite.y - (this.sprite.anchor.y * this.height)) + this.offset.y;
|
||||
// this.x = (this.sprite.worldTransform[2] - (this.sprite.anchor.x * this.width)) + this.offset.x;
|
||||
// this.y = (this.sprite.worldTransform[5] - (this.sprite.anchor.y * this.height)) + this.offset.y;
|
||||
|
||||
@@ -124,20 +129,6 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
this.game.physics.quadTree.insert(this);
|
||||
}
|
||||
|
||||
if (this.deltaX() != 0)
|
||||
{
|
||||
this.sprite.x -= this.deltaX();
|
||||
}
|
||||
|
||||
if (this.deltaY() != 0)
|
||||
{
|
||||
this.sprite.y -= this.deltaY();
|
||||
}
|
||||
|
||||
// Adjust the sprite based on all of the above, so the x/y coords will be correct going into the State update
|
||||
this.sprite.x = this.x - this.offset.x + (this.sprite.anchor.x * this.width);
|
||||
this.sprite.y = this.y - this.offset.y + (this.sprite.anchor.y * this.height);
|
||||
|
||||
if (this.allowRotation)
|
||||
{
|
||||
this.sprite.angle = this.rotation;
|
||||
@@ -147,14 +138,43 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
|
||||
postUpdate: function () {
|
||||
|
||||
this.sprite.x = this.x - this.offset.x + (this.sprite.anchor.x * this.width);
|
||||
this.sprite.y = this.y - this.offset.y + (this.sprite.anchor.y * this.height);
|
||||
|
||||
if (this.allowRotation)
|
||||
if (this.deltaX() != 0)
|
||||
{
|
||||
this.sprite.angle = this.rotation;
|
||||
this.sprite.position.x += this.deltaX();
|
||||
this.sprite.x += this.deltaX();
|
||||
}
|
||||
|
||||
if (this.deltaY() != 0)
|
||||
{
|
||||
this.sprite.position.y += this.deltaY();
|
||||
this.sprite.y += this.deltaY();
|
||||
}
|
||||
|
||||
|
||||
// this._cache.x = this.x - (this.game.world.camera.x * this.scrollFactor.x);
|
||||
// this._cache.y = this.y - (this.game.world.camera.y * this.scrollFactor.y);
|
||||
|
||||
|
||||
// if (this.position.x != this._cache.x || this.position.y != this._cache.y)
|
||||
// {
|
||||
// this.position.x = this._cache.x;
|
||||
// this.position.y = this._cache.y;
|
||||
// this._cache.dirty = true;
|
||||
// }
|
||||
|
||||
|
||||
// Adjust the sprite based on all of the above, so the x/y coords will be correct going into the State update
|
||||
// this.sprite.x = this.x - this.offset.x + (this.sprite.anchor.x * this.width);
|
||||
// this.sprite.y = this.y - this.offset.y + (this.sprite.anchor.y * this.height);
|
||||
|
||||
// this.sprite.x = this.x - this.offset.x + (this.sprite.anchor.x * this.width);
|
||||
// this.sprite.y = this.y - this.offset.y + (this.sprite.anchor.y * this.height);
|
||||
|
||||
// if (this.allowRotation)
|
||||
// {
|
||||
// this.sprite.angle = this.rotation;
|
||||
// }
|
||||
|
||||
},
|
||||
|
||||
checkWorldBounds: function () {
|
||||
@@ -206,27 +226,31 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
this.angularVelocity = 0;
|
||||
this.angularAcceleration = 0;
|
||||
|
||||
this.x = (this.sprite.x - (this.sprite.anchor.x * this.width)) + this.offset.x;
|
||||
this.y = (this.sprite.y - (this.sprite.anchor.y * this.height)) + this.offset.y;
|
||||
this.lastX = this.x;
|
||||
this.lastY = this.y;
|
||||
// this.x = (this.sprite.x - (this.sprite.anchor.x * this.width)) + this.offset.x;
|
||||
// this.y = (this.sprite.y - (this.sprite.anchor.y * this.height)) + this.offset.y;
|
||||
// this.lastX = this.x;
|
||||
// this.lastY = this.y;
|
||||
|
||||
},
|
||||
|
||||
deltaAbsX: function () {
|
||||
// return (this.deltaX() > 0 ? this.deltaX() : -this.deltaX());
|
||||
return (this.deltaX() > 0 ? this.deltaX() : -this.deltaX());
|
||||
},
|
||||
|
||||
deltaAbsY: function () {
|
||||
// return (this.deltaY() > 0 ? this.deltaY() : -this.deltaY());
|
||||
return (this.deltaY() > 0 ? this.deltaY() : -this.deltaY());
|
||||
},
|
||||
|
||||
deltaX: function () {
|
||||
return this.x - this.lastX;
|
||||
// return this.x - this.lastX;
|
||||
return this.x - this.preX;
|
||||
},
|
||||
|
||||
deltaY: function () {
|
||||
return this.y - this.lastY;
|
||||
// return this.y - this.lastY;
|
||||
return this.y - this.preY;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user