Sunday, August 19, 2012

Game Center Leaderboard Dismissal on iPad vs. iPhone

A random piece of knowledge I send off to you for whom it may help.

I used Cocos2d and Ganbaru Game's Game Center helper to integrate Game Center into Dead End, an iOS game of mine.

However, upon converting the game to Universal, I found two problems.

1. GameCenter wouldn't pop up on iPad.
To resolve this, you have to change the modalPresentationStyle for your leaderboard.  The default does not work on iPad.

So this is my showLeaderboard code, with an added line for iPad/iPhone integration.
- (void)showLeaderboardForCategory:(NSString *)category
    if (hasGameCenter)
        GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];
        if (leaderboardController != nil)
            myViewController = [[UIViewController alloc] init];
            leaderboardController.leaderboardDelegate = self;
            leaderboardController.category = category;
            leaderboardController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

            if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
                leaderboardController.modalPresentationStyle = UIModalPresentationFullScreen;
                leaderboardController.modalPresentationStyle = UIModalPresentationFormSheet;
            [[[[CCDirector sharedDirector] openGLView] windowaddSubview:myViewController.view];
            [myViewController presentModalViewController:leaderboardController animated:YES];
        [leaderboardController release];

2. When I was dismissing the leaderboard on iPad, touch controls stopped working.

On iPhone/iPod, the dismissal code looked like:
- (void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController
    [myViewController dismissModalViewControllerAnimated:YES];
    [myViewController.view.superview removeFromSuperview];//I added this to Ganbaru's code
    [myViewController release];

On iPad, however, instead of [myViewController.view.superview removeFromSuperview], it should only be [myViewController.view removeFromSuperview].  I'm not sure why, but it works for me.

Thus, to get leaderboard dismissal to work on both iPhone AND iPad, the full code should be:
- (void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController
    [myViewController dismissModalViewControllerAnimated:YES];

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
        [myViewController.view.superview removeFromSuperview];
        [myViewController.view removeFromSuperview];
    [myViewController release];

Hope this is useful for someone!

Tuesday, January 24, 2012


I work in a youth homeless shelter once a week, and I do it as much for myself as for the kids. These are 18-25 year olds. They are officially adults, but this shelter was started because these poor castaways would otherwise go from foster homes and under-age care one day to rough homeless shelters and rougher streets the next. We consider them adults, but tell me that upon graduating high-school you were ready to go live in a shelter with grizzled 50 year old homeless folk.

There's a gradient to our maturity. Some of us never learn any, others learn too much. So many of these youth are struggling just to get beyond an immature and volatile world that left them in poor health and poor preparation for life. The life they know is beyond me to understand. I've been lucky. There's a gradient of people that are in the shelter. There are youth who are escaping abuse at home, others struggling with drugs, some whose homes were too poor to support them, still others who have never known a real home. There are those who are beating the challenges, those who may beat them, and others who will lose. There are more than a fair share struggling with mental health problems. There are youth I enjoy seeing, others I would have a hard time tolerating, were it my job to maintain order in the shelter.

Far above these struggles, and yet just as important, are high level government decisions, high level business and world market struggles. There are people who want laws to control everything we do. Others want laws to control none of what we do. And still more who see decisions one way over here and another over there. There are decisions about who to hire, who to fire, who to support, who to let down.

Don't mistake life for anything but a gradient. I learned that in art the use of pure black and the use of pure white are rarely desired. Give some texture, throw in some tint of a color. Life is better this way if we accept that our beauty and strength lies in the texture, the variety, and that such variety should be embraced.

And that's why, when we look at our troubles, at our struggles, the solution lies not in changing the individuals, because we will never win that battle, but in changing the rules of how we operate as a society. We need to change the rules that help people, that raise kids. We need to fix how we operate, and accept and embrace variety and diversity. We know that things are never black and white, so we need to keep working on the rules. And we will never finish fixing and refining, because the system always changes. But as long as we look at the system as much and more than we attack individual cases, then we might make progress.

I look at the youth in the shelter, and I know with a fairly heady certainty that we needed to help these kids long ago. We needed to feed some of them better food, we needed to teach others better discipline, we needed to find many of them better parents. But they are going to struggle now because their world's rules were defined and built long ago. There are billions yet to come, why not change the game rather than trying to mess with the pieces?