Cocos2d - Setting Device/Screen Orientation

前端 未结 6 962
情话喂你
情话喂你 2021-01-15 17:31

I am new to the cocos2d API and have noticed that there are a few ways to set the screens orientation within the templates. I have not been able to figure out the correct wa

相关标签:
6条回答
  • 2021-01-15 18:11

    Use this line:

    [[CCDirector sharedDirector] setDeviceOrientation:kkCCDeviceOrientationLandscapeRight];
    
    0 讨论(0)
  • 2021-01-15 18:16

    In the RootViewController.m,search for the line

    return ( UIInterfaceOrientationIsPortrait(interfaceOrientation ));
    

    change it to

    return ( UIInterfaceOrientationIsLandscape(interfaceOrientation ));
    
    0 讨论(0)
  • 2021-01-15 18:22

    Modify GameConfig.h from the cocos2d template.

    #define GAME_AUTOROTATION kGameAutorotationNone
    /* original code is kGameAutorotationUIViewController. */
    

    And modify AppDelegate.m as well.

    #if GAME_AUTOROTATION == kGameAutorotationUIViewController
        [director setDeviceOrientation:kCCDeviceOrientationPortrait];
    #else
        [director setDeviceOrientation:kCCDeviceOrientationLandscapeRight];
        /* original code is "Left". */
    #endif
    
    0 讨论(0)
  • 2021-01-15 18:26

    if you added shouldAutorotateToInterfaceOrientation and not solved your problem

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return UIInterfaceOrientationIsLandscape(interfaceOrientation);
    }
    

    THEN Try to add this line to appDelegate.m

    [window_ setRootViewController:navController_];
    

    Good Luck

    0 讨论(0)
  • 2021-01-15 18:29

    The correct answer - took me a while to find - is in the info.plist, change the supported interface orientations values, item 0 and item 1 have 4 possible values, Portrait (top home button) etc.

    0 讨论(0)
  • 2021-01-15 18:35

    The answer here has changed with cocos2d 2.0, as CCDirector is now a ViewController on iOS:

    CCDirector no longer supports device orientation. All autorotation and device orientation is handled by RootViewController now. Fortunately, [[UIDevice currentDevice] orientation] can be used in place of [[CCDirector sharedDirector] deviceOrientation]. The enums are the same, except that they begin with UI instead of CC.

    Forcing a specific orientation is a simple matter of returning YES only to the desired orientation in the RootViewController method shouldAutorotateToInterfaceOrientation.

    Choosing between Cocos2D v1.x & 2.x and Tips for updating to Cocos2D 2.0 at learn-cocos2d.com

    0 讨论(0)
提交回复
热议问题