Android orientation

Afternoon, 

I have a question about orientation, actually probably more then one.

First question: How can you tell what orientation the device is currently at?

Second Question: I want my stages to “disassemble” and “reassemble” whenever a person changes their orientation. So right now I have an orientation listener (code to come) that gets rid of everything on the stage and calls the function to display it all again. However, this doesn’t seem to work (pretty sure I have some infinite recursion going on but I am unable to figure out why)

[lua]

local function levelFour()

    local fourGroup = display.newGroup()

    – some code that displays what I want to display

    local function change(event)

            fourGroup:removeSelf() 

            fourGroup = nil

            levelFour()

    end

    

    Runtime:addEventListener(“orientation”, change)

end

[/lua]

What am I missing here? The stages themselves are fairly simple ( they are pretty much just buttons and a few other things ) so the amount of time it takes to build the stage is generally < 1 second on a device, so I figured destroying the stage and rebuilding it would be simpler than just moving everything. 

Looking at your code, you add next and next ‘change’ listener when you execute levelFour. So on first orientation change function change() is executed once. On next change it’s called twice and next 4x, 8x, 16x (on each orientation change it doubles)

#1 you can use listener as you did. FirSt oeientation will be orientation set in config.lua or build.settings.
Inside listener event.type will return to what orientation changed.

#2 on each levelFour() you add more and more change() to be executed when orientation change is detected (as written above)

Should be
[lua]
local function levelFour ()

end

local function change(event)

end

Runtime:addEventListener (‘orientation’, change)

– remember to remove this runtime listener when you exit level
– because it will try to call change() each time your orientation
– changes despite of what code is executed
[/lua]

Looking at your code, you add next and next ‘change’ listener when you execute levelFour. So on first orientation change function change() is executed once. On next change it’s called twice and next 4x, 8x, 16x (on each orientation change it doubles)

#1 you can use listener as you did. FirSt oeientation will be orientation set in config.lua or build.settings.
Inside listener event.type will return to what orientation changed.

#2 on each levelFour() you add more and more change() to be executed when orientation change is detected (as written above)

Should be
[lua]
local function levelFour ()

end

local function change(event)

end

Runtime:addEventListener (‘orientation’, change)

– remember to remove this runtime listener when you exit level
– because it will try to call change() each time your orientation
– changes despite of what code is executed
[/lua]