How to mirror/flip sprite?

Status
Not open for further replies.

SilverDash

Veteran
Veteran
Joined
Oct 11, 2015
Messages
426
Reaction score
173
First Language
Dutch
Primarily Uses
RMMV
JavaScript:
this.sprite = new Sprite(bmp);
this.addChild(this.sprite);
this.sprite.scale.x = -1; // <<< this line causes the sprite to become invisible. Why? Why won't it mirror?

JavaScript:
this.sprite.scale.set(-1,1); // also doesn't work. No error either, just turns invisible.
this.sprite.scale.set(2,1); // Works, but it's a positive value so it isn't mirrored...
this.sprite.scale.x = 2; // Works, but it's a positive value so it isn't mirrored...


Also, are we supposed to add a loadlistener to each sprite we use in case the bitmap hasn't yet been loaded?
 
Last edited:

pasunna

Veteran
Veteran
Joined
Feb 3, 2019
Messages
531
Reaction score
278
First Language
thai
Primarily Uses
RMMV
don't know I edit some character code
this.scale.x *= -1;
and it work
 

SilverDash

Veteran
Veteran
Joined
Oct 11, 2015
Messages
426
Reaction score
173
First Language
Dutch
Primarily Uses
RMMV
Okay, the bug was really silly... When you flip a sprite the effective render location (of course!) also changes. In my case it went off-screen... So the code was correct I just had to move it ^^.
 

Raizen

Veteran
Veteran
Joined
Oct 24, 2012
Messages
382
Reaction score
665
First Language
Portuguese
Primarily Uses
RMMV
Ah, just one thing you can use anchor to set the rotation axis, so if you set it like .
this.sprite.anchor.x = 0.5;
this.sprite.anchor.y = 0.5;

When you mirror it, you won't need to move it.
 

pasunna

Veteran
Veteran
Joined
Feb 3, 2019
Messages
531
Reaction score
278
First Language
thai
Primarily Uses
RMMV
Ah, just one thing you can use anchor to set the rotation axis, so if you set it like .
this.sprite.anchor.x = 0.5;
this.sprite.anchor.y = 0.5;

When you mirror it, you won't need to move it.
but I always like top left because I don’t like to think again about the half coordinate xD
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
8,034
Reaction score
5,335
First Language
Dutch
Primarily Uses
RMXP

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

Latest Threads

Latest Profile Posts

Looking back at some sketches, and game design documents on my PC dated summer of 2015. I started development with the release of MZ, but in 2015, I felt a strong desire to make a game out of the blue. I remember feeling sad for no apparent reason, and all these ideas rushed into my head. Now that I think about it, since that day, everything has become easier to do on my PC . . . it’s very creepy.
Everything's going to be alright! We're all in this together. <3
Aaaaannd published my game's tech demo. :D

Feel free to download and play it. And give feedback!
Hey everyone, we know that the edit bar is missing. We're working on it. You can talk about it in the announcement here: https://forums.rpgmakerweb.com/index.php?threads/forum-errors-missing-edit-bar-etc.132715/
So, explain why we can no longer use BBC code or smilies in our posts? This sparks much sadness...

Forum statistics

Threads
107,794
Messages
1,032,263
Members
139,941
Latest member
Finley
Top