Detecting Landscape Orientation Flip on Android

Hi all,

I have a puzzle in my game that uses the accelerometer to affect gravity.  Problem is on Android, if the user flips the orientation from landscapeRight to landscapeLeft, the gravity in the puzzle applies force upwards instead of down.  The “orientation” event doesn’t fire when the screen flips like this so I can’t change the direction of gravity.  This is expected on Android as per: https://docs.coronalabs.com/api/event/orientation/index.html

Is there any way I can detect this flip?  Will be such overkill to lock orientation for my entire game just because of this one small limitation.

Cheers.

most games are locked in orientation and this is normal. if you want to support both landscape and portrait then you will need to refer to the docs regarding orientation changes.

the link you posted literally tells you how to detect this.

Thx for replying.  My game only supports landscape so guess I’ll just lock it.  It’s nice to have freedom of landscape orientation especially when headphones or charge cables are plugged in.

Thinking about it…

You should probably use https://docs.coronalabs.com/api/event/accelerometer/index.html and check for changes in either xGravity, yGravity or zGravity. 

One of those values should flip from +ve to -ve if you rotate the phone 180 degrees?

most games are locked in orientation and this is normal. if you want to support both landscape and portrait then you will need to refer to the docs regarding orientation changes.

the link you posted literally tells you how to detect this.

Thx for replying.  My game only supports landscape so guess I’ll just lock it.  It’s nice to have freedom of landscape orientation especially when headphones or charge cables are plugged in.

Thinking about it…

You should probably use https://docs.coronalabs.com/api/event/accelerometer/index.html and check for changes in either xGravity, yGravity or zGravity. 

One of those values should flip from +ve to -ve if you rotate the phone 180 degrees?