Skip to content

Commit 1097a69

Browse files
committed
Fixed anchor issue with Sprite.body.
1 parent 291f8ef commit 1097a69

3 files changed

Lines changed: 12 additions & 16 deletions

File tree

labs/code/003 thrust.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
2+
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
33

44
function preload() {
55

@@ -16,7 +16,7 @@ function create() {
1616
game.world.setBounds(0, 0, 1920, 1200);
1717

1818
var bg = game.add.sprite(0, 0, 'backdrop');
19-
bg.alpha = 0.8;
19+
bg.alpha = 0.4;
2020

2121
ship = game.add.sprite(200, 200, 'ship');
2222
ship.physicsEnabled = true;
@@ -50,11 +50,3 @@ function update() {
5050
}
5151

5252
}
53-
54-
function render() {
55-
56-
// game.debug.renderText('x: ' + box2.body.velocity.x, 32, 32);
57-
// game.debug.renderText('y: ' + box2.body.velocity.y, 32, 64);
58-
59-
}
60-

src/core/Stage.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,12 @@ Phaser.Stage.prototype.postUpdate = function () {
123123

124124
var i = this.children.length;
125125

126-
while(i-- && this.children[i] !== this.game.world.camera.target)
126+
while(i--)
127127
{
128-
this.children[i].postUpdate();
128+
if (this.children[i] !== this.game.world.camera.target)
129+
{
130+
this.children[i].postUpdate();
131+
}
129132
}
130133
}
131134
else

src/physics/Body.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -632,12 +632,13 @@ Phaser.Physics.Body.prototype = {
632632

633633
if (typeof sprite === 'undefined') { sprite = this.sprite; }
634634

635-
var px = (sprite.width / 2) + (-sprite.width * sprite.anchor.x);
636-
var py = (sprite.height / 2) + (-sprite.height * sprite.anchor.y);
637-
635+
// because Sprite.phyicsEnabled = true now sets anchor to 0.5
636+
// var px = (sprite.width / 2) + (-sprite.width * sprite.anchor.x);
637+
// var py = (sprite.height / 2) + (-sprite.height * sprite.anchor.y);
638+
638639
this.clearShapes();
639640

640-
return this.addRectangle(sprite.width, sprite.height, px, py, sprite.rotation);
641+
return this.addRectangle(sprite.width, sprite.height, 0, 0, sprite.rotation);
641642

642643
},
643644

0 commit comments

Comments
 (0)