rotation question

Hi

I am developing a flashcard app for my students. Each ‘card’ has a multiple choice question and an image. The position of the text and image are set using  display.contentWidth and height.

e.g image.x = display.contentWidth - image.width

The app displays a ‘card’, then waits for a touch from the user, at which point it moves to the next card. The default is landscape. If I rotate the device to portrait while the app is waiting for the touch, the questions and image position are not re-calculated, so I end up with my text and/or image running off the edge. If I stay in portrait, after the touch, when the next card is displayed, then everything sits properly on the screen. 

Not sure what to do about this. Thanks in advance.

david

hey david,

do you want the app to be able to rotate at all?

if not just go to your build.settings and get rid of of portrait in your supported table
[lua]
orientation =
        {
        default = “landscape”,
        supported = { “landscape”, }
    },

[/lua]

further read:
http://docs.coronalabs.com/guide/distribution/buildSettings/index.html

if you want your app to be viewable in landscape and portrait, simply add something like this:
[lua]

local function onOrientationChange( event )
    local direction = event.type

   if (direction == “landscapeLeft” or direction == “landscapeRight”) then
            --move your objects to the positions they suppose to have on landscape
   else
            --move your objects to the positions they suppose to have on portrait     
   end

end
Runtime:addEventListener( “orientation”, onOrientationChange )

[/lua]
further read: http://www.coronalabs.com/blog/2011/01/28/use-dynamic-layouts-in-universal-builds-with-corona-sdk/ (at the bottom)

Or in your case, this should already be enough to do the trick:
[lua]

local function onOrientationChange( event )
    image.x = display.contentWidth - image.width

end

Runtime:addEventListener( “orientation”, onOrientationChange )

[/lua]

           
for your understanding of the issue:
your objects are all having fixed non-dynamic coordinates. even when you have the feeling they do have dynamic coordinates because you placed them with image.x = display.contentWidth - image.width ,
but display.contentWidth - image.width is just a calculated number too that always will be the value of display.contentWidth - image.width from the time you initiated that line of code.

as you programmed it, those coordinates wont change on a rotation of the device because your image.x is still carrying the value of the landscape width minus your image width (because your line that filled the x value was happening at landscape mode).
a simple variable, (as image.x essentially is), will never change by itself unless you make it change.
so it looks like your stuff got pushed out, but it essentially just stayed at the same position.

i hope i was able to help you and that my explaination was not too confusing,
have a nice day and happy programming,
Michael

Hi Michael

Thanks for your email. I’m still wrapping my head around this but will try what you’ve suggested. My understanding is that supporting an orientation in the build settings is not sufficient to get the app to change variables such as image.x  on the fly, which is why you need the functions as well. Is that right? (I do want to support rotation because I read that Apple requires that. But I also read that you don’t need to support upside down portrait since they don’t want people holding their phones upside down)

cheers

David

My understanding is that supporting an orientation in the build settings is not sufficient to get the app to change variables such as image.x  on the fly, which is why you need the functions as well.

Hi David,

exactly, supporting multiple orientations in your build settings is just doing the following:
a ) rotating your screen on orientationchange (around the top left Referencepoint of the screen)

b ) swapping the display.contentWidth and display.contentHeight values

c ) triggering the orientation listener (if you got one)
 

I do want to support rotation because I read that Apple requires that.

that’s new to me, could you please share a link to the source where you read that?
that would make plenty of apps and games not fulfilling the requirements, and i couldnt find any of this information in here:
http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/App-RelatedResources/App-RelatedResources.html
here:
https://developer.apple.com/appstore/resources/approval/guidelines.html
or here:
https://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/MobileHIG/Introduction/Introduction.html

cheers,
Michael
 

OK obviously that was from an unreliable source but if I come across it again (I don’t recall right now where I read it) I will post. 

Rotation from Landscape to Portrait is not really necessary for my app. Perhaps I shouldn’t bother with it if Apple doesn’t require it. Thanks for the info.

i did a bit more research to be sure, and all i was able to find is that they require that if you do an landscape app for ipad you have to include landscape right and landscape left. what might be a rotation lock thing, which as far as i know doesnt exist on iphone and ipod touch.

thanks for your reply, if you find the source let me know nevertheless.

i wish you all the best for your project and have a nice day,
michael

hey david,

do you want the app to be able to rotate at all?

if not just go to your build.settings and get rid of of portrait in your supported table
[lua]
orientation =
        {
        default = “landscape”,
        supported = { “landscape”, }
    },

[/lua]

further read:
http://docs.coronalabs.com/guide/distribution/buildSettings/index.html

if you want your app to be viewable in landscape and portrait, simply add something like this:
[lua]

local function onOrientationChange( event )
    local direction = event.type

   if (direction == “landscapeLeft” or direction == “landscapeRight”) then
            --move your objects to the positions they suppose to have on landscape
   else
            --move your objects to the positions they suppose to have on portrait     
   end

end
Runtime:addEventListener( “orientation”, onOrientationChange )

[/lua]
further read: http://www.coronalabs.com/blog/2011/01/28/use-dynamic-layouts-in-universal-builds-with-corona-sdk/ (at the bottom)

Or in your case, this should already be enough to do the trick:
[lua]

local function onOrientationChange( event )
    image.x = display.contentWidth - image.width

end

Runtime:addEventListener( “orientation”, onOrientationChange )

[/lua]

           
for your understanding of the issue:
your objects are all having fixed non-dynamic coordinates. even when you have the feeling they do have dynamic coordinates because you placed them with image.x = display.contentWidth - image.width ,
but display.contentWidth - image.width is just a calculated number too that always will be the value of display.contentWidth - image.width from the time you initiated that line of code.

as you programmed it, those coordinates wont change on a rotation of the device because your image.x is still carrying the value of the landscape width minus your image width (because your line that filled the x value was happening at landscape mode).
a simple variable, (as image.x essentially is), will never change by itself unless you make it change.
so it looks like your stuff got pushed out, but it essentially just stayed at the same position.

i hope i was able to help you and that my explaination was not too confusing,
have a nice day and happy programming,
Michael

Hi Michael

Thanks for your email. I’m still wrapping my head around this but will try what you’ve suggested. My understanding is that supporting an orientation in the build settings is not sufficient to get the app to change variables such as image.x  on the fly, which is why you need the functions as well. Is that right? (I do want to support rotation because I read that Apple requires that. But I also read that you don’t need to support upside down portrait since they don’t want people holding their phones upside down)

cheers

David

My understanding is that supporting an orientation in the build settings is not sufficient to get the app to change variables such as image.x  on the fly, which is why you need the functions as well.

Hi David,

exactly, supporting multiple orientations in your build settings is just doing the following:
a ) rotating your screen on orientationchange (around the top left Referencepoint of the screen)

b ) swapping the display.contentWidth and display.contentHeight values

c ) triggering the orientation listener (if you got one)
 

I do want to support rotation because I read that Apple requires that.

that’s new to me, could you please share a link to the source where you read that?
that would make plenty of apps and games not fulfilling the requirements, and i couldnt find any of this information in here:
http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/App-RelatedResources/App-RelatedResources.html
here:
https://developer.apple.com/appstore/resources/approval/guidelines.html
or here:
https://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/MobileHIG/Introduction/Introduction.html

cheers,
Michael
 

OK obviously that was from an unreliable source but if I come across it again (I don’t recall right now where I read it) I will post. 

Rotation from Landscape to Portrait is not really necessary for my app. Perhaps I shouldn’t bother with it if Apple doesn’t require it. Thanks for the info.

i did a bit more research to be sure, and all i was able to find is that they require that if you do an landscape app for ipad you have to include landscape right and landscape left. what might be a rotation lock thing, which as far as i know doesnt exist on iphone and ipod touch.

thanks for your reply, if you find the source let me know nevertheless.

i wish you all the best for your project and have a nice day,
michael