Created
November 12, 2012 16:56
-
-
Save TomK32/4060496 to your computer and use it in GitHub Desktop.
control maps in LÖVE2D
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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