Skip to content

Instantly share code, notes, and snippets.

@erloncabral
Created August 1, 2018 12:08
Show Gist options
  • Save erloncabral/b5a6ca830ffa02ff51234757a2f4b341 to your computer and use it in GitHub Desktop.
Save erloncabral/b5a6ca830ffa02ff51234757a2f4b341 to your computer and use it in GitHub Desktop.
love 2d keyboard directions
local x_input = 0
local y_input = 0
local line_width = 32
function love.update(dt)
x_input = (love.keyboard.isDown("right") and 1 or 0) - (love.keyboard.isDown("left") and 1 or 0)
y_input = (love.keyboard.isDown("down") and 1 or 0) - (love.keyboard.isDown("up") and 1 or 0)
end
function love.draw()
love.graphics.line(line_width, line_width, (line_width + x_input * line_width), (line_width + y_input * line_width))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment