I feel like this should be rather simple and I'm over-complicating it, but what's the easiest way to flip an image in love2d? Such as a platformer. The player is facing a right direction, then when you press the left key, his draw image gets flipped left. Such as updating in love.update.
thanks!
Love2d Mirror/Flip Drawn Image.
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- dreadkillz
- Party member
- Posts: 223
- Joined: Sun Mar 04, 2012 2:04 pm
- Location: USA
Re: Love2d Mirror/Flip Drawn Image.
Use a negative scale for the image you want to draw w/ love.graphics.draw
Re: Love2d Mirror/Flip Drawn Image.
How exactly would I set this up?
(In love.update)
(In love.update)
Code: Select all
function love.load()
love.graphics.setBackgroundColor(100, 149, 237)
x = 50
y = 50
speed = 100
playerIdle = love.graphics.newImage("/player/player_idle.png")
playerLeft = love.graphics.newImage("/player/player_walk_2.png")
playerRight = love.graphics.newImage("/player/player_walk_2.png")
playerDown = love.graphics.newImage("/player/player_walk_2.png")
playerUp= love.graphics.newImage("/player/player_walk_2.png")
player = playerIdle -- the player starts looking to the left
end
function love.update(dt)
if love.keyboard.isDown("d") then
x = x + (speed * dt)
player = playerRight
elseif love.keyboard.isDown("a") then
x = x - (speed * dt)
player = playerLeft
-- Here
player = love.graphics.scale(-5, -5 )
--This Just breaks it! D:
else
player = playerIdle
end
if love.keyboard.isDown("s") then
y = y + (speed * dt)
player = playerDown
elseif love.keyboard.isDown("w") then
y = y - (speed * dt)
player = playerUp
end
end
function love.draw()
love.graphics.draw(player, x, y)
end
Re: Love2d Mirror/Flip Drawn Image.
Code: Select all
-- normal
love.graphics.draw(image, x, y, rotation, 1, 1)
-- mirror
love.graphics.draw(image, x, y, rotation, -1, 1)
-- flipped
love.graphics.draw(image, x, y, rotation, 1, -1)
Re: Love2d Mirror/Flip Drawn Image.
Thanks so much! You're awesome
Re: Love2d Mirror/Flip Drawn Image.
Sorry but one last question, why is it that when he rotates he jumps a bit? like, when he scales right he goes like a whole bunch of pixels in that direction? How can I fix this?
More as, how do I chose where I want him to flip from?
More as, how do I chose where I want him to flip from?
- dreadkillz
- Party member
- Posts: 223
- Joined: Sun Mar 04, 2012 2:04 pm
- Location: USA
Re: Love2d Mirror/Flip Drawn Image.
When you flip or rotate an image, it does it about its pivotal point, which is the top left corner of the image. You need to offset your image so that its in the same location as its original state.
You should do this when you flip your image:
You should do this when you flip your image:
Code: Select all
function love.load ()
...
width = playerLeft:getWidth()
...
end
function love.draw()
...
-- flip left
love.graphics.draw( image, x, y, 0, -1, 1, width, 0)
...
end
Re: Love2d Mirror/Flip Drawn Image.
I can't thank you guys enough you've both been a huge help
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 8 guests