6

浏览后我真的找不到我的答案(cocos2d with game center 上的主题不多)

我目前已经设置了我的沙盒游戏中心并且我能够进行身份验证,但是当我创建排行榜时,我假设它是横向启动的。尝试旋转视图但没有。我的游戏只在横向模式下运行。我正在运行 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];
4

8 回答 8

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 - 嘿,快!它工作正常。希望它也适合你。

于 2011-02-22T11:18:16.833 回答
2

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

[tempVC dismissModalViewControllerAnimated:YES];
[tempVC.view.superview removeFromSuperview];
于 2011-11-07T00:15:35.513 回答
1

如果它可能有帮助,我发现仅仅从超级视图中删除 GKLeaderboard 是不够的,所以在你使用之后

[tempVC.view.superview removeFromSuperview];

你也应该使用

[tempVC 发布];

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

我希望它有帮助

于 2012-03-26T21:47:44.597 回答
1

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

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

于 2012-04-19T23:23:40.600 回答
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
于 2013-06-10T06:34:09.973 回答
0

当我的 Cocos2D 游戏在横向时,GC 在 iPad 上纵向启动时遇到了同样的问题。通过从 rootViewController 而不是 UIViewController 派生我的 GameKit 控制器来解决此问题。

@interface GCController :RootViewController {

于 2010-11-07T02:47:14.680 回答
0

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

于 2012-09-26T11:00:55.433 回答
-1

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

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

于 2010-11-01T12:52:12.213 回答