Recipes - npryce/codea-controllers GitHub Wiki

How to compose controllers to make various control schemes.

Joystick and Fire Button

maxSpeed = 400 -- Pixels per second
velocity = vec2(0,0) -- Initially not moving

function launchBullet() ...

controller = Prioritised(
    VirtualStick {moved = function(v) velocity = v*maxSpeed end},
    TapAction {pressed = launchBullet})

Dual-Stick Shooter

maxSpeed = 400 -- pixels per second
velocity = vec2(0,0) -- Initially not moving
fireDirection = vec2(0,0) -- Relative to player position. If (0,0) then the player is not firing

controller = Prioritised(
    VirtualStick {moved = function(v) velocity = v*maxSpeed end},
    VirtualStick {moved = function(v) fireDirection = v:normalize() end})