使用 GKLeaderboardViewController 时的方向问题
不幸的是,我不太了解 UIViewController,也不太了解它们如何与 cocos2d 场景相结合。不过,我能够在 iPhone 上成功地在我的 cocos2d(仅限横向)游戏之上加载标准 Game Center 排行榜视图。但是,我的游戏是一款通用应用程序,当我在 iPad 上尝试时,游戏中心视图以纵向加载,大约是应有尺寸的一半(仅填充屏幕的四分之一),并且不居中。当我旋转设备时,Game Center 视图将自身定向为横向,但实际上会被拉伸,看起来不是为横向视图中的 iPad 设计的。
有人有什么建议吗?
- (void) showLeaderboard
{
if(![MyAppDelegate isGameCenterAPIAvailable])
return;
if ([GKLocalPlayer localPlayer].isAuthenticated == YES)
{
CGSize screenSize = [[UIScreen mainScreen] bounds].size;
tempVC = [[RootViewController alloc] init];
GKLeaderboardViewController *leaderboard = [[[GKLeaderboardViewController alloc] init] autorelease];
if (leaderboard != NULL)
{
leaderboard.leaderboardDelegate = self;
[[[CCDirector sharedDirector] openGLView] addSubview:tempVC.view];
// Pause game
[[CCDirector sharedDirector] pause];
[tempVC presentModalViewController:leaderboard animated: NO];
leaderboard.view.transform = CGAffineTransformMakeRotation(CC_DEGREES_TO_RADIANS(0.0f));
[leaderboard.view setCenter:CGPointMake(screenSize.height/2, screenSize.width/2)];
leaderboard.modalPresentationStyle = UIModalPresentationCurrentContext;
}
}
}
- (void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController
{
[tempVC dismissModalViewControllerAnimated: YES];
[tempVC.view.superview removeFromSuperview];
[tempVC release];
tempVC = nil;
// Resume game
[[CCDirector sharedDirector] resume];
}
Unfortunately, I don't understand UIViewControllers very well, nor do I understand exactly how they mesh with cocos2d scenes. However, I am able to load a standard Game Center leaderboard view on top of my cocos2d (landscape-only) game successfully on the iPhone. But, my game is a universal app and when I try it on iPad, the Game Center view loads in portrait orientation, is about half the size it should be (fills up only one quarter of the screen), and is not centered. When I rotate the device, the Game Center view orients itself to landscape but gets really stretched out and looks like it wasn't designed for iPad in landscape view.
Does anyone have any advice?
- (void) showLeaderboard
{
if(![MyAppDelegate isGameCenterAPIAvailable])
return;
if ([GKLocalPlayer localPlayer].isAuthenticated == YES)
{
CGSize screenSize = [[UIScreen mainScreen] bounds].size;
tempVC = [[RootViewController alloc] init];
GKLeaderboardViewController *leaderboard = [[[GKLeaderboardViewController alloc] init] autorelease];
if (leaderboard != NULL)
{
leaderboard.leaderboardDelegate = self;
[[[CCDirector sharedDirector] openGLView] addSubview:tempVC.view];
// Pause game
[[CCDirector sharedDirector] pause];
[tempVC presentModalViewController:leaderboard animated: NO];
leaderboard.view.transform = CGAffineTransformMakeRotation(CC_DEGREES_TO_RADIANS(0.0f));
[leaderboard.view setCenter:CGPointMake(screenSize.height/2, screenSize.width/2)];
leaderboard.modalPresentationStyle = UIModalPresentationCurrentContext;
}
}
}
- (void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController
{
[tempVC dismissModalViewControllerAnimated: YES];
[tempVC.view.superview removeFromSuperview];
[tempVC release];
tempVC = nil;
// Resume game
[[CCDirector sharedDirector] resume];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请查看在 Cocos2d 应用程序中实现 iAds。
在本教程中,将Subview UIView对象添加到RootViewController.view(即cocos2d应用程序模板中),而不是EAGLView。
Please take a look at Implementing iAds in Cocos2d Application.
In this tutorial, addSubview UIView object to RootViewController.view, that is in the cocos2d application template, instead of EAGLView.