Switch Landscape to Portrait mode?

Hi everyone.
I'm developing a game with 2 modes that use 2 types of screen: Landscape and Portrait.
I designed 2 buttons in Main Menu to select one of these 2 modes.
But i don't know how to switch them. Someone help me!

Hi,

The user changes orientation by tilting the device which the code will have to detect. Then based on the current orientation, you redraw the placement of objects on your screen. These events are only sent for certain devices with accelerometer support.

if you are developing for android, then you definitely want to check this twice.

I mean i have 2 modes: the first likes Ninja Fruit (Landscape) and the second likes Doodle Jump (Portrait).
I want to switch 2 modes when press a button WITHOUT TILTING DEVICE but i cannot find any code in API or forum for this function. I'm still stuck here.

build.settings file:

1
2
3
4
5
6
7
8
9
orientation =
    {
                default = "landscapeRight",
                content = "landscapeRight",
                supported =
                {
                        "landscapeRight"
                },
    },

The following things are setting for portrait mode.

If you are force-fully set the game mode Portrait then check this first in new mode(Portrait Mode) file :

if (system.orientation == "landscapeLeft") or (system.orientation == "landscapeRight") then

localGroup.rotation = -90
localGroup.x = 0
localGroup.y = 768
end

Set all the objects co-ordinates of new mode(Portrait Mode) in portrait form.

This will show ur game in portrait mode even your device in landscape mode.
and also don't forget to set the localGroup rotation in Runtime:addEventListener . like

local function onOrientationChange ( event )

if (event.type == "landscapeLeft") or (event.type == "landscapeRight") then
print(event.type)
localGroup.rotation = -90
localGroup.x = 0
localGroup.y = 0

elseif (event.type == "portrait") or (event.type == "portraitUpsideDown") then
print(event.type)
localGroup.rotation = 360
localGroup.x = 0
localGroup.y = 0

end

return true
end
Runtime:addEventListener("orientation", onOrientationChange )

Little modification on above thing for set in to Landscape Mode.

build.setting :

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

},
}

It's work very well in my game , i hope it's also helpful to u.

views:1783 update:2011/9/29 9:22:17
corona forums © 2003-2011