mirror of
https://github.com/wassname/phaser.git
synced 2026-08-17 11:23:42 +08:00
Collision fixes for testing
This commit is contained in:
+7
-1
@@ -20,7 +20,13 @@ var Phaser = Phaser || {
|
||||
RENDERTEXTURE: 8,
|
||||
TILEMAP: 9,
|
||||
TILEMAPLAYER: 10,
|
||||
EMITTER: 11
|
||||
EMITTER: 11,
|
||||
|
||||
NONE: 0,
|
||||
LEFT: 1,
|
||||
RIGHT: 2,
|
||||
UP: 3,
|
||||
DOWN: 4
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -368,9 +368,13 @@ Phaser.StateManager.prototype = {
|
||||
if (this._created == false && this.onCreateCallback)
|
||||
{
|
||||
// console.log('Create callback found');
|
||||
this._created = true;
|
||||
this.onCreateCallback.call(this.callbackContext);
|
||||
}
|
||||
this._created = true;
|
||||
else
|
||||
{
|
||||
this._created = true;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
||||
@@ -99,6 +99,9 @@ Phaser.Sprite = function (game, x, y, key, frame) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
||||
this.prevX = x;
|
||||
this.prevY = y;
|
||||
|
||||
this.position.x = x;
|
||||
this.position.y = y;
|
||||
|
||||
@@ -215,6 +218,9 @@ Phaser.Sprite.prototype.preUpdate = function() {
|
||||
this.renderOrderID = this.game.world.currentRenderOrderID++;
|
||||
}
|
||||
|
||||
this.prevX = this.x;
|
||||
this.prevY = this.y;
|
||||
|
||||
// |a c tx|
|
||||
// |b d ty|
|
||||
// |0 0 1|
|
||||
@@ -308,6 +314,22 @@ Phaser.Sprite.prototype.postUpdate = function() {
|
||||
|
||||
}
|
||||
|
||||
Phaser.Sprite.prototype.deltaAbsX = function () {
|
||||
return (this.deltaX() > 0 ? this.deltaX() : -this.deltaX());
|
||||
}
|
||||
|
||||
Phaser.Sprite.prototype.deltaAbsY = function () {
|
||||
return (this.deltaY() > 0 ? this.deltaY() : -this.deltaY());
|
||||
}
|
||||
|
||||
Phaser.Sprite.prototype.deltaX = function () {
|
||||
return this.x - this.prevX;
|
||||
}
|
||||
|
||||
Phaser.Sprite.prototype.deltaY = function () {
|
||||
return this.y - this.prevY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the sprite so its center is located on the given x and y coordinates.
|
||||
* Doesn't change the origin of the sprite.
|
||||
|
||||
@@ -44,6 +44,7 @@ Phaser.Physics.Arcade.Body = function (sprite) {
|
||||
this.allowCollision = { none: false, any: true, up: true, down: true, left: true, right: true };
|
||||
this.touching = { none: true, up: false, down: false, left: false, right: false };
|
||||
this.wasTouching = { none: true, up: false, down: false, left: false, right: false };
|
||||
this.facing = Phaser.NONE;
|
||||
|
||||
this.immovable = false;
|
||||
this.moves = true;
|
||||
@@ -130,6 +131,34 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
|
||||
postUpdate: function () {
|
||||
|
||||
// Calculate forward-facing edge
|
||||
if (this.deltaX() == 0 && this.deltaY() == 0)
|
||||
{
|
||||
// Can't work it out from the Body, how about from x position?
|
||||
if (this.sprite.deltaX() == 0 && this.sprite.deltaY() == 0)
|
||||
{
|
||||
// still as a statue
|
||||
}
|
||||
}
|
||||
|
||||
if (this.deltaX() < 0)
|
||||
{
|
||||
this.facing = Phaser.LEFT;
|
||||
}
|
||||
else if (this.deltaX() > 0)
|
||||
{
|
||||
this.facing = Phaser.RIGHT;
|
||||
}
|
||||
|
||||
if (this.deltaY() < 0)
|
||||
{
|
||||
this.facing = Phaser.UP;
|
||||
}
|
||||
else if (this.deltaY() > 0)
|
||||
{
|
||||
this.facing = Phaser.DOWN;
|
||||
}
|
||||
|
||||
if (this.deltaX() != 0)
|
||||
{
|
||||
this.sprite.x += this.deltaX();
|
||||
|
||||
Reference in New Issue
Block a user