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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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