Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / How to flip an Image?
- - By darkhog Date 2014-01-08 06:49
How can I flip an Image? I don't want to double my image count (both directions of my characters are same except being flipped).
Parent - - By jahmaican Date 2014-01-08 08:44
You can achieve it by using negative scaling factors, e.g.: @character.draw(x_pos, y_pos, z_order, -1.0, 1.0) will draw your character unscaled (technically scaled by 1.0 factor) and flipped horizontally.

Notice the image will be flipped relative to right edge, not the center, so you might want to add an offset to your x_pos.
Parent - - By darkhog Date 2014-01-08 13:58
So to flip relative to center do I have to add Image.width/2 or subtract it?
Parent - - By lol_o2 Date 2014-01-08 14:26
You have to add Image.width, because it's like turning a page in book (couldn't find better explanation :) But this is when you use normal Image.draw.
When you use Image.draw_rot then image doesn't change position (if center is default 0.5), but then it draws centered in given position. If you want to place there the top-left corner, you have to add Image.width/2 and Image.height/2.
Parent - By darkhog Date 2014-01-08 20:52
Thanks. Figured it on my own, just forgot to update post. Also thanks for tip about draw_rot. Won't use it in my main sprite class, but probably will in particle class that will be inheriting from sprite.
Up Topic Gosu / Gosu Exchange / How to flip an Image?

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill