Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cocos2D & Leaderboard

I am dealing with a Cocos2D iPhone app with the Game Center Leaderboard. In this app the user has to draw lines in a landscape mode (the iPhone is horizontal). It happens then that the touch may begin outside the screen (in the left side near the microphone) and continue inside the screen. The app correctly starts drawing things as soon as the finger enters in the screen framework. However if I show the view with the leaderboard (that is actually correctly depicted) and I come back to the game the app stops handling touches that begin outside of the screen. It actually stops handling only those starting on the top of the screen as if there is a line of pixel at the top that are not considered.

I started the leaders board this way:

- (void) showLeaderboard
{
   GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];
if (leaderboardController != nil){
    tempVC=[[UIViewController alloc] init] ;
    leaderboardController.leaderboardDelegate = self;
    [[[CCDirector sharedDirector] openGLView] addSubview:tempVC.view];

    [tempVC presentModalViewController:leaderboardController animated:YES];
    tempVC.view.transform = CGAffineTransformMakeRotation(CC_DEGREES_TO_RADIANS(0.0f));
    tempVC.view.bounds = CGRectMake(0, 0, 480, 320);
    tempVC.view.center = CGPointMake(240, 160);

    [leaderboardController release];
}
}

and release it this way:

-(void) leaderboardViewControllerDidFinish: (GKLeaderboardViewController *) viewController{
[tempVC dismissModalViewControllerAnimated:YES];
[tempVC.view.superview removeFromSuperview];
[tempVC.view removeFromSuperview];

[tempVC release];


}
like image 710
Andrea Sindico Avatar asked Nov 14 '22 09:11

Andrea Sindico


1 Answers

Well, your problem sounds a bit nasty, and all I can provide is a guess to where the problem might be..

I have a Cocos2d Game with Leaderboards integrated, and the touches are working perfectly, so let me give you the details on how I add the leaderboard viewController, and you might want to try it out:

Note:It is generally better to use UIKit elements in cocos2d using the RootViewController, added in v0.99.5.

//Action method invoked upon pressing the "Show LeaderBoards button"
-(void)showLeaderboardButtonClicked {
    [gameCenterHandler showLeaderboard];
}

//Inside the GameCenter Handler:
-(void) showLeaderboard {
    if (isGameCenterAvailable == NO) {
        return;
    } else if (![[GKLocalPlayer localPlayer] isAuthenticated]) {
        [self authenticateLocalPlayer];
    } else {
        GKLeaderboardViewController* leaderboardVC = [[[GKLeaderboardViewController alloc] init] autorelease];
        if (leaderboardVC != nil) {
            leaderboardVC.leaderboardDelegate = self;
            [rootVC presentModalViewController:leaderboardVC animated:YES];
        }
}

-(void) leaderboardViewControllerDidFinish:(GKLeaderboardViewController*)viewController {
    [rootVC dismissModalViewControllerAnimated:YES];
}

Where rootVC is in AppDelegate.h:

    RootViewController  *viewController;
like image 195
Mazyod Avatar answered Nov 16 '22 03:11

Mazyod