
CoronaSDK Proper Orientation Rotation with Animation
This is a code I came up when learning Lua & CoronaSDK programming. Copy of the original code still available at Ansca code exchange.
It is mostly working as I wanted except a small bug. If you rotate the device while app is loading assets, there might be a small delay. I’m planning to work on an update for that as soon as our game is out…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
--]] -- SET YOUR ORIENTATIONS HERE local mainOr = "portrait" local altOr = "portraitUpsideDown" -- MASTER CODE local stage = display.getCurrentStage( ) stage:setReferencePoint(display.CenterReferencePoint) isRotated = false local rotatefilter --function reserve local rotatestart --function reserve local rotatecomplete --function reserve local curOrientation = mainOr --inital launch always match mainOr local rota = 0 local isrotating = false local rd = 600 -- iPad rotates slower if system.getInfo("model") == "iPad" then rd = 750 end function rotatefilter( ) if (system.orientation == mainOr or system.orientation == altOr ) then return system.orientation else if curOrientation then return curOrientation else return mainOr end end end function rotatestart( val, initial ) if isrotating == false and curOrientation ~= val then if val == mainOr then rota = 180 curOrientation = mainOr elseif val == altOr then rota = -180 curOrientation = altOr end isrotating = true if initial and rd == 750 then transition.to( stage, { rotation=rota, time=0, delta=true, onComplete=rotatecomplete } ) else transition.to( stage, { rotation=rota, time=rd, delta=true, transition=easing.inOutQuad, onComplete=rotatecomplete } ) end end end function rotatecomplete( ) isrotating = false if curOrientation == altOr then isRotated = true else isRotated = false end if curOrientation ~= rotatefilter() then rotatestart(rotatefilter()) end end --Check initial orientation and and rotate if needed if ( system.orientation == altOr and isrotating == false) then rotatestart(altOr,true) end local function onOrientationChange( event ) local type = event.type if ( type == mainOr or type == altOr ) then rotatestart(type) end end Runtime:addEventListener( "orientation", onOrientationChange ) |
im also having trouble getting this working with ghost vs monsters demo..
currently in my game i have it set up as
settings =
{
orientation = {
default = “landscapeRight”, },
iphone =
{
plist =
{
CFBundleIconFile = “Icon.png”, CFBundleIconFiles = { “Icon.png”,
“Icon@2x.png”,
“Icon-72.png”,
— “Icon-72@2x.png”, “Icon-Small.png”, “Icon-Small@2x.png”, “Icon-Small-50.png”, “Icon-Small-50@2x.png”,
},
},
},
}
can you send me a sample to try out ??
thanks
I’m afraid I won’t be able to help you with the sample as we are no longer using CoronaSDK. But you should try to add following config directives so orientation section should read:
default = landscapeRight,
content = landscapeRight,
supported =
{
landscapeLeft, landscapeRight
},
I hope this helps…
in landscape mode i have an issue when i rotate the ipad in the right or left direction. each time on the first rotation the content is updsidedown, on the second it looks good & then again on the third upsidesdown…
i have set landscapeRight & left in both files build.settings & rotationfix.lua as described. did i have put something wrong ? thank you.
Hi Ezra,
Have you also put “content” tag in there? That sounds like rotationfix & native rotation working together…
build.settings should look like that ->
orientation =
{
default = landscapeLeft,
content = landscapeLeft,
supported =
{
landscapeLeft, landscapeRight
}
},
I can’t make it work in the Corona simulator in landscape mode in my game.
I tried on Ghosts versus Monsters example and it also does not work.
Does it work for you?
Hi Luciane,
I’ve just replied your ticket and sent u a working Ghost vs Monsters sample project…
Works great on iPad 2. Looks more professional.
Thank you,
Mike
You’re welcome… I’m glad to hear it’s been useful. :)
Hi,
I want to Make the game like some pages are in portrait mode and some are in landscape mode, Using rotation i am not able approach it .
So, please suggest me some tutorials.
Thankyou..
Hi Nirosha, I’m afraid I won’t be able to help you as we’re not using Corona SDK anymore. You should try Coronalabs forum instead…