Rotate scree 180 degrees

Okay, I’m about ready to drop kick my computer across the room. I’ve spent 4 hours trying to add device orientation event to my app.

My app will only support Landscape and I thought it would be cool to have it flip 180 degrees depending on “landscapeRight” and “landscapeLeft”

I found the code easy enough to handle the orientation event.

onOrientationChange = function( event )

if( currentOrientation == “landscapeRight” or currentOrientation == “landscapeLeft” ) then
        local newAngle = LoadLevelScene.SceneGroup.rotation - 180
        transition.to( LoadLevelScene.SceneGroup, {time = 750,  rotation = newAngle  })
end – end if

end

Runtime:addEventListener( “orientation”, onOrientationChange )

I wasted about 2 hours trying to manipulate the sceneGroup in composer-- Setting the anchorPoints, and rotating the sceneGroup – the screen wouldn’t rotate around the center no matter what I did blah, blah, Then I found an article where Roaming Gamer said:

Don’t directly make changes to rotation in your sceneGroup in your composer scene. If you want to rotate create a new group to make changes. So I made a new display Group :

LoadLevelScene.SceneGroup = display.newGroup()

sceneGroup:insert( LoadLevelScene.SceneGroup )

I also read the article http://coronalabs.com/blog/2013/10/15/tutorial-anchor-points-in-graphics-2-0/

Generally speaking, groups don’t care about anchor points because they are “unbounded.”

So, I set the .anchorChildren to true as the article suggested. This worked and the screen seemed rotate around the center but:

When I set anchorChildren to true – the entire Scene goes offset what it was before.  Now everything works perfect except the .anchorChildren has the entire screen offset and I can’t get it exactly in the center. Ugh

So – Why does setting anchorChildren to true offset the group? And should you always leave anchorChildren set to true for rotating the entire screen or set it to true before the rotation and then false after the rotation?

ultimately setting anchorChildren to true  does make the anchorPoints work but my screen doesn’t  seem to rotate directly around the center. When I rotate the app in the simulator the screen slowly spins off the screen ugh

Any help, suggestion or code will help.

Thanks!

If you’ve added “landscapeLeft” and “landscapeRight” in your build.settings, Corona should rotate your screen for you and you shouldn’t need to deal with orientation events.  Where that becomes important is if your game needs to do cool things when flipped.  I used that in a game to enable an Easter Egg.  If you have an app that’s both landscape and portrait, then you might need to reposition things.

But just for a Landscape app that you want to handle flipping, then Corona can deal with that with just build.settings.

Rob

Omg Robert you’re right. I always assumed Corona didn’t handle it for you and I locked the app in “landscapeRight”. This is what happens when you assume. Lol.

BTW, its really extremely awesome what you guys have done for us.

If you’ve added “landscapeLeft” and “landscapeRight” in your build.settings, Corona should rotate your screen for you and you shouldn’t need to deal with orientation events.  Where that becomes important is if your game needs to do cool things when flipped.  I used that in a game to enable an Easter Egg.  If you have an app that’s both landscape and portrait, then you might need to reposition things.

But just for a Landscape app that you want to handle flipping, then Corona can deal with that with just build.settings.

Rob

Omg Robert you’re right. I always assumed Corona didn’t handle it for you and I locked the app in “landscapeRight”. This is what happens when you assume. Lol.

BTW, its really extremely awesome what you guys have done for us.