The next step in our journey is to add input handling. We have to create a file called input_manager.lua
; it will be in charge of listening to input events and will be queried by our game when needed. We will create it so that it will be usable with both mouse devices and touchscreens.
Note
Generally speaking, all hosts are supposed to implement their own input schema. We won't see this in detail in this book, but so you understand where this comes from, take a look at the hosts that are shipped with Moai SDK.
Search for all the references to the AKUReserveInputDevice*
and AKUSetInputDevice*
method calls in moai-sdk/hosts/src/GlutHost.cpp
.
We'll now inspect only the most important methods; please take a look at the full code in order to understand how everything fits together.
function InputManager:initialize () if MOAIInputMgr.device.pointer then local pointerCallback = function ( x, y ) previousX, previousY = pointerX, pointerY pointerX, pointerY = x, y if touchCallbackFunc...