I am making a game called "Insomnia". It's a 2d horror game. I'm having a bit trouble with player movement, I have the movement part nailed down but when I move the opposite direction that the character is facing, it goes in that direction, but when I left go of "A, left movement" the characters texture will go back to the right, could anyone tell me how to fix this? I have two separate textures for both the character facing left & right.
Example:
Pic #1: Walking whilst holding "D" Pic #2: Walking whilst holding "A" Pic #3: When I stop holding "A"
local moveKey
local playerImages = {}
playerImages["idle"] = love.graphics.newImage("textures/character_idle.png")
playerImages["left"] = love.graphics.newImage("textures/character_left.png")
playerImages["right"] = love.graphics.newImage("textures/character_right.png")
function love.keypressed(key)
if key == "left" or key == "right" then moveKey = key end
end
function love.keyreleased(key)
if key == "left" or key == "right" then moveKey = nil end
if key == "left" and love.keyboard.isDown("right") then moveKey = "right" end
if key == "right" and love.keyboard.isDown("left") then moveKey = "left" end
end
function player_draw()
love.graphics.setColor(255,255,255)
love.graphics.draw(playerImages[moveKey] or playerImages["idle"], player.x, player.y)
end
Wouldn't it make more sense to do that in keypressed rather than released?
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.