Step 2: Camera & Events


The first thing that you'll want to do is to capture the users input so they can interact with your game.
The pushFPSCamera function uses EventMaps to capture user input and in turn move the Camera around.
You'll notice that the first thing it does is to create a new map by calling fpskeymap = 
Then it assigns functions to keys using the setEvent method on the new keymap.
A key name is prepended by the state that you want to respond to. 
Possible states incule keyPressed, keyReleased and keyDown (keyDown fires every 10ms).
Finally once the map is build, it's pushed onto the EventHandler stack via the push function.
When a key is pressed, the top of the EventHandler stack is consulted, if the key is handled by that map it is, otherwise it digs deeper down the

( Wild Pockets Manual : More details about events. )

Camera Functions

In addition to eventMaps, you'll notice that the Camera is manipulated here.
The default Camera comes with a bunch of useful functions (though if you'd like more detailed control, consult our manual).
The Camera.setEye method defines the point in space where the Camera is located.
The Camera.setFocus method fines the point in space where the Camera is looking.
In addition the Camera.moveLeft, moveUp, etc functions manipulate the Cameras eye and focus.
The Camera.beginRotate function pushes a new EventMap onto the stack that tracks the users mouse and rotates the Camera accordingly.
To stop the rotation Camera.endRotate pops that EventMap.
Now you should be able to test your pocket and find that you can look around with the right mouse button and move with the arrow keys.

( Wild Pockets Manual : More details about the camera. )

    -- onSceneStart is called first to start the game
function onSceneStart()
-- Output to the debug console
print ("Hello World")

        -- Add camera controls
        -- Set initial camera position
-- This function will add an eventMap that control the camera
function pushFPSCamera()
    -- Create a new event map
    fpskeymap = EventMap:new()
    -- Add callback functions to specific input events
    fpskeymap:setEvent("scrollWheel",function(d) Camera.zoomIn(d/200) end)
    fpskeymap:setEvent("keyPress-rightMouse",function() Camera.beginRotate(150) end)
    fpskeymap:setEvent("keyRelease-rightMouse",function() Camera.endRotate() end)
    fpskeymap:setEvent("keyDown-left",function() Camera.moveLeft(0.1) end)
    fpskeymap:setEvent("keyDown-right",function() Camera.moveRight(0.1) end)
    fpskeymap:setEvent("keyDown-up",function() if EventHandler.keyIsDown("shift") then  Camera.moveUp(0.1) else Camera.moveForward(0.1) end end)
    fpskeymap:setEvent("keyDown-down",function() if EventHandler.keyIsDown("shift") then  Camera.moveDown(0.1) else Camera.moveBackward(0.1) end end)
    -- Add the eventmap to the stack