Having problems opening the Game Center UI

I have set up so that my app can connect to the Game Center. I followed this guide and had a C++ class wrapper to call them in my other classes. I’m using iPad (iOS 5.1), iPod Touch 4th Gen (iOS 5.1), and iPhone 4s and 3GS to test. It works fine on iPad devices but for some unknown reason, it does not on iPhone and iPod. It properly connects to the Sandbox but the UI is not shown, or rather, the UI is somewhere off-screen.

What happens on the iPhone is:

# If I’m not logged in and I access the Game Center, a login window appears. When I log in, nothing happens. However, the console says a view is added.
# If I’m logged in and I access the Game Center, nothing happens. However, the console says a view is added.
# If I access the Game Center before I get authenticated, the Game Center UI appears. However…
* The Game Center is in Landscape Mode (no problem there, since my app is in landscape) but the top bar (the bar with the DONE button) is placed as if the orientation is portrait.
* The whole UI is not shown, just ~30% of the screen.

This is how I launch the Game Center UI:

- (void)showLeaderboardForCategory:(NSString *)category
{
    // Only execute if OS supports Game Center & player is logged in
    if ( hasGameCenter )
    {
        // Create leaderboard view w/ default Game Center style
        GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];

        // If view controller was successfully created...
        if (leaderboardController != nil)
        {
            // Leaderboard config
            leaderboardController.leaderboardDelegate = self;   // The leaderboard view controller will send messages to this object
            leaderboardController.category = category;  // Set category here
            leaderboardController.timeScope = GKLeaderboardTimeScopeToday;  // GKLeaderboardTimeScopeToday, GKLeaderboardTimeScopeWeek, GKLeaderboardTimeScopeAllTime

            // Create an additional UIViewController to attach the GKLeaderboardViewController to
            myViewController = [[UIViewController alloc] initWithNibName:nil bundle:nil ];

            // Add the temporary UIViewController to the main OpenGL view
            // NOTE: This is the part that I think is the suspect. I am not sure if iPhones and iPods support EAGLView.
            [ [ EAGLView sharedEGLView ] addSubview:myViewController.view ];

            // Tell UIViewController to present the leaderboard
            [ myViewController presentModalViewController:leaderboardController animated:NO ];
            NSLog( @"Leaderboard opened." );
        }
    }
}

Any help is appreciated and thanks in advance.
Using OpenFeint is not an option.

Any help? I’ve done a few checks and tempVC is indeed inside EAGLView, but for some reason, nothing shows up on screen.

Anyone? :frowning:

Hey, I will check into this. I have implemented game Centre Successfully in a cocos2d-x project. I am not at my comp right now… so will get back to it by end of day

Thanks a lot bro. Meanwhile, let me edit my question to show what I’ve found out lately.

I fixed it now.

For anyone who’s wondering, what I did was use [ [ UIApplication sharedApplication ] keyWindow ] instead of [ EAGLView sharedEGLVew ]

Hello Lance
Could you post your Game Center UI wrapper code ? I am very appreciated. I have just finished the wrapper class for the Game Center (similar to the UIWebView that I posted previously), and I did not have time to backup, and my son drop my laptop and everything is gone and I do not want to re-write again.

Thanks
Dac

I followed this then created a new MM file to call the Obj-C codes using C++

Hello
Following your suggestion. It’s simpler than my previous version (having the GameCenter in the Cocos2d-x layer) and it works.

Here is the header file =
#ifndef CC_GAMECENTERBRIDE_H
#define CC_GAMECENTERBRIDE_H

#include “GameCommonDefine.h”

class GameCenterBridge
{
private:
static bool mAuthenticated;
public:
GameCenterBridge();
~GameCenterBridge();

static void authenticateLocalPlayer();
static void showLeaderBoard();
static void reportScore(int score);

};

#endif

= the mm
//
#include “GameCenterBridge.h”
#include “GameCenterManager.h”

#define kLeaderboardID @“M1”

bool GameCenterBridge::mAuthenticated =false;

GameCenterBridge::GameCenterBridge()
{
}

GameCenterBridge::~GameCenterBridge()
{

}

void GameCenterBridge::authenticateLocalPlayer()
{
if(mAuthenticated false)
{
[[GameCenterManager sharedGameCenterManager ]authenticateLocalPlayer];
mAuthenticated = true;
}
}

void GameCenterBridge::showLeaderBoard()
{
[[GameCenterManager sharedGameCenterManager ]showLeaderboardForCategory:kLeaderboardID ];
}

void GameCenterBridge::reportScore(int score)
{
[[GameCenterManager sharedGameCenterManager ]reportScore:score forCategory:kLeaderboardID];
}

Modification to the GameCenterManager.mm ==

  • (void)showLeaderboardForCategory:(NSString )category
    {
    // Only execute if OS supports Game Center & player is logged in
    if
    {
    // Create leaderboard view w/ default Game Center style
    GKLeaderboardViewController
    leaderboardController = [[GKLeaderboardViewController alloc] init];

// If view controller was successfully created…
if (leaderboardController != nil)
{
// Leaderboard config
leaderboardController.leaderboardDelegate = self; // The leaderboard view controller will send messages to this object
leaderboardController.category = category; // Set category here
leaderboardController.timeScope = GKLeaderboardTimeScopeAllTime; // GKLeaderboardTimeScopeToday, GKLeaderboardTimeScopeWeek, GKLeaderboardTimeScopeAllTime

// Create an additional UIViewController to attach the GKLeaderboardViewController to
myViewController = [[UIViewController alloc] init];

// Add the temporary UIViewController to the main OpenGL view
//[[[CCDirector sharedDirector] openGLView] addSubview:myViewController.view];
[[ [ UIApplication sharedApplication ] keyWindow ] addSubview:myViewController.view ];//modification
// Tell UIViewController to present the leaderboard
[myViewController presentModalViewController:leaderboardController animated:YES];
}
}
}

/***
Since this singleton is the GKLeaderboardViewControlerDelegage, it intercepts this method and removes the view
**/

  • (void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController
    {
    [viewController dismissModalViewControllerAnimated:NO];//modification
    [myViewController.view removeFromSuperview];
    [myViewController release];
    }