Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cocos 2d and Game Center (Leaderboard issue)

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];
like image 274
Arbel Avatar asked Nov 01 '10 10:11

Arbel


3 Answers

=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.

like image 92
SomaMan Avatar answered Oct 21 '22 23:10

SomaMan


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];
like image 30
Arbel Avatar answered Oct 21 '22 22:10

Arbel


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

like image 1
Endre Olah Avatar answered Oct 21 '22 21:10

Endre Olah