Nearly fixed the tilemap / body issue. More tests needed but then can push to master.

This commit is contained in:
photonstorm
2013-10-29 04:07:26 +00:00
parent 7ceb11ae49
commit 3de62907a0
8 changed files with 95 additions and 77 deletions
+2 -9
View File
@@ -195,15 +195,8 @@ Phaser.Camera.prototype = {
this.checkBounds();
}
if (this.view.x !== -this.displayObject.position.x)
{
this.displayObject.position.x = -this.view.x;
}
if (this.view.y !== -this.displayObject.position.y)
{
this.displayObject.position.y = -this.view.y;
}
this.displayObject.position.x = -this.view.x;
this.displayObject.position.y = -this.view.y;
},
+17 -14
View File
@@ -306,6 +306,8 @@ Phaser.Sprite = function (game, x, y, key, frame) {
* @default
*/
this.fixedToCamera = false;
this.cameraOffset = new Phaser.Point;
this.world = new Phaser.Point;
/**
* You can crop the Sprites texture by modifying the crop properties. For example crop.width = 50 would set the Sprite to only render 50px wide.
@@ -364,17 +366,19 @@ Phaser.Sprite.prototype.preUpdate = function() {
this.renderOrderID = this.game.world.currentRenderOrderID++;
}
this.prevX = this.x;
this.prevY = this.y;
if (this.fixedToCamera)
{
this.prevX = this.game.camera.view.x + this.x;
this.prevY = this.game.camera.view.y + this.y;
}
else
{
this.prevX = this.x;
this.prevY = this.y;
this.x = this.game.camera.view.x + this.cameraOffset.x;
this.y = this.game.camera.view.y + this.cameraOffset.y;
// this.prevX = this.game.camera.view.x + this.x;
// this.prevY = this.game.camera.view.y + this.y;
}
this.world.setTo(this.game.camera.x + this.worldTransform[2], this.game.camera.y + this.worldTransform[5]);
this.updateCache();
this.updateAnimation();
@@ -656,8 +660,8 @@ Phaser.Sprite.prototype.postUpdate = function() {
if (this.fixedToCamera)
{
this._cache.x = this.game.camera.view.x + this.x;
this._cache.y = this.game.camera.view.y + this.y;
this._cache.x = this.game.camera.view.x + this.cameraOffset.x;
this._cache.y = this.game.camera.view.y + this.cameraOffset.y;
}
else
{
@@ -665,11 +669,10 @@ Phaser.Sprite.prototype.postUpdate = function() {
this._cache.y = this.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.world.setTo(this.game.camera.x + this.worldTransform[2], this.game.camera.y + this.worldTransform[5]);
this.position.x = this._cache.x;
this.position.y = this._cache.y;
}
}
+9 -6
View File
@@ -350,13 +350,14 @@ Phaser.Physics.Arcade.Body.prototype = {
this.embedded = false;
this.screenX = (this.sprite.worldTransform[2] - (this.sprite.anchor.x * this.width)) + this.offset.x;
this.screenY = (this.sprite.worldTransform[5] - (this.sprite.anchor.y * this.height)) + this.offset.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.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.preX = (this.sprite.world.x - (this.sprite.anchor.x * this.width)) + this.offset.x;
this.preY = (this.sprite.world.y - (this.sprite.anchor.y * this.height)) + this.offset.y;
this.preRotation = this.sprite.angle;
@@ -513,8 +514,10 @@ Phaser.Physics.Arcade.Body.prototype = {
this.angularVelocity = 0;
this.angularAcceleration = 0;
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.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.preX = (this.sprite.world.x - (this.sprite.anchor.x * this.width)) + this.offset.x;
this.preY = (this.sprite.world.y - (this.sprite.anchor.y * this.height)) + this.offset.y;
this.preRotation = this.sprite.angle;
this.x = this.preX;
+9 -3
View File
@@ -556,15 +556,21 @@ Phaser.Utils.Debug.prototype = {
this.start(x, y, color);
this.line(sprite.name);
if (sprite.name)
{
this.line(sprite.name);
}
this.line('x: ' + sprite.x);
this.line('y: ' + sprite.y);
this.line('pos x: ' + sprite.position.x);
this.line('pos y: ' + sprite.position.y);
this.line('local x: ' + sprite.localTransform[2]);
this.line('local y: ' + sprite.localTransform[5]);
this.line('world x: ' + sprite.worldTransform[2]);
this.line('world y: ' + sprite.worldTransform[5]);
this.line('t x: ' + sprite.worldTransform[2]);
this.line('t y: ' + sprite.worldTransform[5]);
this.line('world x: ' + sprite.world.x);
this.line('world y: ' + sprite.world.y);
this.stop();