Cocos 2d and Game Center (Leaderboard Edition)

I can’t find my answer after watching (not many themes on cocos2d with game center)

I currently have my sandbox game center installed and I can authenticate, but when I create the leaderboard it starts sideways in the portrait, I guess. I tried to rotate the view, but nothing. My game only works in landscape mode. I am launching beta version 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]; } 

In fact, any help would be appreciated. Receiving a response from the cocos2d board.

EDIT:

Fixed by changing auto-rotation to CCDirector. In addition, I had problems with the loss of multitouch functions after showing the gamecenter. Dismissal for advice should use this:

 [tempVC dismissModalViewControllerAnimated:YES]; [tempVC.view.superview removeFromSuperview]; 
+6
objective-c iphone uiview cocos2d-iphone game-center
source share
8 answers

Fixed by changing auto-rotation to CCDirector. In addition, I had problems with the loss of multitouch functions after showing the gamecenter. Dismissal for advice should use this:

 [tempVC dismissModalViewControllerAnimated:YES]; [tempVC.view.superview removeFromSuperview]; 
+2
source share

= I had this problem and tormented my hair for a long time, but in the end I got it to work perfectly in landscape mode, regardless of how the user holds the phone. This is a little strange, and if anyone knows better, please let me know!

1 - I have to have a representation (of the controller that calls the leaderboard) in the portrait, in my case, done in IB

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

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

3 - Then you need to resize and 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 works great. Hope this works for you too.

+2
source share

if this can help, I found that simply removing GKLeaderboard from the supervisor is not enough, so after using

[tempVC.view.superview removeFromSuperview];

you should also use

[tempVC release];

Without this, the GKLeaderboardViewController does some strange things, for example, after the second call, it does not automatically rotate in the view.

I hope this helps

+1
source share

Using this on cocos2d v1.0.1, the latest stable version since April 19, 2012, it actually prevents vc from disappearing animated. Probably do the following instead:

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

It was more correct 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 
+1
source share

There was the same issue with running GC in portrait on iPad when my Cocos2D game was in the landscape. This is fixed by outputting my GameKit controller from rootViewController instead of UIViewController.

@interface GCController: RootViewController {

0
source share

As soon as I had the same problem, I followed Connor Denman's block, which works for me. Here is the link
http://connordenman.com/post/15554858770/presenting-a-modal-view-controller-in-cocos2d-iphone

0
source share

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

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

-one
source share

All Articles