How to detect and respond to a shake event in your CoronaSDK application.
This very simple (and as a result, short) example will show you how to detect a shake event in your app.
local function onShake (event)
if event.isShake then
print "Device was shaken"
This is of course more basic than many of my other tutorials but nonetheless I feel it is a useful addition to the Techority library
As you can see we are using a Runtime listener tied to the accelerometer (which is of course how we detect any movement of the device, including a shake event) and then printing a statement.
To test this in the Corona simulator you can press CMD+up and to test on device make sure your device is hooked up to a computer so you can view the Xcode console. Alternatively rather than using a print statement you could make an object appear on the screen, show some text, etc.
This will work on both iOS and Android.