Cocos 2d和游戏中心(排行榜问题)

时间:2010-11-01 10:58:20

标签: iphone objective-c uiview cocos2d-iphone game-center

我无法在浏览后找到我的答案(不是很多关于cocos2d与游戏中心的主题)

我目前已经设置了沙箱游戏中心并且我能够进行身份验证,但是当我创建排行榜时,它会以纵向方式侧向启动我假设。尝试旋转视图,但没有。我的游戏只能在横向模式下运行。我正在运行beta 3 0.99.5。这是我的代码供参考。

tempVC = [[RootViewController alloc] init];

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

if (leaderboardController != nil)
{
    leaderboardController.leaderboardDelegate = self;
    [[[CCDirector sharedDirector] openGLView] addSubview:tempVC.view];
    [tempVC presentModalViewController:leaderboardController animated:YES];
}

真的很感激任何帮助。没有得到cocos2d董事会的答复。

编辑:

通过将自动旋转更改为CCDirector来修复。此外,在显示游戏中心后,我遇到了丢失多点触控功能的问题。解雇董事会应该使用:

[tempVC dismissModalViewControllerAnimated:YES];
[tempVC.view.superview removeFromSuperview];

8 个答案:

答案 0 :(得分:2)

=我遇到了这个问题并且已经把头发撕掉了好几天,但是无论用户拿着手机的方式如何,我最终都能在横向模式下完美地工作。这有点奇怪,如果有人知道更好,请告诉我!

1 - 我必须有(纵向调用排行榜的控制器)视图,我的情况是在IB中完成

2 - 仅当您支持纵向方向(即使它看起来像风景)时才有效 -

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

3 - 然后你需要调整大小&旋转排行榜 -

[self presentModalViewController: leaderboardController animated: YES];

leaderboardController.view.transform = CGAffineTransformMakeRotation(CC_DEGREES_TO_RADIANS(0.0f));
leaderboardController.view.bounds = CGRectMake(0, 0, 480, 320);
leaderboardController.view.center = CGPointMake(240, 160);

4 - 嘿presto!它工作正常。希望它也适合你。

答案 1 :(得分:2)

通过将自动旋转更改为CCDirector来修复。此外,在显示游戏中心后,我遇到了丢失多点触控功能的问题。解雇董事会应该使用:

[tempVC dismissModalViewControllerAnimated:YES];
[tempVC.view.superview removeFromSuperview];

答案 2 :(得分:1)

如果它有帮助,我发现只是从superview中删除GKLeaderboard是不够的,所以在你使用之后

[tempVC.view.superview removeFromSuperview];

你也应该使用

[tempVC发布];

如果没有这个,GKLeaderboardViewController会做一些奇怪的事情,比如在第二次调用之后它不会在视图中自动旋转。

我希望它有所帮助

答案 3 :(得分:1)

在2012年4月19日的最新稳定版cocos2d v1.0.1上使用它,这实际上不允许vc消失动画。可能会改为运行:

[tempVC dismissModalViewControllerAnimated:YES];
[[[tempVC view] superview] performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1.2];
[tempVC performSelector:@selector(release) withObject:nil afterDelay:1.3];

答案 4 :(得分:1)

正确的方法是实施并包含以下类别:

·H

#import <GameKit/GameKit.h>

@interface GKLeaderboardViewController (additions)
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation;
-(NSUInteger)supportedInterfaceOrientations;
@end

的.m

#import "GKLeaderboardViewController+additions.h"

@implementation GKLeaderboardViewController (additions)
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}
-(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}
@end

答案 5 :(得分:0)

当我的Cocos2D游戏处于横向状态时,在iPad上以纵向方式启动GC会出现同样的问题。通过从rootViewController而不是UIViewController派生我的GameKit控制器来解决这个问题。

@interface GCController:RootViewController {

答案 6 :(得分:0)

一旦我遇到同样的问题,我就跟着Connor Denman的博客,这对我有用。这里是链接
 http://connordenman.com/post/15554858770/presenting-a-modal-view-controller-in-cocos2d-iphone

答案 7 :(得分:-1)

GKLeaderboardViewController用于显示默认排行榜,这是一个仅限纵向视图。要显示横向排行榜,您必须实现自己的自定义排行榜视图。

编辑:自从最初编写本文以来,GKLeaderboardViewController已经过改进,可以在任何方向上正常工作。

相关问题