How to reverse a picture from right to left??

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
Bernard51
Prole
Posts: 46
Joined: Fri Jan 20, 2017 5:51 pm

How to reverse a picture from right to left??

Post 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
St. Cosmo
Prole
Posts: 8
Joined: Wed Nov 07, 2018 6:53 pm

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

Post 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
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

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

Post 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
Bernard51
Prole
Posts: 46
Joined: Fri Jan 20, 2017 5:51 pm

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

Post by Bernard51 »

Thank you
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests