0

我正在 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 没有区别

4

1 回答 1

0

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

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

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

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

于 2012-09-25T11:23:38.220 回答