Shake Event On Android

Hi guys,

We just recently launched  PUK (pukgame.com) and we’re getting quite a few complaints that the shake event is not triggering.

While I can do a shake on my android device, it does seem to be much less sensitive than iOS.

Does anyone know:

  1. Can we increase the shake sensitivity?

  2. Could we use the normal accelerometer to listen for a ‘large’ movement, rather than using ‘shake’?

Thanks!

Hi @roballison182,

This is an interesting question. In our documentation for “event.isShake”, it states “When the user shakes the device, this value is true. What constitutes a shake is dependent on the OS/device.” So, it really depends on the device (and it might vary not only from iOS to Android, but likely from Android device to Android device).

But, I think it’s worth testing out the accelerometer as a method to sense smaller movements. I imagine it would just need to sense that a sudden move happened between two game cycles. Have you used the accelerometer before, and do you have the code samples you need?

The sample project is in your local application folder: Corona SDK > SampleCode > Hardware > Accelerometer1

And, of course, the API documentation:

http://docs.coronalabs.com/api/event/accelerometer/index.html

Best regards,

Brent

I don’t think there are any shake adjustments. It is what it is.

Shake events are based on accelerometer readings.  Increasing the accelerometer sample interval will increase the shake sensitivity.  By default, this interval is 10 Hz, which is 10 reading per second.  I suggest that you increase it to 60 Hz as follows…

system.setAccelerometerInterval(60)

I suggest 60 Hz because it doesn’t make much sense to set it to a frequency higher than your frame rate, which for games is normally set to 60 FPS.  Otherwise you’ll be receiving more accelerometer events than rendering “enterFrame” events.

Anyways, I hope this helps.

Thanks for the answers guys! I really appreciate it! I will give this a go.

Your suggestion worked a treat, thanks again!

Hi @roballison182,

This is an interesting question. In our documentation for “event.isShake”, it states “When the user shakes the device, this value is true. What constitutes a shake is dependent on the OS/device.” So, it really depends on the device (and it might vary not only from iOS to Android, but likely from Android device to Android device).

But, I think it’s worth testing out the accelerometer as a method to sense smaller movements. I imagine it would just need to sense that a sudden move happened between two game cycles. Have you used the accelerometer before, and do you have the code samples you need?

The sample project is in your local application folder: Corona SDK > SampleCode > Hardware > Accelerometer1

And, of course, the API documentation:

http://docs.coronalabs.com/api/event/accelerometer/index.html

Best regards,

Brent

I don’t think there are any shake adjustments. It is what it is.

Shake events are based on accelerometer readings.  Increasing the accelerometer sample interval will increase the shake sensitivity.  By default, this interval is 10 Hz, which is 10 reading per second.  I suggest that you increase it to 60 Hz as follows…

system.setAccelerometerInterval(60)

I suggest 60 Hz because it doesn’t make much sense to set it to a frequency higher than your frame rate, which for games is normally set to 60 FPS.  Otherwise you’ll be receiving more accelerometer events than rendering “enterFrame” events.

Anyways, I hope this helps.

Thanks for the answers guys! I really appreciate it! I will give this a go.

Your suggestion worked a treat, thanks again!