我正在使用此库在我的应用中报告分数和成就:https://github.com/csddavies/DDGameKitHelper
因此,在我的应用中,我会报告百分比,让用户知道他们与完成成就有多接近。所以我做了这样的事情:
[[DDGameKitHelper sharedGameKitHelper] reportAchievement:@"Achievement1" percentComplete:totalTime/300.0f];
然而,似乎报道我完成了成就,“成就1”,尽管我没有。当我NSLog totalTime/300.0f
时,我得到一个像 0.563 和 NOT 100 的值。
所以现在我认为reportAchievement
方法一定有问题,所以我看了它,我不确定会出现什么问题。以下是与reportAchievement
相关的方法:
-(void) reportAchievement:(NSString*)identifier percentComplete:(float)percent
{
if (isGameCenterAvailable == NO)
return;
GKAchievement* achievement = [self getAchievement:identifier];
if (achievement.percentComplete < percent)
{
NSLog(@"new achievement %@ reported", achievement.identifier);
achievement.percentComplete = percent;
[achievement reportAchievementWithCompletionHandler:^(NSError* error)
{
[delegate onReportAchievement:(GKAchievement*)achievement];
}];
[self saveAchievements];
}
}
-(GKAchievement*) getAchievement:(NSString*)identifier
{
GKAchievement* achievement = [achievements objectForKey:identifier];
if (achievement == nil)
{
achievement = [[[GKAchievement alloc] initWithIdentifier:identifier] autorelease];
[achievements setObject:achievement forKey:achievement.identifier];
}
return achievement;
}
这里有什么可以导致我的成就报告为尽早完成,即使他们真的没有?
谢谢!
EDIT1:
2012-11-19 20:50:15.946 App[16894:907] percent: 0.005556
2012-11-19 20:50:15.947 App[16894:907] achievement percentComplete: 0.004861
2012-11-19 20:50:15.972 App[16894:907] percent: 0.000000
2012-11-19 20:50:15.973 App[16894:907] achievement percentComplete: 0.000000
2012-11-19 20:50:15.974 App[16894:907] percent: 0.026000
2012-11-19 20:50:15.974 App[16894:907] achievement percentComplete: 0.024000
2012-11-19 20:50:16.003 App[16894:907] percent: 0.002600
2012-11-19 20:50:16.004 App[16894:907] achievement percentComplete: 0.002400
2012-11-19 20:50:16.010 App[16894:907] percent: 0.000000
2012-11-19 20:50:16.011 App[16894:907] achievement percentComplete: 0.000000
2012-11-19 20:50:16.012 App[16894:907] percent: 0.016667
2012-11-19 20:50:16.012 App[16894:907] achievement percentComplete: 0.016667
2012-11-19 20:50:16.013 App[16894:907] percent: 0.000000
2012-11-19 20:50:16.014 App[16894:907] achievement percentComplete: 0.000000
答案 0 :(得分:0)
我认为这里的问题是在支票if (achievement.percentComplete < percent)
中,它太模糊了。我的百分比完成率可能是5%,我的百分比值可能是6%,但绝不是100%完成。因此,通过上述方法的方式,每次更新成就的百分比完成时,只会显示成就横幅,这不是游戏中心的工作方式。我也注意到,即使横幅显示我确实解锁了成就,但当我在Game Center应用程序中检查时,我真的没有。所以我改为采用以下方法:
-(void) reportAchievement:(NSString*)identifier percentComplete:(float)percent
{
if (isGameCenterAvailable == NO)
return;
GKAchievement* achievement = [self getAchievement:identifier];
if (percent > achievement.percentComplete)
{
NSLog(@"new achievement %@ reported", achievement.identifier);
achievement.percentComplete = percent;
[achievement reportAchievementWithCompletionHandler:^(NSError* error) {
if (achievement.isCompleted) {
[delegate onReportAchievement:(GKAchievement*)achievement];
}
}];
[self saveAchievements];
}
}
在此代码中,它仍将向100%报告更新的值,但如果GC的isComplete BOOL返回YES,则仅显示横幅。