Orientation bug -- show stopping :(

Hello everyone,

My app supports all screen orientations, to handle that, I’ve implemented listeners that handle the “orientation” event.

The bug is: sometimes the orientation event is a “portrait” orientation, but the screen sizes are as if in landscape. I tried the sample code that writes text on the screen with the current orientation and couldn’ reproduce the bug, so I added the code to my app and I could.

images that show the problem ocurring:
normal:

bugged:

Here is the function I used:
the “orientation ~= getOrientation() then
setOrientation()” bit is to prevent useless

[lua]function orientationHandler(e)

label.text = e.type…" - screenSizeX: “…screenSizeX()…” - screenSizeY: "…screenSizeY()
local direction = e.type
label.x = display.contentCenterX
label.y = display.contentCenterY - 100
if orientation ~= getOrientation() then
setOrientation()
for attr,value in pairs(subscribers) do
value:positioning(e)
end
end

label2.text = e.type…" - screenSizeX: “…screenSizeX()…” - screenSizeY: "…screenSizeY()
local direction = e.type
label2.x = display.contentCenterX
label2.y = display.contentCenterY + 100

label:toFront()
label2:toFront()
end
Runtime:addEventListener(“orientation”,orientationHandler)[/lua]
[import]uid: 79152 topic_id: 23588 reply_id: 323588[/import]

other orientations:

[import]uid: 79152 topic_id: 23588 reply_id: 94586[/import]

Is the native orientation sample code working for you?

If not can you please file a bug report with test case we can run and info on Corona build you are using and the like?

Peach :slight_smile: [import]uid: 52491 topic_id: 23588 reply_id: 94701[/import]

the native orientation sample code is working fine…
I’m guessing it has to do with heavy images…
I’ll file the bug :slight_smile: [import]uid: 79152 topic_id: 23588 reply_id: 94910[/import]

I’ve filed the bug under “Device orientation type async w/ device height/width”
Is there a place where I can check the bug status?
[import]uid: 79152 topic_id: 23588 reply_id: 94947[/import]

Hey,

You will see if a daily build comes out in its note the bug numbers it addressed.

You will also likely get an email from whoever the bug was assigned to as they need more info or to update you.

If you need to add additional info yourself you can reply to the email you got after filing the bug and the details will automatically be updated.

Peach :slight_smile: [import]uid: 52491 topic_id: 23588 reply_id: 95040[/import]

are u handling faceup and facedown orientation? i think you are not and that’s why once device go in that orientation you will get this thing.

just a guess.
:slight_smile: [import]uid: 12482 topic_id: 23588 reply_id: 95080[/import]

Just curious, why did you choose the listener-based orientation? I haven’t used that in over a year for anything (it never seemed to work properly, despite being an Ansca-provided example). I just set up my orientations in the “build.settings” file and my resolutions/scaling in “config.lua”. If you do that properly, iOS should handle the remainder on the fly. Perhaps I didn’t understand your specific issue, but in most cases there should be no need for listener-based orientations.

Brent [import]uid: 9747 topic_id: 23588 reply_id: 95083[/import]

hgvyas is right, i bet the bug only appears when your iPad lays flat on the table, right?
i had the same problem, it’s because >a rather annoying and unwanted< “faceUp” orientation is registred, so here’s more or less how I handled the orientation change:

local function onOrientationChange ( event )  
  
  
 if event.type == "faceUp" or event.type == "faceDown" then  
 -- if its face up or down ignore orientation  
 event.type = \_G.PARAMS.lastOrientation  
 end  
  
  
 if event.type ~= myOrientation then  
  
  
 -- update orientation thing  
 myOrientation = event.type  
 \_G.PARAMS.lastOrientation = myOrientation  
  
  
 -- reorder layout in loaded scene  
 local moduleName = director.loadedModule  
 if type(package.loaded[moduleName]) == "table" then  
 if package.loaded [moduleName].onOrientationChange ~= nil then  
 package.loaded [moduleName].onOrientationChange ( event )  
 end  
 end  
  
end  

you will probably notice that

if event.type ~= myOrientation then  

will be redundant if we previously set event.type = _G.PARAMS.lastOrientation,
but actually I also needed to do somewhere else in code a “manual” checkup of the orientation, using timer that looks to accelerometer values:

  
local function checkOrientation ( event )  
  
 local o = system.orientation  
 --print ( "orientation is "..o )  
 if o ~= myOrientation then  
 onOrientationChange ( { type = o } )  
 elseif accel.x then  
 local realOrientation  
 local min, max = .15, .4  
  
 if math.abs ( accel.x ) \< min and accel.y \< -max then  
 -- portrait  
 realOrientation = "portrait"  
 elseif math.abs ( accel.x ) \< min and accel.y \> max then  
 -- portrait upsidedown  
 realOrientation = "portraitUpsideDown"  
 elseif math.abs ( accel.y ) \< min and accel.x \> max then  
 -- landscape button left  
 realOrientation = "landscapeLeft"  
 elseif math.abs ( accel.y ) \< min and accel.x \< -max then  
 -- landscape button right  
 realOrientation = "landscapeRight"  
 else  
 realOrientation = "landscapeRight"  
 end  
  
  
 end  
  
end  
  
local function onAccelerate ( event )  
 accel.x, accel.y = event.xGravity, event.yGravity  
end  

this is quite a bit messy, and probably a few of other pieces of code are left out (because now it looks to me that part below “elseif accel.x then” doesn’t do anything anymore, but hope to give you some ideas.

cheers
n [import]uid: 80100 topic_id: 23588 reply_id: 95099[/import]

@IgnisDesign

The problem is that you don’t get an animated rotation unless listeners are used. At least that’s what I’ve encountered.
Since the rotation is instant on the device, you also get a rather unsightly rectangle that rotates without any content when you switch orientations… [import]uid: 70847 topic_id: 23588 reply_id: 95111[/import]

Thanks for the replys peeps.

I am handling the orientation events to rearrange content. I offer two display modes in my apps, and the content is set up according to the screen size, if X is larger than Y, I assume it’s landscape, otherwise I assume it’s portrait.

You can try it yourself (bug won’t happen on simulator, must be on device)
Create an “ebook” sample code and substitute the “page1.lua” with the following code, it’s not 100% but I guess one could get my point of view:
[lua]-----------------------------------------------------------------------------------------

– page1.lua


local storyboard = require( “storyboard” )
local scene = storyboard.newScene()


– BEGINNING OF YOUR IMPLEMENTATION

– NOTE: Code outside of listener functions (below) will only be executed once,
– unless storyboard.removeScene() is called.


– forward declarations and other locals
local background, pageText, continueText, pageTween, fadeTween1, fadeTween2, sunObj, moonObj, coronaIcon

local swipeThresh = 100 – amount of pixels finger must travel to initiate page swipe
local tweenTime = 500
local animStep = 1
local readyToContinue = false

– function to show next animation
local function showNext()
if readyToContinue then
continueText.isVisible = false
readyToContinue = false

local function repositionAndFadeIn()
pageText:setReferencePoint( display.CenterReferencePoint )
pageText.x = display.contentWidth * 0.5
pageText.y = display.contentHeight * 0.20
pageText.isVisible = true

fadeTween1 = transition.to( pageText, { time=tweenTime*0.5, alpha=1.0 } )
end

local function completeTween()
animStep = animStep + 1
if animStep > 3 then animStep = 1; end

readyToContinue = true
continueText.isVisible = true
end

if animStep == 1 then
pageText.alpha = 0
pageText.text = “High-performance, OpenGL graphics engine.”
repositionAndFadeIn()

– hide corona icon
coronaIcon.isVisible = false

sunObj.alpha = 1
sunObj.x = -sunObj.contentWidth
sunObj.isVisible = true
pageTween = transition.to( sunObj, { time=tweenTime, x=display.contentWidth*0.5, transition=easing.outExpo, onComplete=completeTween } )

elseif animStep == 2 then
pageText.alpha = 0
pageText.text = “Easy API accessed via Lua scripting.”
repositionAndFadeIn()

moonObj.alpha = 1
moonObj.x = display.contentWidth + moonObj.contentWidth
moonObj.isVisible = true
pageTween = transition.to( moonObj, { time=tweenTime, x=display.contentWidth*0.5, transition=easing.outExpo, onComplete=completeTween } )

elseif animStep == 3 then
pageText.alpha = 0
pageText.text = “Corona SDK: Code Less. Play More.”
repositionAndFadeIn()

– hide sun and moon
fadeTween1 = transition.to( sunObj, { time=tweenTime*0.5, alpha=0 } )
fadeTween2 = transition.to( moonObj, { time=tweenTime*0.5, alpha=0 } )

coronaIcon.isVisible = true
coronaIcon.alpha = 0
coronaIcon.x = display.contentWidth * 0.5
pageTween = transition.to( coronaIcon, { time=tweenTime*1.5, alpha=1, transition=easing.inOutExpo, onComplete=completeTween } )
end
end
end

– touch event listener for background object
local function onPageSwipe( self, event )
local phase = event.phase
if phase == “began” then
display.getCurrentStage():setFocus( self )
self.isFocus = true

elseif self.isFocus then
if phase == “ended” or phase == “cancelled” then

local distance = event.x - event.xStart
if distance > swipeThresh then
– SWIPED to right; go back to title page scene
storyboard.gotoScene( “title”, “slideRight”, 800 )
else
– Touch and release; initiate next animation
showNext()
end

display.getCurrentStage():setFocus( nil )
self.isFocus = nil
end
end
return true
end
– Called when the scene’s view does not exist:
function scene:createScene( event )
local group = self.view

– create background image
background = display.newImageRect( group, “space.jpg”, display.contentWidth, display.contentHeight )
background:setReferencePoint( display.CenterReferencePoint )
background.x, background.y = display.contentCenterX, display.contentCenterY
background.alpha = 0.5
function orientation(self,e)

self.x, self.y = display.contentCenterX, display.contentCenterY
end
background.orientation = function(self,e)
if display.viewableContentWidth > display.viewableContentHeight then
self.rotation = 90
else
self.rotation = 0
end
self.x, self.y = display.contentCenterX, display.contentCenterY
end
Runtime:addEventListener(“orientation”,background)
– create overlay
local overlay = display.newImageRect( group, “pagebg1.png”, display.contentWidth, display.contentHeight )
overlay:setReferencePoint( display.CenterReferencePoint )
overlay.x, overlay.y = display.contentCenterX, display.contentCenterY
function overlay:orientation()
overlay.width,overlay.height = display.contentWidth, display.contentHeight
self.x, self.y = display.contentCenterX, display.contentCenterY
end
Runtime:addEventListener(“orientation”,overlay)

– create sun, moon, and corona icon
sunObj = display.newImageRect( group, “sun.png”, 300, 300 )
sunObj.isVisible = false
sunObj:setReferencePoint( display.CenterReferencePoint )
sunObj.x, sunObj.y = display.contentCenterX, display.contentCenterY
sunObj.orientation = orientation
Runtime:addEventListener(“orientation”,sunObj)

moonObj = display.newImageRect( group, “moon.png”, 300, 300 )
moonObj.isVisible = false
moonObj:setReferencePoint( display.CenterReferencePoint )
moonObj.x, moonObj.y = display.contentCenterX, display.contentCenterY
moonObj.orientation = orientation
Runtime:addEventListener(“orientation”,moonObj)

coronaIcon = display.newImageRect( group, “coronaicon-big.png”, 450, 444 )
coronaIcon:setReferencePoint( display.CenterReferencePoint )
coronaIcon.x = display.contentWidth * 0.5
coronaIcon.y = display.contentHeight * 0.5
coronaIcon.orientation = orientation
coronaIcon.alpha = 0
Runtime:addEventListener(“orientation”,coronaIcon)

– create pageText
pageText = display.newRetinaText( group, “”, 0, 0, native.systemFontBold, 18 )
pageText:setReferencePoint( display.CenterReferencePoint )
pageText.x = display.contentWidth * 0.5
pageText.y = display.contentHeight * 0.5
pageText.orientation = function (self,e)
self.x, self.y = display.contentCenterX, display.contentHeight * 0.20
end
pageText.isVisible = false
Runtime:addEventListener(“orientation”,pageText)

– create text at bottom of screen
continueText = display.newRetinaText( group, “\ndisplay.viewableContentHeight:”…display.viewableContentHeight…"\ndisplay.viewableContentWidth"…display.viewableContentWidth, 0, 0, native.systemFont, 18 )
continueText:setReferencePoint( display.CenterReferencePoint )
continueText.x = display.contentWidth * 0.5
continueText.y = display.contentHeight - (display.contentHeight * 0.04 )
continueText.orientation = orientation
continueText.isVisible = false
continueText.orientation = function (self,e)
continueText.text = e.type…"\n"…display.viewableContentHeight…“display.viewableContentHeight:”…display.viewableContentHeight…"\n"…display.viewableContentWidth…“display.viewableContentWidth”…display.viewableContentWidth
self.x, self.y = display.contentCenterX,display.contentCenterY
end
Runtime:addEventListener(“orientation”,continueText)
end

– Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view

animStep = 1
readyToContinue = true
showNext()

– assign touch event to background to monitor page swiping
background.touch = onPageSwipe
background:addEventListener( “touch”, background )
end

– Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view

– hide objects
sunObj.isVisible = false
moonObj.isVisible = false
coronaIcon.isVisible = false
pageText.isVisible = false

– remove touch event listener for background
background:removeEventListener( “touch”, background )

– cancel page animations (if currently active)
if pageTween then transition.cancel( pageTween ); pageTween = nil; end
if fadeTween1 then transition.cancel( fadeTween1 ); fadeTween1 = nil; end
if fadeTween2 then transition.cancel( fadeTween2 ); fadeTween2 = nil; end
end

– If scene’s view is removed, scene:destroyScene() will be called just prior to:
function scene:destroyScene( event )
local group = self.view

– INSERT code here (e.g. remove listeners, remove widgets, save state variables, etc.)

end


– END OF YOUR IMPLEMENTATION

– “createScene” event is dispatched if scene’s view does not exist
scene:addEventListener( “createScene”, scene )

– “enterScene” event is dispatched whenever scene transition has finished
scene:addEventListener( “enterScene”, scene )

– “exitScene” event is dispatched whenever before next scene’s transition begins
scene:addEventListener( “exitScene”, scene )

– “destroyScene” event is dispatched before view is unloaded, which can be
– automatically unloaded in low memory situations, or explicitly via a call to
– storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( “destroyScene”, scene )


return scene[/lua] [import]uid: 79152 topic_id: 23588 reply_id: 100358[/import]

@Peach:

I did not receive any bug report email… nor did I subscribe to the bug :(( [import]uid: 79152 topic_id: 23588 reply_id: 100359[/import]

You did file a bug though? If so, give me the case # and I will help you updating it. [import]uid: 52491 topic_id: 23588 reply_id: 100399[/import]