Monday, 28 October 2013

How to check whether the testing device supports vibration facility in corona SDK

You may need to implement vibration feedbacks in many of your applications, especially in games and during warning alerts. In this chapter, you will learn about the a boolean key event to check whether your device supports vibrational feedback for your corona app. If this key event returns true,then your device will support vibration feedbacks, and if it returns false, then your device won't.



--  Function to trigger key event --
local function onKeyEvent( event )
    -- Vibrate the gamepad if its 'A' button was pressed.
    if (event.keyName == "button_A") and (event.phase == "down") then
        if event.device and event.device.canVibrate then
            event.device:vibrate()
        end
    end
end

Runtime:addEventListener( "key", onKeyEvent )



Note: This will not work with Android versions <= 4.0.

No comments:

Post a Comment