Page 1 of 1

[Solved]Making a character switch images when pressing a button to move

Posted: Wed Sep 30, 2020 8:34 pm
by TurtlyDz
In the game I am trying to make, I have two character images one of the character looking left and one looking right. I already have the image that looks right walking around but I want to be able to switch the image when I press 'a' to go left. If you need me to attach the game files just tell me. I am really new to Lua and LOVE and I would appreciate your help. Thank you.

Re: Making a character switch images when pressing a button to move

Posted: Wed Sep 30, 2020 11:53 pm
by sphyrth
TurtlyDz wrote: Wed Sep 30, 2020 8:34 pm If you need me to attach the game files just tell me.
Please do. There are several ways of solving your problem.

Re: Making a character switch images when pressing a button to move

Posted: Wed Sep 30, 2020 11:59 pm
by Xugro
I attached a small example. But as sphyrth sad: This is just one of many solutions.

The basic idea is mostly the same: Save the direction the character is looking in some variable and read it when you draw the image.

Re: Making a character switch images when pressing a button to move

Posted: Thu Oct 01, 2020 12:08 am
by TurtlyDz
I have just realized how to do it. I was thinking that I had to change images when I pressed a button but I found a function that just flips a character over the y axis:
if self.direction == 'right' then
scaleX = 1
else
scaleX = -1
end
love.graphics.draw(player_right, math.floor(player_rightX), math.floor(player_rightY), 0, scaleX, 1, self.width / 2, self.height / 2)

Thank you for trying to help! Honestly I thought it would;d take a while for someone to respond. Thank you again.