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
How to reverse a picture from right to left??
Re: How to reverse a picture from right to left??
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
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??
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):
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
Who is online
Users browsing this forum: Bing [Bot] and 3 guests