2012-04-29 88 views
1

我正在嘗試將領導委員會與我的iOS遊戲整合。iOS排行榜遊戲中心

我看到GKScore類需要一個類別,但是,我只有一個排行榜。我沒有在任何地方看到字段類別。我有本地化的領導委員會ID,領導委員會參考名稱和領導委員會名稱。我使用哪一個,如果有的話?

我提交了兩個帳戶的分數,但是,我從來沒有在排行榜上看到任何分數。我正在使用模擬器。

+0

您正在使用模擬器。 iOS沒有模擬器。 (我試圖編輯你的問題,但編輯太小而無法接受,我沒有發現任何值得更正的內容:P) – 2012-05-30 09:19:57

回答

3

首先,不要使用模擬器。如果可以的話,請使用設備,因爲許多功能(如向遊戲中心提交分數)在模擬器上不起作用。您是否嘗試記錄嘗試分數報告返回的錯誤?這會給你更多關於未來困難的細節。要回答您的問題,請使用排行榜ID作爲類別。這裏是你可以用它來提交分數類別的樣本函數:

定義在頭文件中的isGameCenterAvailable布爾和使用下面的代碼設置它的值:

Class gameKitLocalPlayerClass = NSClassFromString(@"GKLocalPlayer");   
bool isLocalPlayerAvailable = (gameKitLocalPlayerClass != nil);  

// Test if device is running iOS 4.1 or higher 
NSString* reqSysVer = @"4.1"; 
NSString* currSysVer = [[UIDevice currentDevice] systemVersion]; 
bool isOSVer41 = ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending); 

isGameCenterAvailable = (isLocalPlayerAvailable && isOSVer41); 
NSLog(@"GameCenter available = %@", isGameCenterAvailable ? @"YES" : @"NO"); 

使用這種方法提交的分數:

-(void) submitScores:(int64_t)score category:(NSString*)category { 

    if (!isGameCenterAvailable){ 
     return; 
    } 

    GKScore* gkScore = [[[GKScore alloc] initWithCategory:category] autorelease]; 
    gkScore.value = score; 

    [gkScore reportScoreWithCompletionHandler:^(NSError* error) { 
     bool success = (error == nil); 
     if(!success){ 
      NSLog(@"Error Reporting High Score: %@", [[error userInfo] description]); 
     } 
     [delegate onScoresSubmitted:success]; 
    }]; 
} 

此代碼由Steffen Itterheim撰寫,他撰寫了一本關於cocos2d遊戲開發的書。這裏是他和他的許多其他產品的鏈接:http://www.learn-cocos2d.com/

+0

感謝您的代碼!我也發現這有幫助:http://www.cocos2d-iphone.org/forum/topic/20998 – 2012-04-29 15:10:02

相關問題