Home
Reviews
Forums
New Games
Podcast
• submit tip •
  #1  
Old 07-04-2012, 07:05 PM
Stafaa Stafaa is offline
Junior Member
 
Join Date: Dec 2011
Posts: 12
Default Trouble bringing up leaderboards with my code

I'm having trouble getting the leaderboards to show up in my game, short of my initial login, i have no idea if gamecenter is cooperating with my code. I prompt the leaderboards using a touch detect on some text, ala...

Quote:
leaderboard = [CCMenuItemFont itemFromString:@"Online Leaderboards" target:self selector:@selector(leaderboardCmd: )];
and...

Quote:
- (void) leaderboardCmd: (id) sender {

[self showLeaderboard];

}
Which then triggers...

Quote:
- (void) showLeaderboard {

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

if (leaderboardController != nil)
{
leaderboardController.category = @"highscores";
leaderboardController.timeScope = GKLeaderboardTimeScopeAllTime;
leaderboardController.leaderboardDelegate = self;
[self presentModalViewController: leaderboardController animated: YES];
}

}
The app simply crashes. It seems as though the app crashes when executing "presentModalViewController", which looks like a function of UIKit? The apple provided GKTapper code doesn't shed any light on how to properly implement this into a CCLayer.

Can anyone help? Or is there an existing example other than GKTapper?
Reply With Quote
  #2  
Old 07-04-2012, 07:36 PM
Nicor Nicor is offline
Junior Member
iPad 2, iOS 5.x
 
Join Date: Jul 2012
Location: Argentina
Posts: 17
Default

I think you are missing the leaderboardViewControllerDidFinish: method. One implementation (that I haven't checked) could be the following, although I had found one-liners as well:


-(void)leaderboardViewControllerDidFinishGKLeader boardViewController*)viewController{
CGRect frame = viewController.view.frame;
[UIView beginAnimations:@"curldoup" context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:.5];
[UIView setAnimationDidStopSelector:
@selector(animationDidStop:finished:context];
frame.origin.y = 480;
viewController.view.frame = frame;
[UIView commitAnimations];
}
Reply With Quote
  #3  
Old 07-05-2012, 09:26 AM
DemonJim's Avatar
DemonJim DemonJim is offline
Developer
iPhone 4, iOS 6.x
 
Join Date: Nov 2010
Location: UK
Posts: 366
Default

My guess would be that you are just missing the required delegate template in the .h header:

Code:
@interface MyVC : UIViewController <GKLeaderboardViewControllerDelegate> {

}
This delegate is required in any class that you assign to .leaderboardDelegate.
Reply With Quote
  #4  
Old 07-05-2012, 10:06 AM
u2elan's Avatar
u2elan u2elan is offline
Member
iPhone 5, iOS 6.x
 
Join Date: Nov 2010
Location: Portland, OR
Posts: 82
Default

You can't pop a UIViewController directly from a CCLayer, you need to do it from within the context of another UIViewController.

First, expose your RootViewController as a property from your AppDelegate:
@property (nonatomic, retain) RootViewController *viewController;

Then, import your AppDelegate in your CCLayer.h file.

Next:

GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];
leaderboardController.leaderboardDelegate = self;

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
RootViewController *vCont = appDelegate.viewController;
[vCont presentModalViewController:leaderboardController animated:YES];

[leaderboardController release];
Reply With Quote
  #5  
Old 07-05-2012, 09:26 PM
Stafaa Stafaa is offline
Junior Member
 
Join Date: Dec 2011
Posts: 12
Default

If i understand correctly, the leaderboard must be popped from a UIViewController?
Reply With Quote
  #6  
Old 07-05-2012, 09:45 PM
u2elan's Avatar
u2elan u2elan is offline
Member
iPhone 5, iOS 6.x
 
Join Date: Nov 2010
Location: Portland, OR
Posts: 82
Default

Correct. It's just like popping a modal view controller in UIKit.

There are a number of people who have written sample code for this and suggest using a temporary view controller, but I prefer to do this against my app's root view controller as that seems to yield better results when dealing with orientation changes.
Reply With Quote
  #7  
Old 07-08-2012, 03:23 AM
AgnesDev AgnesDev is offline
Member
iPhone 4, iOS 4.x
 
Join Date: Jan 2012
Location: Warsaw, Poland
Posts: 33
Default

I had very similar issue, but I found a simple solution, like this:

HighscoreScene.h:
Code:
@interface HighscoreScene : BaseScene <GKLeaderboardViewControllerDelegate>
{
(...)
}

(...)
- (void) showLeaderboard;
- (void) leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)leaderboardVC;
(...)
(where BaseScene inherits from NSObject)

HighscoreScene.m:
Code:
- (void) showLeaderboard
{
    UIWindow* window = [UIApplication sharedApplication].keyWindow;
	
    GKLeaderboardViewController *leaderboardVC = [[GKLeaderboardViewController alloc] init];   
    if (leaderboardVC != nil)
    {
	leaderboardVC.leaderboardDelegate = self;
		
	UIViewController *vc = [[UIViewController alloc] init];
	[window addSubview: vc.view];
        [vc presentModalViewController: leaderboardVC animated: YES];
    }
}

- (void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)leaderboardVC
{
    [leaderboardVC dismissModalViewControllerAnimated:YES];
    [leaderboardVC.view.superview removeFromSuperview];
    [leaderboardVC release];
}

-=Agnes=-
Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


iPhone Game Reviews | iPhone Apps

All times are GMT -5. The time now is 09:35 AM.