Cocos2D 与 Cocos2D排行榜

发布于 2025-01-08 20:16:24 字数 1206 浏览 5 评论 0原文

我正在处理带有游戏中心排行榜的 Cocos2D iPhone 应用程序。在这个应用程序中,用户必须在横向模式下画线(iPhone 是水平的)。然后,触摸可能会从屏幕外部(靠近麦克风的左侧)开始,并在屏幕内部继续。一旦手指进入屏幕框架,应用程序就会正确开始绘制内容。但是,如果我用排行榜显示视图(实际上正确描述)并且我返回游戏,则应用程序将停止处理从屏幕外部开始的触摸。它实际上停止只处理那些从屏幕顶部开始的像素,就好像顶部有一行像素没有被考虑一样。

我以这种方式启动领导板:

- (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];
}
}

并以这种方式发布:

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

[tempVC release];


}

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];


}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

贪恋 2025-01-15 20:16:24

好吧,你的问题听起来有点令人讨厌,我所能提供的只是猜测问题可能出在哪里。

我有一个集成了排行榜的 Cocos2d 游戏,并且触摸效果很好,所以让我向您详细介绍如何我添加了排行榜viewController,你可能想尝试一下:

注意:通常最好使用cocos2d中的UIKit元素使用RootViewController,添加在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];
}

其中 rootVC 位于 AppDelegate.h 中:

    RootViewController  *viewController;

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文