diff --git a/examples/games/invaders.js b/examples/games/invaders.js index 8b001000..b522eab9 100644 --- a/examples/games/invaders.js +++ b/examples/games/invaders.js @@ -300,5 +300,7 @@ function render() { { game.debug.renderPhysicsBody(aliens._container.children[i].body); } + + game.debug.renderPhysicsBody(player.body); } \ No newline at end of file diff --git a/examples/wip/body group.js b/examples/wip/body group.js index ce70ab4a..946b21b2 100644 --- a/examples/wip/body group.js +++ b/examples/wip/body group.js @@ -114,7 +114,9 @@ function createAliens () { } */ - bob = aliens.create(48, 50, 'invader'); +bob = game.add.sprite(32, 32, 'invader'); + + // bob = aliens.create(48, 50, 'invader'); bob.debug = true; @@ -145,8 +147,9 @@ console.log('descend'); function update() { - aliens.x += 1; - // bob.body.velocity.x = 100; + // aliens.x += 1; + bob.body.velocity.x = 100; + // bob.body.velocity.y = 100; // Scroll the background // starfield.tilePosition.y += 2; @@ -325,7 +328,9 @@ function render() { for (var i = 0; i < aliens._container.children.length; i++) { - game.debug.renderPhysicsBody(aliens._container.children[i].body); + // game.debug.renderPhysicsBody(aliens._container.children[i].body); } - + + game.debug.renderPhysicsBody(bob.body); + } \ No newline at end of file diff --git a/src/gameobjects/Sprite.js b/src/gameobjects/Sprite.js index 4471ef92..d964861d 100644 --- a/src/gameobjects/Sprite.js +++ b/src/gameobjects/Sprite.js @@ -729,7 +729,7 @@ Phaser.Sprite.prototype.postUpdate = function() { { this.body.postUpdate(); - console.log('Sprite postUpdate wt', this.worldTransform[2], this.worldTransform[5], 'xy', this.x, this.y); + // console.log('Sprite postUpdate wt', this.worldTransform[2], this.worldTransform[5], 'xy', this.x, this.y); // this._cache.x = this.x; // this._cache.y = this.y; @@ -751,7 +751,7 @@ Phaser.Sprite.prototype.postUpdate = function() { this._cache.y = this.y; } - this.world.setTo(this.game.camera.x + this.worldTransform[2], this.game.camera.y + this.worldTransform[5]); + // 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; diff --git a/src/physics/arcade/Body.js b/src/physics/arcade/Body.js index c51b38a7..b44b1127 100644 --- a/src/physics/arcade/Body.js +++ b/src/physics/arcade/Body.js @@ -477,27 +477,34 @@ Phaser.Physics.Arcade.Body.prototype = { */ preUpdate: function () { - // this.preX = this.x; - // this.preY = this.y; - // this.preRotation = this.sprite.angle; // If the GROUP is moving, then this doesn't work!!! - this.x = (this.sprite.x - (this.sprite.anchor.x * this.sprite.width)) + this.offset.x; - this.y = (this.sprite.y - (this.sprite.anchor.y * this.sprite.height)) + this.offset.y; + // this.x = (this.sprite.x - (this.sprite.anchor.x * this.sprite.width)) + this.offset.x; + // this.y = (this.sprite.y - (this.sprite.anchor.y * this.sprite.height)) + this.offset.y; // If the SPRITE is moving, but in a Group, this doesn't work!!! - // this.x = (this.sprite.world.x - (this.sprite.anchor.x * this.sprite.width)) + this.offset.x; - // this.y = (this.sprite.world.y - (this.sprite.anchor.y * this.sprite.height)) + this.offset.y; - - // I think I need to record both the world AND local X/Y values and decide if they should update? - - this.rotation = this.preRotation; + this.x = (this.sprite.world.x - (this.sprite.anchor.x * this.sprite.width)) + this.offset.x; + this.y = (this.sprite.world.y - (this.sprite.anchor.y * this.sprite.height)) + this.offset.y; + // This covers any motion that happens during this frame, no since the last frame this.preX = this.x; this.preY = this.y; this.preRotation = this.sprite.angle; + + // I think I need to record both the world AND local X/Y values and decide if they should update? + + // Velocity will adjust a sprites local x/y, but it may still be being updated by a group x/y too, so don't over-write both! + // Equally don't use world x/y changes as delta, but DO use them for precise positioning of the Body. + + this.rotation = this.preRotation; + + // this.preX = this.x; + // this.preY = this.y; + // this.preRotation = this.sprite.angle; + + if (this.sprite.scale.x !== this._sx || this.sprite.scale.y !== this._sy) { this.updateScale(); @@ -1334,26 +1341,32 @@ if (this.sprite.debug) // console.log('Body postUpdate Sprite:', this.sprite.x, this.sprite.y, 'cached', this.sprite._cache.x, this.sprite._cache.y); // console.log('Body postUpdate Rotation:', this.rotation); - // console.log('Body postUpdate Sprite x:', this.sprite.x, 'y:', this.sprite.y); - // console.log('Body postUpdate Sprite world:', this.sprite.world.x, 'y:', this.sprite.world.y); + console.log('Body postUpdate Sprite x:', this.sprite.x, 'y:', this.sprite.y); + console.log('Body postUpdate Sprite world:', this.sprite.world.x, 'y:', this.sprite.world.y); // console.log('Body postUpdate Sprite position:', this.sprite.position.x, 'y:', this.sprite.position.y); // console.log('Body postUpdate Sprite localTransform:', this.sprite.localTransform[2], 'y:', this.sprite.localTransform[5]); // console.log('Body postUpdate Sprite worldTransform:', this.sprite.worldTransform[2], 'y:', this.sprite.worldTransform[5]); } - if (this.preX !== this.x || this.preY !== this.y) + if (this.deltaX() !== 0 || this.deltaY() !== 0) { - console.log('BoDY APPLIED', this.x, this.y, 'pre', this.preX, this.preY); + // console.log('BoDY APPLIED', this.x, this.y, 'pre', this.preX, this.preY, 'delta', this.deltaX(), this.deltaY()); + + this.sprite.x += this.deltaX(); + this.sprite.y += this.deltaY(); + } + + // this.sprite.x = (this.x + (this.sprite.anchor.x * this.sprite.width) - this.offset.x); // this.sprite.y = (this.y + (this.sprite.anchor.y * this.sprite.height) - this.offset.y); - this.sprite.x = (this.x + (this.sprite.anchor.x * this.sprite.width) - this.offset.x); - this.sprite.y = (this.y + (this.sprite.anchor.y * this.sprite.height) - this.offset.y); + // this.sprite.x = (this.x + (this.sprite.anchor.x * this.sprite.width) - this.offset.x); + // this.sprite.y = (this.y + (this.sprite.anchor.y * this.sprite.height) - this.offset.y); // this.sprite.position.x = this.sprite.x = this.x + (this.sprite.anchor.x * this.sprite.width) - this.offset.x; // this.sprite.position.y = this.sprite.y = this.y + (this.sprite.anchor.y * this.sprite.height) - this.offset.y; - } + // } if (this.allowRotation && this.deltaZ() !== 0) { @@ -1400,6 +1413,8 @@ if (this.sprite.debug) this.blocked = { x: 0, y: 0, up: false, down: false, left: false, right: false }; this.x = (this.sprite.world.x - (this.sprite.anchor.x * this.sprite.width)) + this.offset.x; this.y = (this.sprite.world.y - (this.sprite.anchor.y * this.sprite.height)) + this.offset.y; + this.preX = this.x; + this.preY = this.y; this.updateBounds(); }, @@ -1412,14 +1427,14 @@ if (this.sprite.debug) */ deltaX: function () { - if (this.moves) - { + // if (this.moves) + // { return this.x - this.preX; - } - else - { - return this.sprite.deltaX; - } + // } + // else + // { + // return this.sprite.deltaX; + // } }, @@ -1431,14 +1446,14 @@ if (this.sprite.debug) */ deltaY: function () { - if (this.moves) - { + // if (this.moves) + // { return this.y - this.preY; - } - else - { - return this.sprite.deltaY; - } + // } + // else + // { + // return this.sprite.deltaY; + // } },