Skip to content

Instantly share code, notes, and snippets.

@TomK32
Created November 12, 2012 16:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TomK32/4060496 to your computer and use it in GitHub Desktop.
Save TomK32/4060496 to your computer and use it in GitHub Desktop.
control maps in LÖVE2D
-- small improvement from http://tannerrogalsky.com/blog/2012/04/06/control-maps-in-love2d/
-- this version has a cleaner control_map by calling m
class "GameController" {
moveUp = function(self)
end,
control_map = {
keyboard = {
on_press = {
up = "moveUp"
}
}
}
}
game_controller = GameController()
function love.keypressed(key, unicode)
local action = game_controller.control_map.keyboard.on_press[key]
if action then
if type(action) == "function" then action(game_controller) end
if type(game_controller[action]) == 'function' then game_controller[action](game_controller) end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment