Orientation Events vs Accelerometer

I'm trying to decide whether to wait and see if I should use orientation events, or just use the accelerometer for Android. I want my graphics to transition.to a new rotation when I turn the screen.

Orientation Events

  • Received on Windows Simulator whether I have a build.settings file or not.
  • Only received on phone if I support different orientations in build.settings file. But I can't transition as it automatically rotates the entire stage/display for me
  • Maybe orientation events will be included in a later build for Android phones without needing a build.settings file?

Accelerometer

  • Even if I set the setAccelerometerInterval(10), I still worry this may be more battery intensive than I desire, or needed (especially for a game/app that doesn't use the accelerometer)
  • Works on phone, but I have nothing to emulate accelerometer on Windows Simulator (and that's OK for now)

I hope someone out there understands my dilemma. I'm just looking for comments on the best solutions for a transitioning rotation! Thanks!

PS - Here is the code I'm using currently for my accelerometer rotation code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
myRotation = 0
 
function onAcc(event)
        local rotation
        if math.abs(event.zGravity) > 0.95 then
                rotation = 0 --flat phone
        elseif math.abs(event.xGravity) > math.abs(event.yGravity) then
                if event.xGravity > 0.5 then
                        rotation = -90
                elseif event.xGravity < -0.5 then
                        rotation = 90
                end
        else
                if event.yGravity > 0.5 then
                        rotation = 180
                elseif event.yGravity < -0.5 then
                        rotation = 0
                end
        end
        if rotation ~= myRotation then
                myRotation = rotation
                --transition code
        end
end
 
Runtime:addEventListener("accelerometer", onAcc)
system.setAccelerometerInterval(10)
views:789 update:2011/10/10 15:46:04
corona forums © 2003-2011