簡體   English   中英

iOS排行榜GameCenter

[英]iOS Leaderboard GameCenter

我正在嘗試將排行榜與我的iOS游戲集成。

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

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

首先,不要使用模擬器。 如果可以,請使用設備,因為許多功能(如向游戲中心提交分數)在模擬器上不起作用。 您是否嘗試記錄嘗試得分報告返回的錯誤? 這將為您提供有關未來困難的更多詳細信息。 要回答您的問題,請使用排行榜ID作為類別。 以下是可用於提交類別分數的示例函數:

在頭文件中定義isGameCenterAvailable bool並使用以下代碼設置其值:

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/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM