Game Development Reference
In-Depth Information
Handling Input
Since Moai can generate executables from a single source for mobile devices, desktops, and web
browsers, it has a very highly involved input system. This includes the keyboard, mouse, and touch.
Input is encapsulated in the MOAIInputMgr class; this depends on a callback function to handle an
input event.
Keyboard Events
While developing, you will test your code on the desktop. For this you will need to capture and test
MOAIInputMgr.device.
object.
if down == true then
print("Key down : ", key)
else
print("Key up : ", key)
end
MOAIInputMgr.device.keyboard is not present; instead, you use the
MOAIKeyboardIOS class and set the listeners for the EVENT_INPUT and the EVENT_RETURN .
function onInput(start, length, text)
print("on input")
print(start, length, text)
print(MOAIKeyboardIOS.getText())
end
function onReturn()
print("on return")
print(MOAIKeyboardIOS.getText())
end
MOAIKeyboardIOS.setListener(MOAIKeyboardIOS.EVENT_INPUT,onInput)
MOAIKeyboardIOS.setListener(MOAIKeyboardIOS.EVENT_RETURN,onReturn)
MOAIKeyboardIOS.showKeyboard ()
Mouse Events
For devices that do not have touch events, Moai offers mouse handlers. In a similar fashion to
keyboard handlers, you need to set a callback on the MOAIInputMgr.device.pointer object. This
captures the mouse movement events.
function onMove(evtX, evtY)
print( "Pointer : ", x, y)
end
 
Search WWH ::




Custom Search