Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to mirror a sprite in PIXI.js

I need to flip a sprite by its bottom line. I know theres a way to flip it by a scale property. But that would be only a flip my its center. Searching the Pixi.js documentation wasn't helpful either.

like image 943
xetra11 Avatar asked Feb 05 '23 21:02

xetra11


1 Answers

I have no experience with Pixi, but from what I've read, you have to set the anchor property of your sprite to the bottom of the sprite, then scale by -1. Something like this; please note I didn't test it.

mySprite.anchor.y = 1;     /* 0 = top, 0.5 = center, 1 = bottom */
mySprite.scale.y *= -1;    /* flip vertically */
like image 160
Ruud Helderman Avatar answered Feb 27 '23 22:02

Ruud Helderman