Page 1 of 1

How to reverse a picture from right to left??

Posted: Fri Feb 08, 2019 2:34 pm
by Bernard51
Hello
I have this picture:
https://www.zupimages.net/up/19/06/xf8g.png

if I press the right arrow key the gun points to the right
But if I press the left arrow key, I would like the gun to point to the left I want my image to reverse
Should there be two pictures for that or is it possible with an image? thank you

Re: How to reverse a picture from right to left??

Posted: Fri Feb 08, 2019 3:03 pm
by St. Cosmo
When you look at your draw call, you need to do

love.graphics.draw( drawable, x, y, r, sx * -1, sy, ox, oy, kx, ky )

basically, the scale factor on the x axis also flips the image horizontally.
Same works vertically with the scale Y factor

Re: How to reverse a picture from right to left??

Posted: Fri Feb 08, 2019 3:08 pm
by grump
You also need to adjust the X offset to keep it at its position when you mirror it.

If you only want to flip the cannon part, you can create two quads: one that covers the upper part with the cannon, and another one for the rest of the image. Then draw the first quad like described above, and the second one normally, with an Y offset.

Like this (needs adjustment, all coordinates are guesses):

Code: Select all

local lg = love.graphics
local tank = lg.newImage('tank.png')
local cannonHeight = 20
local upper = lg.newQuad(0, 0, tank:getWidth(), cannonHeight, tank:getDimensions())
local lower = lg.newQuad(0, cannonHeight, tank:getWidth(), tank:getHeight() - cannonHeight, tank:getDimensions())

function love.draw()
	lg.draw(tank, upper, 0, 0, 0, -1, 1, tank:getWidth(), 0)
	lg.draw(tank, lower, 0, cannonHeight)
end

Re: How to reverse a picture from right to left??

Posted: Fri Feb 08, 2019 4:32 pm
by Bernard51
Thank you