Orientation

Features demonstrated:

How to handle orientation changes manually, by rotating elements within Corona.
Note that the Corona stage remains fixed in place, and only the text rotates in this case.

Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
local label = display.newText( "portrait", 0, 0, nil, 30 )
label:setTextColor( 255,255,255 )
label.x = display.contentWidth/2
label.y = display.contentHeight/2
 
local function onOrientationChange( event )
        -- change text to reflect current orientation
        label.text = event.type
        local direction = event.type
 
        -- rotate text so it remains upright
        local newAngle = label.rotation - event.delta
        transition.to( label, { time=150, rotation=newAngle } )
end
 
Runtime:addEventListener( "orientation", onOrientationChange )