Jump to content

Changing Sprite's Scale Causes Physics Body To Become Detached


Disease
 Share

Recommended Posts

I'm using Phaser 2.4.8 and seem to be having a strange issue. 

In the player sprite constructor I set the anchor to .5, .5

this.anchor.setTo(.5, .5);

The spritesheet is drawn with the character facing right, so when the player presses LEFT this is what I do to point it left:

          if (this.game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
            if (this.scale.x == 1) {
              this.scale.x = -1;
            }
}

Unfortunately this simple act causes the Sprite's physics body to leap to the sprite/sprite texture's right side for no reason I can see. The image of the character moves around fine but the physics body jumps around every time the scale switches between 1 and -1. 

You can see this happening with all the debugging information turned on at:

http://syntonicstudios.github.io/Shapeshifter/bin/index.html

Also the entire source of the game is at:

https://github.com/SyntonicStudios/Shapeshifter

I thought I was missing something simple until I looked at an old game I did wish Phaser were I did the exact same thing but this issue did not crop up at all. 

Anyone know what is going on here? 

Link to comment
Share on other sites

5 minutes ago, LTNGames said:

 

Alright, thanks for the quick reply. I must have a bad case of Imposter Syndrome because I was staring intently at my code for like two hours trying to figure out where I messed up. 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...