Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cocos2D needs to support all 'supportedInterfaceOrientations' options #891

Open
Ben-G opened this issue Jul 17, 2014 · 6 comments
Open

Cocos2D needs to support all 'supportedInterfaceOrientations' options #891

Ben-G opened this issue Jul 17, 2014 · 6 comments

Comments

@Ben-G
Copy link
Contributor

Ben-G commented Jul 17, 2014

Currently the supported interface orientations are determined by the CCNavigationController inside CCAppDelegate:

-(NSUInteger)supportedInterfaceOrientations
{
    if ([_screenOrientation isEqual:CCScreenOrientationAll])
    {
        return UIInterfaceOrientationMaskAll;
    }
    else if ([_screenOrientation isEqual:CCScreenOrientationPortrait])
    {
        return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
    }
    else
    {
        return UIInterfaceOrientationMaskLandscape;
    }
}

The supported screen orientation is determined by the screenOrientation property of CCNavigationController which only has three valid values:

NSString* const CCScreenOrientationLandscape = @"CCScreenOrientationLandscape";
NSString* const CCScreenOrientationPortrait = @"CCScreenOrientationPortrait";
NSString* const CCScreenOrientationAll = @"CCScreenOrientationAll"

If games want to restrict the supported device orientation to only one orientation (e.g. LandscapeLeft) the Cocos2D source code needs to be modified to change the implementation of the supportedInterfaceOrientations method.

CCNavigationController should expose all possible supported device orientations, either by adding more string constants or by another solution.

@Metalboyblue
Copy link

Agreed. I am having this problem now. Also, I would like to add the request to set this parameter on a "Per-Scene" basis. I have a unique situation I am sure but some of the scenes work best in landscape and some in portrait.

@slembcke
Copy link
Contributor

You could override the method easily enough without needing to change Cocos code. I'm a bit hesitant to add too many options or configurability to CCAppDelegate since it's purpose was to simplify the app delegate experience from 2.x. Using CCAppDelegate is optional, it's just meant to be a convenience that does what most people want with minimal fuss.

As for per-scene transitions, you could override the supportedInterfaceOrientations and make it more dynamic. It would get much more tricky if you wanted to have transitions involved though.

@Ben-G
Copy link
Contributor Author

Ben-G commented Jul 21, 2014

At the moment the methods are implemented inside of CCNavigationController which is instantiated inside of setupCocos2dWithOptions. So I would have to override setupCocos2dWithOptions which is the majority of the code in CCAppDelegate in order to instantiate my subclass of CCNavigationController. Or am I missing something?

To me it seems that adding the additional options for the orientations would not add a lot of complexity to CCAppDelegate.

@slembcke
Copy link
Contributor

You are of course correct. Shoot. I remember thinking it was way easier than that.

Does it make sense to expose this using more options for the setup dictionary? (Since we didn't use bitmasks... urk!) Should the navigation controller forward the method call to the app delegate so that it can be overridden? That would make more dynamic usages possible too.

@Ben-G
Copy link
Contributor Author

Ben-G commented Jul 21, 2014

Yes, I was thinking of the second option and I think I prefer that one. It is also compatible with SpriteBuilder projects, because SpriteBuilder would otherwise override the setup .plist file.

@iMobCoding
Copy link
Contributor

Here is a pull request that solves this #930
Basically what @slembcke suggested as 2nd option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants