Orientation Changes

I’m quite a newbie in Corona. And right now I’m having a difficulty in grasping the orientation changes. Can anyone give me a guide in handling orientation changes properly?

You need the following in your build.settings file : 

 orientation = { default ="portrait", supported = { "portrait", "portraitUpsideDown", "landscapeRight", "landscapeLeft", }, },

You need the following listener in your main.lua . This will allow you to detect the changes and trigger any screen formatting changes etc 

--The following code shows how an app can respond to orientation events: local function onOrientationEvent( event ) local eventType = event.type --print (eventType) if ( eventType == "portrait" ) then elseif ( eventType == "portraitUpsideDown" ) then elseif ( eventType == "landscapeRight" ) then elseif ( eventType == "landscapeLeft" ) then end end Runtime:addEventListener( "orientation", onOrientationEvent )

You need the following in your build.settings file : 

 orientation = { default ="portrait", supported = { "portrait", "portraitUpsideDown", "landscapeRight", "landscapeLeft", }, },

You need the following listener in your main.lua . This will allow you to detect the changes and trigger any screen formatting changes etc 

--The following code shows how an app can respond to orientation events: local function onOrientationEvent( event ) local eventType = event.type --print (eventType) if ( eventType == "portrait" ) then elseif ( eventType == "portraitUpsideDown" ) then elseif ( eventType == "landscapeRight" ) then elseif ( eventType == "landscapeLeft" ) then end end Runtime:addEventListener( "orientation", onOrientationEvent )

Hi ksan,

I did the same as you mentioned above but still getting some problem.

Some time my screen is stuck in the middle of the device. It’s showing half of the screen in right hand side of device and  it happens only in portrait mode.

I am stuck at this point. How do i solve this?

Here is my code:

<lua>

function onOrientationChange( event )

   if system.orientation == “portrait” or system.orientation == “portraitUpsideDown” then

    

      _W = 768

    _H = 1024

    _X = _W/2

    _Y = _H/2

        

  else

        

    _W = 1024

    _H = 768

    _X = _W/2

    _Y = _H/2

  end    

    

end    

Runtime:addEventListener( “orientation”, onOrientationChange )

</lua>

Here is my build.setting and config.lua file:

<lua>

settings =

{

    orientation =

    {

        default = “portrait”,

        supported = 

        { 

            “portrait”, “portraitUpsideDown”, “landscapeRight”, “landscapeLeft” 

        }

    },

    ipad =

    {

        plist=

        {

                

            UIApplicationExitsOnSuspend = false,

            UIStatusBarHidden = true,

            UIPrerenderedIcon = true,

            CFBundleIconFile = “Icon.png”,

            UIAppFonts = {“Harrowprint.ttf”,“Thonburi.otf”,“helvetica-neue-bold.ttf”},    

            CFBundleDisplayName = “Quran”,

            CFBundleIconFiles = {

                           “Icon.png”, 

                           “Icon@2x.png”,

                           “Icon-72.png”,

                        },

        },

    },

}

</lua>

<lua>

application =

{

    content =

    {

        fps = 60,

        width = 768,

        height = 1024,

        scale = “letterBox”,

    },

}

</lua>

Any help will be appreciated?

Thannks. 

Hi ksan,

I did the same as you mentioned above but still getting some problem.

Some time my screen is stuck in the middle of the device. It’s showing half of the screen in right hand side of device and  it happens only in portrait mode.

I am stuck at this point. How do i solve this?

Here is my code:

<lua>

function onOrientationChange( event )

   if system.orientation == “portrait” or system.orientation == “portraitUpsideDown” then

    

      _W = 768

    _H = 1024

    _X = _W/2

    _Y = _H/2

        

  else

        

    _W = 1024

    _H = 768

    _X = _W/2

    _Y = _H/2

  end    

    

end    

Runtime:addEventListener( “orientation”, onOrientationChange )

</lua>

Here is my build.setting and config.lua file:

<lua>

settings =

{

    orientation =

    {

        default = “portrait”,

        supported = 

        { 

            “portrait”, “portraitUpsideDown”, “landscapeRight”, “landscapeLeft” 

        }

    },

    ipad =

    {

        plist=

        {

                

            UIApplicationExitsOnSuspend = false,

            UIStatusBarHidden = true,

            UIPrerenderedIcon = true,

            CFBundleIconFile = “Icon.png”,

            UIAppFonts = {“Harrowprint.ttf”,“Thonburi.otf”,“helvetica-neue-bold.ttf”},    

            CFBundleDisplayName = “Quran”,

            CFBundleIconFiles = {

                           “Icon.png”, 

                           “Icon@2x.png”,

                           “Icon-72.png”,

                        },

        },

    },

}

</lua>

<lua>

application =

{

    content =

    {

        fps = 60,

        width = 768,

        height = 1024,

        scale = “letterBox”,

    },

}

</lua>

Any help will be appreciated?

Thannks.