Jump to content

How to flip sprite?


Dang_Khoa
 Share

Recommended Posts

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 comment
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 comment
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 comment
Share on other sites

On 6/21/2017 at 7:25 PM, ncil said:

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);

 

Found the problem. I trimmed my spritesheet in texturepacker. Now works perfectly with setTo(0.5, 0.5)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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