mirror of
https://github.com/wassname/phaser.git
synced 2026-08-11 11:23:06 +08:00
More collision test cases and fixing a few issues as I go :)
This commit is contained in:
@@ -167,6 +167,9 @@ Phaser.Sprite = function (game, x, y, key, frame) {
|
||||
// Set-up the physics body
|
||||
this.body = new Phaser.Physics.Arcade.Body(this);
|
||||
|
||||
this.velocity = this.body.velocity;
|
||||
this.acceleration = this.body.acceleration;
|
||||
|
||||
// World bounds check
|
||||
this.inWorld = Phaser.Rectangle.intersects(this.bounds, this.game.world.bounds);
|
||||
this.inWorldThreshold = 0;
|
||||
|
||||
@@ -424,11 +424,12 @@ Phaser.Physics.Arcade.prototype = {
|
||||
*/
|
||||
separate: function (body1, body2) {
|
||||
|
||||
if (this.separateX(body1, body2) || this.separateY(body1, body2))
|
||||
this._result = (this.separateX(body1, body2) || this.separateY(body1, body2));
|
||||
|
||||
if (this._result)
|
||||
{
|
||||
body1.postUpdate();
|
||||
body2.postUpdate();
|
||||
this._result = true;
|
||||
}
|
||||
|
||||
},
|
||||
@@ -496,12 +497,21 @@ Phaser.Physics.Arcade.prototype = {
|
||||
// Then adjust their positions and velocities accordingly (if there was any overlap)
|
||||
if (this._overlap != 0)
|
||||
{
|
||||
body1.overlapX = this._overlap;
|
||||
body2.overlapX = this._overlap;
|
||||
|
||||
if (body1.customSeparateX || body2.customSeparateX)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
this._velocity1 = body1.velocity.x;
|
||||
this._velocity2 = body2.velocity.x;
|
||||
|
||||
if (!body1.immovable && !body2.immovable)
|
||||
{
|
||||
this._overlap *= 0.5;
|
||||
|
||||
body1.x = body1.x - this._overlap;
|
||||
body2.x += this._overlap;
|
||||
|
||||
@@ -510,6 +520,7 @@ Phaser.Physics.Arcade.prototype = {
|
||||
this._average = (this._newVelocity1 + this._newVelocity2) * 0.5;
|
||||
this._newVelocity1 -= this._average;
|
||||
this._newVelocity2 -= this._average;
|
||||
|
||||
body1.velocity.x = this._average + this._newVelocity1 * body1.bounce.x;
|
||||
body2.velocity.x = this._average + this._newVelocity2 * body2.bounce.x;
|
||||
}
|
||||
@@ -595,12 +606,21 @@ Phaser.Physics.Arcade.prototype = {
|
||||
// Then adjust their positions and velocities accordingly (if there was any overlap)
|
||||
if (this._overlap != 0)
|
||||
{
|
||||
body1.overlapY = this._overlap;
|
||||
body2.overlapY = this._overlap;
|
||||
|
||||
if (body1.customSeparateY || body2.customSeparateY)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
this._velocity1 = body1.velocity.y;
|
||||
this._velocity2 = body2.velocity.y;
|
||||
|
||||
if (!body1.immovable && !body2.immovable)
|
||||
{
|
||||
this._overlap *= 0.5;
|
||||
|
||||
body1.y = body1.y - this._overlap;
|
||||
body2.y += this._overlap;
|
||||
|
||||
@@ -609,6 +629,7 @@ Phaser.Physics.Arcade.prototype = {
|
||||
this._average = (this._newVelocity1 + this._newVelocity2) * 0.5;
|
||||
this._newVelocity1 -= this._average;
|
||||
this._newVelocity2 -= this._average;
|
||||
|
||||
body1.velocity.y = this._average + this._newVelocity1 * body1.bounce.y;
|
||||
body2.velocity.y = this._average + this._newVelocity2 * body2.bounce.y;
|
||||
}
|
||||
@@ -616,6 +637,7 @@ Phaser.Physics.Arcade.prototype = {
|
||||
{
|
||||
body1.y = body1.y - this._overlap;
|
||||
body1.velocity.y = this._velocity2 - this._velocity1 * body1.bounce.y;
|
||||
|
||||
// This is special case code that handles things like horizontal moving platforms you can ride
|
||||
if (body2.active && body2.moves && (body1.deltaY() > body2.deltaY()))
|
||||
{
|
||||
@@ -626,6 +648,7 @@ Phaser.Physics.Arcade.prototype = {
|
||||
{
|
||||
body2.y += this._overlap;
|
||||
body2.velocity.y = this._velocity1 - this._velocity2 * body2.bounce.y;
|
||||
|
||||
// This is special case code that handles things like horizontal moving platforms you can ride
|
||||
if (body1.sprite.active && body1.moves && (body1.deltaY() < body2.deltaY()))
|
||||
{
|
||||
|
||||
@@ -49,6 +49,17 @@ Phaser.Physics.Arcade.Body = function (sprite) {
|
||||
this.allowRotation = true;
|
||||
this.allowGravity = true;
|
||||
|
||||
// These two flags allow you to disable the custom separation that takes place
|
||||
// Used in combination with your own collision processHandler you can create whatever
|
||||
// type of collision response you need.
|
||||
this.customSeparateX = false;
|
||||
this.customSeparateY = false;
|
||||
|
||||
// When this body collides with another the amount of overlap is stored in here
|
||||
// These values are useful if you want to provide your own custom separation logic.
|
||||
this.overlapX = 0;
|
||||
this.overlapY = 0;
|
||||
|
||||
this.collideWorldBounds = false;
|
||||
|
||||
this.lastX = sprite.x;
|
||||
|
||||
Reference in New Issue
Block a user