2010-11-01 72 views
6

我真的不能找到瀏覽後,我的答案(而不是在cocos2d的很多話題與遊戲中心)科科斯2d和遊戲中心(排行榜問題)

我現在有我的沙盤遊戲中心的成立,我能進行身份驗證,但是當我創建排行榜時,它會在我假設的肖像中橫向展開。試圖旋轉視圖,但沒有。我的遊戲只在橫向模式下運行。我正在運行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]; 
+1

謝謝......我無法讓我的排行榜或成績解僱,並且您的編輯解決了我的問題! – jsherk 2012-07-09 20:36:17

回答

2

通過將自動旋轉更改爲CCDirector進行修正。此外,在顯示遊戲中心後,我遇到了失去多點觸控功能的問題。該電路板的解僱應使用此:

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

提供我的評論作爲答案...見下文。 – RoLYroLLs 2012-04-19 23:23:13

+0

「通過改變自動旋轉到CCDirector來固定」這是什麼意思? – Jonny 2013-06-10 06:17:40

-1

甲GKLeaderboardViewController用於顯示默認的排行榜,這是一個只肖像視圖。要顯示橫向排行榜,您必須實現自己的自定義排行榜視圖。

編輯:由於最初編寫這個,GKLeaderboardViewController已被改進,以在任何方向工作得很好。

+0

那麼像憤怒的小鳥這樣的遊戲是完全自定義的?我不知道我是否理解。 – Arbel 2010-11-01 13:02:12

+0

憤怒的小鳥將水晶SDK用於其排行榜。 http://www.crystalsdk.com/ – 2010-11-01 13:19:52

+0

謝謝你的回答 – Arbel 2010-11-01 13:55:49

0

當我的Cocos2D遊戲處於橫向模式時,在iPad上以縱向方式啓動時出現同樣的問題。通過從rootViewController而不是UIViewController派生我的GameKit控制器來解決這個問題。

@interface GCController:RootViewController的{

+0

不能爲我工作。同樣的問題。看起來實際的遊戲中心視圖橫向翻轉。所以我用橫向排列的遊戲排行榜顯示覆蓋不到屏幕的一半,並延伸到屏幕之外。 (不知道這是否有意義?)我完全失去了。 – Arbel 2010-11-07 05:26:29

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 - 變戲法似的!它工作正常。希望它也適用於你。

1

如果它可能會幫助,我發現,簡單地從上海華去除GKLeaderboard是不是真的不夠,所以你用

[tempVC.view後。superview removeFromSuperview];

,你也應該使用

[tempVC發佈];

如果沒有這個,GKLeaderboardViewController會做一些奇怪的事情,比如在第二次調用之後它不會自動在視圖中自動旋轉。

我希望它幫

1

上的cocos2d 1.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];

+0

好的答案,但是從最近的iOS更新(iOS 4?)開始,你現在可以在這個方法中使用塊來減少一點麻煩:'[vc dismissViewControllerAnimated:(BOOL)completion:^(void)completion];'Ex :[tempVC dismissViewControllerAnimated:YES completion:^ {tempVC.view removeFromSuperview]; [tempVC發佈]; }];' – jmosesman 2012-07-03 05:15:02

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 
+1

您可能希望在'GKGameCenterViewController','GKAchievementViewController'和匹配生成控制器上創建相同的類別。 – Jonny 2013-06-10 06:36:43