I have a game that uses the accelerometer to move a character back and forth along the x axis in landscape mode. When I rotate the device the game flips fine but my accelerometer driven character moves in reverse-so if you tilt right he goes left. I am using the build settings to flip the app. I am guessing I need to somehow detect when the device flips and change accelerometer functions but I am not sure how to do this. [import]uid: 39370 topic_id: 22671 reply_id: 322671[/import]
Check out this API: http://developer.anscamobile.com/reference/index/systemorientation
There’s also a native orientation example in SampleCode that shows handling rotation. [import]uid: 52491 topic_id: 22671 reply_id: 90415[/import]
Thanks Peach for the help. I do have one more questions now for anyone who knows. I have a runtime listener checking for orientation changes and adjusting the accelerometer values -this works fine. I have another function shown below that check the systems orientation when the play button is hit-this does not work on iPad only iPhone-if the user had the iPad in landscapeLeft then he or she actually has to tilt the device some and force the runtime listener to pick up the change to make the accelerometer values correct.
[lua]
if system.orientation == “landscapeRight” then
moveFixNum = 1
–the moveFixNum is multiplied by the accelerometer value to adjust for screen orientation
elseif system.orientation == “landscapeLeft” then
moveFixNum = -1
end[/lua]
To get around this I took this function out and just have one runtime listener on the entire app checking for orientation change-this works great on iPhone and iPad. My Question in this–If I never remove that runtime listener but I made sure it is never duplicated is this bad for the system-if the user suspends the app to do something else is this listener still running and hurting battery life or is it suspended as well-I did a test suspending the app and rotating the device then opening the app back up and it worked fine leading me to believe that the listener is still running when the app is suspended [import]uid: 39370 topic_id: 22671 reply_id: 91109[/import]
Actually I just removed the runtime when the system suspends and added it back in when I resume and then tried that code from above in the on resume area and it works there. Not sure why it didn’t work when I had it run when the start button was pressed. I needed the code from above for times when the device was rotated during suspend and them the user started the app again. In this case the runtime listener would not change anything unless the user tilted the device to a limit to have it kick in. [import]uid: 39370 topic_id: 22671 reply_id: 91119[/import]