O'Reilly logo

Developing Mobile Games with Moai SDK by Francisco Tufro

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Keyboard input

We'll have to change a couple of things in order to start using the keyboard:

  1. First of all, we need to remove our processInput method and the call to on Game:start in game.lua.
  2. 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.

  3. 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required