We'll have to change a couple of things in order to start using the keyboard:
First of all, we need to remove our
processInput
method and the call to onGame:start
ingame.lua
.Then we need to create a method that will be in charge of managing the key input from
InputManager
.function Game:keyPressed ( key, down ) if key == 'right' then Character:moveRight(down)end if key == 'left' then Character:moveLeft(down)end if key == 'up' then Character:jump(down)end end
This method maps some key presses with the methods we created on
Character
. This should be enough to handle the movement of our character.Now, we'll have to remove all the code (except the module definition) from
input_manager.lua
and rewrite it using the following code:function InputManager:initialize () function onKeyboardEvent ( key, down ) if key == 119 then key = 'up' end if key == 97 then key = 'left' end if key == 100 then key = 'right' end Game:keyPressed(key, down...