[Solved]Making a character switch images when pressing a button to move
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
[Solved]Making a character switch images when pressing a button to move
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.
Last edited by TurtlyDz on Thu Oct 01, 2020 12:09 am, edited 1 time in total.
Re: Making a character switch images when pressing a button to move
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.
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.
- Attachments
-
- left_and_right.love
- (82.28 KiB) Downloaded 145 times
Re: Making a character switch images when pressing a button to move
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.
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.
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 1 guest