Skip to content

Commit 09dd845

Browse files
committed
Arcade Physics Body incorrectly positioned if the Sprite had a negative scale (see http://www.html5gamedevs.com/topic/22695-247-248-body-anchoring-any-migration-tips/) (thanks @SBCGames @icameron @Nuuf @EvolViper phaserjs#2488 phaserjs#2490)
1 parent 07e2edc commit 09dd845

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,15 +342,15 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
342342

343343
### Updates
344344

345-
* TypeScript definitions fixes and updates (thanks )
345+
* TypeScript definitions fixes and updates (thanks @wingyplus @monagames)
346346
* Docs typo fixes (thanks )
347-
*
347+
* The TypeScript defs ambient declaration has been updated to make it compatible with the SystemJS loader (thanks @monagames)
348348
*
349349
*
350350

351351
### Bug Fixes
352352

353-
*
353+
* Arcade Physics Body incorrectly positioned if the Sprite had a negative scale (see http://www.html5gamedevs.com/topic/22695-247-248-body-anchoring-any-migration-tips/) (thanks @SBCGames @icameron @Nuuf @EvolViper #2488 #2490)
354354
*
355355
*
356356

src/physics/arcade/Body.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,11 @@ Phaser.Physics.Arcade.Body.prototype = {
452452

453453
this.updateBounds();
454454

455-
this.position.x = (this.sprite.world.x - (this.sprite.anchor.x * this.sprite.width)) + this.offset.x;
456-
this.position.y = (this.sprite.world.y - (this.sprite.anchor.y * this.sprite.height)) + this.offset.y;
455+
this.position.x = (this.sprite.world.x - (this.sprite.anchor.x * this.sprite.width)) + this.sprite.scale.x * this.offset.x;
456+
this.position.x -= this.sprite.scale.x < 0 ? this.width : 0;
457+
458+
this.position.y = (this.sprite.world.y - (this.sprite.anchor.y * this.sprite.height)) + this.sprite.scale.y * this.offset.y;
459+
this.position.y -= this.sprite.scale.y < 0 ? this.height : 0;
457460

458461
this.rotation = this.sprite.angle;
459462

@@ -713,8 +716,11 @@ Phaser.Physics.Arcade.Body.prototype = {
713716
this.angularVelocity = 0;
714717
this.angularAcceleration = 0;
715718

716-
this.position.x = (x - (this.sprite.anchor.x * this.sprite.width)) + this.offset.x;
717-
this.position.y = (y - (this.sprite.anchor.y * this.sprite.height)) + this.offset.y;
719+
this.position.x = (this.sprite.world.x - (this.sprite.anchor.x * this.sprite.width)) + this.sprite.scale.x * this.offset.x;
720+
this.position.x -= this.sprite.scale.x < 0 ? this.width : 0;
721+
722+
this.position.y = (this.sprite.world.y - (this.sprite.anchor.y * this.sprite.height)) + this.sprite.scale.y * this.offset.y;
723+
this.position.y -= this.sprite.scale.y < 0 ? this.height : 0;
718724

719725
this.prev.x = this.position.x;
720726
this.prev.y = this.position.y;

0 commit comments

Comments
 (0)