Multiple orientation support

I’ve developed a cocos2d-x game locked in landscape mode.

now I need to support portrait.

When I add portrait to “supported interface orientations” in the info.plist, the landscape mode, which previously looked great, now shows a mostly black screen, with the entire scene shoved in the top right corner.

I tried resetting the frame size of the glview, as well as the designresolutionsize, but that doesn’t seem to help.

surely device orientation changes are supported in cocos2d-x already, right? all the forum posts on the subject are old, and the solutions in them don’t really work.

has anyone sorted this out yet? thanks.

We having same issue as there is not much information how to solve, reset view size.

As workaround we just did: based on accelerometer setting phone position Landscape, Portrait and repositioning all elements based on this. Issue with this approach - Ads is showed in original Portrait mode and system tools are in portrait position if visible.

Let’s see if someone have good recipe for solving that issue…

Unfortunately Cocos is not really setup to support changing orientations. I did this for an app last year and it was a serious pain. You have to modify iOS’s RootViewController.mm to allow the change in orientation, and pass the new frame size on to Cocos once it happens (I calc’d it in willRotateToInterfaceOrientation:) to update the GLView, then notify your scenes that the orientation changed so they can reset their elements.

One big problem I ran in to was that the rotation does not animate well, so the upcoming “rotated” scene started out squished, then stretched in to place.

We will be creating videos on this topic very soon.

2 Likes

Can’t wait to for you to make videos over this topic. Thanks for all your contribution.

Your welcome.

You can also look here: Running game in both Landscape AND Portrait mode

2 Likes

yup really looking forward. @SonarSystems

1 Like

As are we :smiley:

Can someone please post some hints as to how to simply set the orientation of a Cocos2D app in Objective-C to “Portrait”? This would be the initial orientation and only orientation supported by the app.

If I set the device orientation to “Portrait” in the project settings it is ignored and displays in landscape mode. The plist file sets the “Initial interface orientation” to “Portrait” and the “Supported interface orientation” to “Portrait”.

I am updating an existing (and very old) app with the latest Cocos2D. The existing app supports portrait and landscape but I recall I had spent weeks trying to get the orientation change to work properly. All of the code to do this is no longer valid. The app works best in Portrait mode so I only need to support this mode.

I see a myriad of postings on Stack Overflow but they cause crashes. I’m unable to post the links here apparently.

Any help appreciated.

Chris

P.S. It appears the orientation is managed in CCAppDelegate.m. A small modification enforces portrait mode.

// The available orientations should be defined in the Info.plist file.
// And in iOS 6+ only, you can override it in the Root View controller in the "supportedInterfaceOrientations" method.
// Only valid for iOS 6+. NOT VALID for iOS 4 / 5.
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    // Force Portrait mode only
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
    
//    if ([_screenOrientation isEqual:CCScreenOrientationAll])
//    {
//        return UIInterfaceOrientationMaskAll;
//    }
//    else if ([_screenOrientation isEqual:CCScreenOrientationPortrait])
//    {
//        return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
//    }
//    else
//    {
//        return UIInterfaceOrientationMaskLandscape;
//    }
}