【问题标题】:cocos2d + GKMatchmakerViewController causes portrait modecocos2d + GKMatchmakerViewController 导致竖屏模式
【发布时间】:2012-09-25 19:23:38
【问题描述】:

我正在一个 cocos2d 游戏项目中实现 Game Kit。

游戏仅横向。 gamekit 也应该如此。

当我展示用于匹配的 gamekit 模态视图控制器时,它以横向显示。但是底层的 cocos2d CCLayer 变成了纵向。

rootViewContollers 定位代码如下所示:

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

//
// There are 2 ways to support auto-rotation:
//  - The OpenGL / cocos2d way
//   - Faster, but doesn't rotate the UIKit objects
//  - The ViewController way
//  - A bit slower, but the UiKit objects are placed in the right place
//

#if GAME_AUTOROTATION==kGameAutorotationNone
//
// EAGLView won't be autorotated.
// Since this method should return YES in at least 1 orientation,
// we return YES only in the Portrait orientation
//
return ( interfaceOrientation == UIInterfaceOrientationPortrait );

#elif GAME_AUTOROTATION==kGameAutorotationCCDirector
//
// EAGLView will be rotated by cocos2d
//
// Sample: Autorotate only in landscape mode
//
if( interfaceOrientation == UIInterfaceOrientationLandscapeLeft ) {
    [[CCDirector sharedDirector] setDeviceOrientation: kCCDeviceOrientationLandscapeRight];
} else if( interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
    [[CCDirector sharedDirector] setDeviceOrientation: kCCDeviceOrientationLandscapeLeft];
}

// Since this method should return YES in at least 1 orientation,
// we return YES only in the Portrait orientation
return ( UIInterfaceOrientationIsLandscape(interfaceOrientation) );

#elif GAME_AUTOROTATION == kGameAutorotationUIViewController
//
// EAGLView will be rotated by the UIViewController
//
// Sample: Autorotate only in landscpe mode
//
// return YES for the supported orientations

return ( UIInterfaceOrientationIsLandscape( interfaceOrientation ) );

#else
#error Unknown value in GAME_AUTOROTATION

#endif // GAME_AUTOROTATION


// Shold not happen
return NO;
}

如果我将 GAME_AUTOROTATION 定义为 kGameAutorotationUIViewController 或 kGameAutorotationCCDirector 或 kGameAutorotationNone 没有区别

【问题讨论】:

    标签: cocos2d-iphone orientation gamekit


    【解决方案1】:

    所以我相信我已经找到了解决办法。

    在我的 AppDelegate 中,我进行了以下更改:

    //[window addSubview: viewController.view];
    [window setRootViewController:viewController];
    

    然后方向在 iOS6 上完美运行,但在 iOS6 之前的 iOS 版本上,窗口大小的宽度和高度被颠倒了,并导致游戏出现问题。我通过在运行我的正常场景之前添加一个空白场景来解决这个问题,因为在推送新场景时反向大小是自行固定的。从我运行的空白场景 [[CCDirector sharedDirector] replaceWithScene:[Game scene]];延迟后,现在可以使用了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-25
      • 1970-01-01
      • 2016-02-27
      • 2020-04-13
      相关资源
      最近更新 更多