Jump to content

Horizontal sprite flipping reseting width


Smilo
 Share

Recommended Posts

I have am trying to flip a sprite using

 

sprite.scale.x = -1;

 

This works fine however because I have scaled the sprite previously (Just part of my game mechanics to have different sized enemies) it seems to set the width of the sprite to the origional width values of the image.

 

I was hoping someone could help me to fix this problem as I have been struggling with it.

 

Thanks in advance

 

Link to comment
Share on other sites

  • 1 month later...

Use the random scale you selected for the particular monster, and turn that into a negative.

 

So if you're scaling a particular enemy to 2.5, you'll have to make it a -2.5.  I just set a scaleSetting variable for specific monsters, not random, so I end up with monster.scale.setTo(-scaleSetting, scaleSetting). 

 

 

Interesting when I flip an image like this:

 

image.scale.x *= 1;

 

then check the width

 

console.log(image.width);  // shows -511

 

It shows a negative width! Pretty sure that is incorrect behavior...

 

 

That's just how Phaser handles sprite rendering.  It basically translates to stretching the width out into negative coordinates based on your sprite being (0,0).  A positive width would be stretching out on the X axis into positive numbers.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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