cocos2d + GKMatchmakerViewController导致纵向模式

时间:2012-09-21 08:25:41

标签: cocos2d-iphone orientation gamekit

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

游戏仅面向横向。游戏套件也应如此。

当我提出用于配对的游戏套件模态视图控制器时,它会以横向显示。但是潜在的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

,则没有区别

1 个答案:

答案 0 :(得分:0)

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

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

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

然后方向在iOS6上完美运行,但在iOS6之前的iOS版本中,窗口大小的宽度和高度被颠倒,并导致游戏出现问题。我通过在运行我的普通场景之前添加一个空白场景来解决这个问题,因为在推动新场景时反向尺寸是自己修复的。从空白场景我跑[[CCDirector sharedDirector] replaceWithScene:[Game scene]];经过一段时间后,现在就可以了。

相关问题