6

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];
Arbel
  • 425
  • 8
  • 26
  • 1
    Thanks... I could not get my leaderboard or acheivements to dismiss and your EDIT above solved it for me! – jsherk Jul 09 '12 at 20:36

8 Answers8

2

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

SomaMan
  • 4,127
  • 1
  • 34
  • 45
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];
Arbel
  • 425
  • 8
  • 26
1

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];
RoLYroLLs
  • 3,113
  • 4
  • 38
  • 57
  • Good answer, but as of a recent iOS update (iOS 4?) you can now use blocks in this method to be a little less hacky: `[vc dismissViewControllerAnimated:(BOOL) completion:^(void)completion];` Ex: `[tempVC dismissViewControllerAnimated:YES completion:^{ [tempVC.view removeFromSuperview]; [tempVC release]; }];` – jmosesman Jul 03 '12 at 05:15
1

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
Jonny
  • 15,955
  • 18
  • 111
  • 232
  • 1
    You might want to make the same category on `GKGameCenterViewController`, `GKAchievementViewController` and the match making controller. – Jonny Jun 10 '13 at 06:36
1

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

Endre Olah
  • 875
  • 2
  • 9
  • 25
0

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

Ajit Satarkar
  • 717
  • 6
  • 20
0

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 {

lil Z
  • 1
  • Nope didnt work for me. Same issue. It appears the actual gameCenter view is landscape turned sideways. So I have the game in landscape with a leaderboard that shows up covering less than half the screen and extends beyond the screen. (Not sure if that makes any sense?) I am at a complete loss. – Arbel Nov 07 '10 at 05:26
-1

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.

Mr. Berna
  • 10,525
  • 1
  • 39
  • 42
  • So the one in games like Angry Birds is completely custom? Im not sure I quite understand. – Arbel Nov 01 '10 at 13:02
  • Angry Birds uses the Crystal SDK for its leaderboard. http://www.crystalsdk.com/ – Mr. Berna Nov 01 '10 at 13:19
  • Hmmm it appears this isn't entirely correct, unless you are talking about something else. After some fiddling around with the Cocos2d default rotations, I got the leaderboard to properly display in landscape mode. However my UIScrollView on the next scene was improperly displaying. No clue what is going on. – Arbel Nov 02 '10 at 10:31
  • How'd you manage to get the leaderboard to display in landscape mode? – jtalarico Nov 14 '10 at 00:00
  • It has something to do with Cocos2d auto-rotation. If I use the CCDirector autorotation, it launches the leaderboard in landscape. However, once dismissed I have other issues, like multi-touch not working anymore. If I use the default UIView rotation, the leaderboard is launched in portrait but turned sideways. No rotation efforts I make change it. – Arbel Nov 15 '10 at 15:10