Game Development Reference
In-Depth Information
MOAIInputMgr.device.pointer:setCallback(onMove)
If we want to capture when the mouse buttons are clicked, you need to set callback functions for the
mouse buttons, like mouseLeft , mouseRight , and mouseCenter .
function onMouseL(down)
print("The Left Mouse button down is ", down)
end
function onMouseR(down)
print("The Right Mouse button down is ", down)
end
function onMouseC(down)
print("The Center Mouse button down is ", down)
end
MOAIInputMgr.device.mouseLeft:setCallback(onMouseL)
MOAIInputMgr.device.mouseRight:setCallback(onMouseL)
MOAIInputMgr.device.mouseCenter:setCallback(onMouseL)
In some cases you might not want to set callback functions on the mouse buttons. In such cases,
you can query for them using the isUp and isDown functions. You can set a callback on the pointer,
and in the callback also check for the button states.
function handleMouse( x, y )
if MOAIInputMgr.device.mouseLeft:isUp() then
print("Left button clicked at : ", x, y)
end
end
MOAIInputMgr.device.pointer:setCallback(handleMouse)
You might have noticed the pull-to-refresh functionality in quite a few applications. With iOS 6, the
mail application has a pull-to-refresh; when you pull, the circle elongates like slime, pulling down
from the larger blob on the top. We can quickly re-create the same effect with Moai and the mouse.
In this example, the blob reacts to the mouse pointer moving down as you move the mouse in the
window. The effect is shown in Figure 10-10 .
Search WWH ::




Custom Search