How to mirror/flip sprite?

Status
Not open for further replies.

SilverDash

Veteran
Veteran
Joined
Oct 11, 2015
Messages
423
Reaction score
170
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
489
Reaction score
190
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
423
Reaction score
170
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
243
Reaction score
255
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
489
Reaction score
190
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
6,486
Reaction score
4,404
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.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Playtesting for Battle Castle is done, demo time for me was roughly 6 hours and 20 minutes. I'm going to pass it on to a few friends first, and after getting some feedback will be posting an official topic.
There's another Humble Bundle available now for RPG developer assets, this time focused somewhat more towards pixel art style games.
Ive got a long lost half uncle. Thats real cool.
I forget what is bumping rule in this forum. Is anyone know? Thank you.
BCj
Ew, why does my blogpost on the rpgmaker.net site look like a garbled mess? Are html codes disabled or something?

Forum statistics

Threads
97,907
Messages
947,772
Members
129,148
Latest member
lemminace
Top