Question

I cant really find my answer after browsing (not a lot of topics on cocos2d with game center)

I currently have my sandbox game center set up and I am able to authenticate, but when I create the leaderboard it is launched sideways in portrait I assume. Tried rotating the view but nothing. My game runs only in landscape mode. I am running beta 3 0.99.5. Here is my code for reference.

tempVC = [[RootViewController alloc] init];

GKLeaderboardViewController *leaderboardController = [[[GKLeaderboardViewController alloc] init] autorelease];

if (leaderboardController != nil)
{
    leaderboardController.leaderboardDelegate = self;
    [[[CCDirector sharedDirector] openGLView] addSubview:tempVC.view];
    [tempVC presentModalViewController:leaderboardController animated:YES];
}

Really would appreciate any help. Getting no response from the cocos2d board.

EDIT:

Fixed by changing auto-rotation to CCDirector. Furthermore, I had issues with losing multi-touch functionality after showing gamecenter. The dismissal for the board should use this:

[tempVC dismissModalViewControllerAnimated:YES];
[tempVC.view.superview removeFromSuperview];
Was it helpful?

Solution 2

Fixed by changing auto-rotation to CCDirector. Furthermore, I had issues with losing multi-touch functionality after showing gamecenter. The dismissal for the board should use this:

[tempVC dismissModalViewControllerAnimated:YES];
[tempVC.view.superview removeFromSuperview];

OTHER TIPS

=I had this problem and was tearing my hair out for days, but I eventually got it to work perfectly in landscape mode, no matter what way the user is holding the phone. It's a bit weird, and if anyone knows better please let me know!

1 - I have to have the view (of the controller which calls the leaderboard) in portrait, in my case done in IB

2 - It only works if you support the portrait orientation (even if it looks like landscape) -

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

3 - You then need to resize & rotate the leaderboard -

[self presentModalViewController: leaderboardController animated: YES];

leaderboardController.view.transform = CGAffineTransformMakeRotation(CC_DEGREES_TO_RADIANS(0.0f));
leaderboardController.view.bounds = CGRectMake(0, 0, 480, 320);
leaderboardController.view.center = CGPointMake(240, 160);

4 - Hey presto! It's working fine. Hope it works for you too.

if it might help, I have found that simply removing the GKLeaderboard from the superview is not really enough, so after you use

[tempVC.view.superview removeFromSuperview];

you should also use

[tempVC release];

Without this the GKLeaderboardViewController is doing some weird things, like after the second call it is not auto rotating itself in the view.

I hope it help

Using this on cocos2d v1.0.1, latest stable version as of Apr 19th, 2012, this actually doesn't allow the vc to disappear animated. Probably running this instead:

[tempVC dismissModalViewControllerAnimated:YES];
[[[tempVC view] superview] performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1.2];
[tempVC performSelector:@selector(release) withObject:nil afterDelay:1.3];

The correct was is to implement and include this category:

.h

#import <GameKit/GameKit.h>

@interface GKLeaderboardViewController (additions)
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation;
-(NSUInteger)supportedInterfaceOrientations;
@end

.m

#import "GKLeaderboardViewController+additions.h"

@implementation GKLeaderboardViewController (additions)
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}
-(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}
@end

Had the same problem with GC launching in portrait on iPad when my Cocos2D game was in landscape. Fixed this by deriving my GameKit controller from rootViewController instead of UIViewController.

@interface GCController :RootViewController {

Once i was having the same problem, I followed the Connor Denman's blog which works for me Here is the link
http://connordenman.com/post/15554858770/presenting-a-modal-view-controller-in-cocos2d-iphone

A GKLeaderboardViewController is used to display the default leaderboard, which is a portrait only view. To display a landscape leaderboard, you have to implement your own custom leaderboard view.

Edit: Since the initial writing of this, GKLeaderboardViewController has been improved to work just fine in any orientation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top