Game Development Reference
In-Depth Information
The best way to set up handlers is to ensure the existence of a device before the callback is set.
Here's how to check for the existence of a device:
if MOAIInputMgr.device.touch then
MOAIInputMgr.device.touch:setCallback(onTouch)
end
Note Setting a callback can cause an error if the device in question is not supported. It is best to
check for the presence of the device before setting the callback. This is applicable to devices involving
touch, mouse pointers, keyboards, and even GPS and accelerometers.
Sound
While some frameworks have an elaborate and complex audio functionality, Moai has a very simple
function available in the MOAIUntzSound class. However, before you can use the audio functions, you
need to initialize the MOAIUntzSystem , like so:
MOAIUntzSystem.initialize ()
sound = MOAIUntzSound.new ()
sound:load ( 'mono16.wav' )
sound:setVolume ( 1 )
sound:setLooping ( false )
sound:play ()
Displaying a Dialog
Moai allows you to display messages to the user and even get input from the user in the form of a yes/
no/cancel-type dialog. In such a scenario, you can use the showDialog function from the MOAIDialogIOS
class. Here's an example:
function onDialogDismiss(code)
print("Dialog Dismissed")
if (code==MOAIDialog.DIALOG_RESULT_POSITIVE) then
print("Clicked Yes")
elseif (code==MOAIDialog.DIALOG_RESULT_NEUTRAL) then
print("Clicked Maybe")
elseif (code==MOAIDialog.DIALOG_RESULT_NEGATIVE) then
print("Clicked No")
elseif (code==MOAIDialog.DIALOG_RESULT_CANCEL) then
print("Clicked Cancel")
else then
print("Clicked Unknown")
end
end
MOAIDialogIOS.showDialog("Sample Dialog", "", "Yes", "Maybe", "No", true, onDialogDismiss)
 
Search WWH ::




Custom Search