diff --git a/README.md b/README.md
index 6a42b4cd..498451a9 100644
--- a/README.md
+++ b/README.md
@@ -39,6 +39,9 @@ Change Log
Version 1.1.2
+* Fixed issue 135 - Added typeof checks into most ArcadePhysics functions to avoid errors with zero values.
+* Fixed issue 136 - distanceTo using worldX/Y instead of x/y.
+
Version 1.1.1 - October 26th 2013
diff --git a/examples/collision/group vs group.js b/examples/collision/group vs group.js
index 75754867..dc6b4151 100644
--- a/examples/collision/group vs group.js
+++ b/examples/collision/group vs group.js
@@ -44,6 +44,9 @@ function create() {
sprite = game.add.sprite(400, 550, 'phaser');
+ // Stop the following keys from propagating up to the browser
+ game.input.keyboard.addKeyCapture([ Phaser.Keyboard.LEFT, Phaser.Keyboard.RIGHT, Phaser.Keyboard.SPACEBAR ]);
+
}
function update() {
diff --git a/examples/collision/sprite vs group.js b/examples/collision/sprite vs group.js
index 781e10fd..c0f08a6b 100644
--- a/examples/collision/sprite vs group.js
+++ b/examples/collision/sprite vs group.js
@@ -37,6 +37,8 @@ function create() {
c.body.immovable = true;
}
+ game.input.keyboard.addKeyCapture([ Phaser.Keyboard.LEFT, Phaser.Keyboard.RIGHT, Phaser.Keyboard.UP, Phaser.Keyboard.DOWN ]);
+
}
function update() {
diff --git a/examples/collision/transform.js b/examples/collision/transform.js
index 4188d132..2411433b 100644
--- a/examples/collision/transform.js
+++ b/examples/collision/transform.js
@@ -52,7 +52,7 @@ function test2 () {
sprite1.body.immovable = true;
// sprite1.body.setSize(100, 100, 0, 0);
- sprite2 = game.add.sprite(-100, 150, 'mushroom');
+ sprite2 = game.add.sprite(-100, 140, 'mushroom');
sprite2.name = 'mushroom';
sprite3 = game.add.sprite(-200, 150, 'flectrum');
diff --git a/examples/index.html b/examples/index.html
index c164a413..311b0e65 100644
--- a/examples/index.html
+++ b/examples/index.html
@@ -12,7 +12,7 @@
diff --git a/examples/tilemaps/sci fly.js b/examples/tilemaps/sci fly.js
index e5de4111..472ec5ed 100644
--- a/examples/tilemaps/sci fly.js
+++ b/examples/tilemaps/sci fly.js
@@ -1,5 +1,5 @@
-var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
+var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
@@ -54,7 +54,7 @@ function create() {
sprite.anchor.setTo(0.5, 0.5);
game.camera.follow(sprite);
- game.camera.deadzone = new Phaser.Rectangle(160, 160, layer.renderWidth-320, layer.renderHeight-320);
+ // game.camera.deadzone = new Phaser.Rectangle(160, 160, layer.renderWidth-320, layer.renderHeight-320);
cursors = game.input.keyboard.createCursorKeys();
@@ -80,7 +80,7 @@ function particleBurst() {
function update() {
- game.physics.collide(sprite, layer);
+ // game.physics.collide(sprite, layer);
game.physics.collide(emitter, layer);
sprite.body.velocity.x = 0;
@@ -88,7 +88,7 @@ function update() {
if (cursors.up.isDown)
{
- sprite.body.velocity.y = -150;
+ sprite.body.velocity.y = -150;
}
else if (cursors.down.isDown)
{
@@ -107,3 +107,12 @@ function update() {
}
}
+
+
+function render() {
+
+ // game.debug.renderSpriteCorners(sprite);
+ // game.debug.renderSpriteInfo(sprite, 32, 32);
+ game.debug.renderSpriteCoords(sprite, 32, 32);
+
+}
\ No newline at end of file
diff --git a/src/gameobjects/Sprite.js b/src/gameobjects/Sprite.js
index 3384cb73..43518256 100644
--- a/src/gameobjects/Sprite.js
+++ b/src/gameobjects/Sprite.js
@@ -364,8 +364,16 @@ 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.updateCache();
this.updateAnimation();
diff --git a/src/physics/arcade/ArcadePhysics.js b/src/physics/arcade/ArcadePhysics.js
index d9579234..ad419aa3 100644
--- a/src/physics/arcade/ArcadePhysics.js
+++ b/src/physics/arcade/ArcadePhysics.js
@@ -404,28 +404,25 @@ Phaser.Physics.Arcade.prototype = {
this._mapData = tilemapLayer.getTiles(sprite.body.x, sprite.body.y, sprite.body.width, sprite.body.height, true);
- if (this._mapData.length > 1)
+ // console.log('getTiles', this._tx, this._ty);
+ if (this.game.input.keyboard.isDown(Phaser.Keyboard.SHIFT))
{
- for (var i = 1; i < this._mapData.length; i++)
+ console.log('cst', this._mapData, sprite.body.x, sprite.body.y);
+ }
+
+ if (this._mapData.length == 0)
+ {
+ return;
+ }
+
+ for (var i = 0; i < this._mapData.length; i++)
+ {
+ if (this.separateTile(sprite.body, this._mapData[i]))
{
- this.separateTile(sprite.body, this._mapData[i]);
-
- if (this._result)
+ // They collided, is there a custom process callback?
+ if (processCallback)
{
- // They collided, is there a custom process callback?
- if (processCallback)
- {
- if (processCallback.call(callbackContext, sprite, this._mapData[i]))
- {
- this._total++;
-
- if (collideCallback)
- {
- collideCallback.call(callbackContext, sprite, this._mapData[i]);
- }
- }
- }
- else
+ if (processCallback.call(callbackContext, sprite, this._mapData[i]))
{
this._total++;
@@ -435,6 +432,15 @@ Phaser.Physics.Arcade.prototype = {
}
}
}
+ else
+ {
+ this._total++;
+
+ if (collideCallback)
+ {
+ collideCallback.call(callbackContext, sprite, this._mapData[i]);
+ }
+ }
}
}
@@ -1025,8 +1031,8 @@ Phaser.Physics.Arcade.prototype = {
*/
moveToObject: function (displayObject, destination, speed, maxTime) {
- speed = speed || 60;
- maxTime = maxTime || 0;
+ if (typeof speed === 'undefined') { speed = 60; }
+ if (typeof maxTime === 'undefined') { maxTime = 0; }
this._angle = Math.atan2(destination.y - displayObject.y, destination.x - displayObject.x);
@@ -1059,9 +1065,9 @@ Phaser.Physics.Arcade.prototype = {
*/
moveToPointer: function (displayObject, speed, pointer, maxTime) {
- speed = speed || 60;
+ if (typeof speed === 'undefined') { speed = 60; }
pointer = pointer || this.game.input.activePointer;
- maxTime = maxTime || 0;
+ if (typeof maxTime === 'undefined') { maxTime = 0; }
this._angle = this.angleToPointer(displayObject, pointer);
@@ -1096,8 +1102,8 @@ Phaser.Physics.Arcade.prototype = {
*/
moveToXY: function (displayObject, x, y, speed, maxTime) {
- speed = speed || 60;
- maxTime = maxTime || 0;
+ if (typeof speed === 'undefined') { speed = 60; }
+ if (typeof maxTime === 'undefined') { maxTime = 0; }
this._angle = Math.atan2(y - displayObject.y, x - displayObject.x);
@@ -1126,7 +1132,7 @@ Phaser.Physics.Arcade.prototype = {
*/
velocityFromAngle: function (angle, speed, point) {
- speed = speed || 60;
+ if (typeof speed === 'undefined') { speed = 60; }
point = point || new Phaser.Point;
return point.setTo((Math.cos(this.game.math.degToRad(angle)) * speed), (Math.sin(this.game.math.degToRad(angle)) * speed));
@@ -1145,7 +1151,7 @@ Phaser.Physics.Arcade.prototype = {
*/
velocityFromRotation: function (rotation, speed, point) {
- speed = speed || 60;
+ if (typeof speed === 'undefined') { speed = 60; }
point = point || new Phaser.Point;
return point.setTo((Math.cos(rotation) * speed), (Math.sin(rotation) * speed));
@@ -1164,7 +1170,7 @@ Phaser.Physics.Arcade.prototype = {
*/
accelerationFromRotation: function (rotation, speed, point) {
- speed = speed || 60;
+ if (typeof speed === 'undefined') { speed = 60; }
point = point || new Phaser.Point;
return point.setTo((Math.cos(rotation) * speed), (Math.sin(rotation) * speed));
@@ -1311,8 +1317,8 @@ Phaser.Physics.Arcade.prototype = {
pointer = pointer || this.game.input.activePointer;
- this._dx = displayObject.worldX - pointer.x;
- this._dy = displayObject.worldY - pointer.y;
+ this._dx = displayObject.x - pointer.x;
+ this._dy = displayObject.y - pointer.y;
return Math.sqrt(this._dx * this._dx + this._dy * this._dy);
diff --git a/src/physics/arcade/Body.js b/src/physics/arcade/Body.js
index 7827de7c..26cff394 100644
--- a/src/physics/arcade/Body.js
+++ b/src/physics/arcade/Body.js
@@ -350,6 +350,8 @@ 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;
diff --git a/src/tilemap/TilemapLayer.js b/src/tilemap/TilemapLayer.js
index c49afbd3..65b3e370 100644
--- a/src/tilemap/TilemapLayer.js
+++ b/src/tilemap/TilemapLayer.js
@@ -311,10 +311,13 @@ Phaser.TilemapLayer.prototype.getTiles = function (x, y, width, height, collides
this._tw = (this.game.math.snapToCeil(width, tileWidth) + tileWidth) / tileWidth;
this._th = (this.game.math.snapToCeil(height, tileHeight) + tileHeight) / tileHeight;
- this._results.length = 0;
+ // This should apply the layer x/y here
+
+ // this._results.length = 0;
+ this._results = [];
// pretty sure we don't use this any more?
- this._results.push( { x: x, y: y, width: width, height: height, tx: this._tx, ty: this._ty, tw: this._tw, th: this._th });
+ // this._results.push( { x: x, y: y, width: width, height: height, tx: this._tx, ty: this._ty, tw: this._tw, th: this._th });
var _index = 0;
var _tile = null;
diff --git a/src/utils/Debug.js b/src/utils/Debug.js
index f959530b..9b6cca2c 100644
--- a/src/utils/Debug.js
+++ b/src/utils/Debug.js
@@ -559,6 +559,8 @@ Phaser.Utils.Debug.prototype = {
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]);