From 1097a699c38d05a9b3a45637d71c634b470e1bda Mon Sep 17 00:00:00 2001 From: photonstorm Date: Fri, 14 Feb 2014 18:06:00 +0000 Subject: [PATCH] Fixed anchor issue with Sprite.body. --- labs/code/003 thrust.js | 12 ++---------- src/core/Stage.js | 7 +++++-- src/physics/Body.js | 9 +++++---- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/labs/code/003 thrust.js b/labs/code/003 thrust.js index 08956c20..3809c368 100644 --- a/labs/code/003 thrust.js +++ b/labs/code/003 thrust.js @@ -1,5 +1,5 @@ -var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); +var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update }); function preload() { @@ -16,7 +16,7 @@ function create() { game.world.setBounds(0, 0, 1920, 1200); var bg = game.add.sprite(0, 0, 'backdrop'); - bg.alpha = 0.8; + bg.alpha = 0.4; ship = game.add.sprite(200, 200, 'ship'); ship.physicsEnabled = true; @@ -50,11 +50,3 @@ function update() { } } - -function render() { - - // game.debug.renderText('x: ' + box2.body.velocity.x, 32, 32); - // game.debug.renderText('y: ' + box2.body.velocity.y, 32, 64); - -} - diff --git a/src/core/Stage.js b/src/core/Stage.js index 1f2d62af..fb23944a 100644 --- a/src/core/Stage.js +++ b/src/core/Stage.js @@ -123,9 +123,12 @@ Phaser.Stage.prototype.postUpdate = function () { var i = this.children.length; - while(i-- && this.children[i] !== this.game.world.camera.target) + while(i--) { - this.children[i].postUpdate(); + if (this.children[i] !== this.game.world.camera.target) + { + this.children[i].postUpdate(); + } } } else diff --git a/src/physics/Body.js b/src/physics/Body.js index 8ab9b97b..ee98ef8c 100644 --- a/src/physics/Body.js +++ b/src/physics/Body.js @@ -632,12 +632,13 @@ Phaser.Physics.Body.prototype = { if (typeof sprite === 'undefined') { sprite = this.sprite; } - var px = (sprite.width / 2) + (-sprite.width * sprite.anchor.x); - var py = (sprite.height / 2) + (-sprite.height * sprite.anchor.y); - + // because Sprite.phyicsEnabled = true now sets anchor to 0.5 + // var px = (sprite.width / 2) + (-sprite.width * sprite.anchor.x); + // var py = (sprite.height / 2) + (-sprite.height * sprite.anchor.y); + this.clearShapes(); - return this.addRectangle(sprite.width, sprite.height, px, py, sprite.rotation); + return this.addRectangle(sprite.width, sprite.height, 0, 0, sprite.rotation); },