Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Detecting Landscape Orientation Flip on Android
Started by ddubya82 Dec 22 2018 07:44 AM

3 replies to this topic
android orientation flip event landscape
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

ddubya82

[GLOBAL: userInfoPane.html]
ddubya82
  • Enthusiast

  • 41 posts
  • Corona SDK

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.



[TOPIC: post.html]
#2

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 1,967 posts
  • Corona SDK

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.



[TOPIC: post.html]
#3

ddubya82

[GLOBAL: userInfoPane.html]
ddubya82
  • Enthusiast

  • 41 posts
  • Corona SDK

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.



[TOPIC: post.html]
#4

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 1,967 posts
  • Corona SDK

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?




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: android, orientation, flip, event, landscape