我正在尝试将排行榜与我的iOS游戏集成在一起。
我看到GKScore类需要一个类别,然而,我只有一个排行榜。我在任何地方都看不到字段类别。我有一个引导板ID、一个引导板引用名称和一个本地化的引导板名称。如果有的话,我应该使用哪一个?
我提交了两个帐户的分数,然而,我从未在排行榜上看到任何分数。我正在使用模拟器。
发布于 2012-04-29 10:16:23
首先,不要使用模拟器。如果可以,请使用设备,因为许多功能,如将分数提交到游戏中心,在模拟器上不起作用。您是否尝试记录由尝试的分数报告返回的错误?这将为您提供有关未来困难的更多详细信息。要回答您的问题,请使用排行榜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/
https://stackoverflow.com/questions/10369033
复制相似问题