Jump to content

How to flip sprite?


Go to solution Solved by meanderingleaf,

Recommended Posts

  • Solution

Setting its scale to negative and positive has worked for me. Note that if you want to have it flip in a normal way, you need to set it's x-anchor to the middle first

 sprite.anchor.setTo(.5, 1); //so it flips around its middle sprite.scale.x = 1; //facing default direction sprite.scale.x = -1; //flipped
Link to post
Share on other sites
  • 3 years later...

Hi

after using the solution 

//After creating a new sprite
this.player.anchor.set(0.5);
// inside a class that extends from the sprite
this.scale.x = this.direction;
// direction is either 1 or -1

I have to problem, that the physical body(using P2) is not aligned correctly with the sprite anymore.

Any ideas?

1.png

2.png

Link to post
Share on other sites
On 6/20/2017 at 0:14 PM, faebeee said:

Hi

after using the solution 


//After creating a new sprite
this.player.anchor.set(0.5);

// inside a class that extends from the sprite
this.scale.x = this.direction;
// direction is either 1 or -1

I have to problem, that the physical body(using P2) is not aligned correctly with the sprite anymore.

Any ideas?

I'm not sure if this is part of the issue, but when setting the anchor, try this instead...

this.player.anchor.setTo(0.5, 1);

 

Link to post
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...
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...