Game Center - Orientation

Cocos2d Version: v0.99.04

I am adding Game Center to my current application and I found the code to open the GKMatchmakerViewController. It seems that it works well, except when it deviates, it changes the orientation in the simulator to a portrait. The game only works in the landscape. I turn the device back to landscape and all cocos2d scenes still work fine, but if I open a warning or picketer, they will open in portrait mode. I can open and close scenes, but now they will show this behavior. This also happens using a real device.

// *.h UIViewController *tempVC; // *.m // Open GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease]; request.minPlayers = 2; request.maxPlayers = 2; GKMatchmakerViewController *mmvc = [[[GKMatchmakerViewController alloc] initWithMatchRequest:request] autorelease]; mmvc.matchmakerDelegate = self; tempVC=[[UIViewController alloc] init]; [[[CCDirector sharedDirector] openGLView] addSubview:tempVC.view]; [tempVC presentModalViewController: mmvc animated: YES]; // Close [tempVC dismissModalViewControllerAnimated:YES]; [tempVC.view removeFromSuperview]; [tempVC release]; 

As soon as I click rejectModalViewControllerAnimated, this will happen when the simulator rotates.

Thanks in advance for your help.

+4
source share
2 answers

I had the same problem (not using cocos2d) and I solved it by subclassing the UIViewController that Game Center is attached to:

 @interface GameCenterViewController : UIViewController { } -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation; @end @implementation GameCenterViewController - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { // Does it match my screenOrientation? if (sceneOrientation == (UIDeviceOrientation)toInterfaceOrientation) return YES; return NO; } @end 
0
source

Put this in AppDelegate.m before @implementation

 @interface UINavigationController (Private) - (NSUInteger)supportedInterfaceOrientations; - (BOOL)shouldAutorotate; @end @implementation UINavigationController (Private) - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscape; } - (BOOL)shouldAutorotate { return YES; } @end 
0
source

All Articles