我的游戏中心成就出现在游戏中心,所以我知道我的实施在报告中是正确的。
关于这一点的几个问题。
首先,在游戏中心,它没有显示图像上的百分比视图......即在成就旁边完成2%,即使我已报告.02。我知道这个成就正在被报道,因为如果我把它扔掉,就会记录成就。
其次,我的成就不会在奖励时出现在用户面前。据我所知,这个功能假设由gamekit自动处理。我的印象是小模态会让用户知道他们完成了一项成就。我现在认为我必须要做的事情,因为没有出现小模态。
我会附上我的代码,但大部分都是库存。
我的最后一个问题是检索分数。我相信我将不得不存储我自己的分数,因为我目前的实现看起来不会很好。
提前致谢...
- (void) loadAchievements
{ [GKAchievement loadAchievementsWithCompletionHandler:^(NSArray *achievements, NSError *error) {
if (error != nil)
{
// handle errors
}
if (achievements != nil)
{
// process the array of achievements.
}
}];
}
-(float)getAchievementPercentageForIdentifier:(NSString *)identifier {
__block float percentage = 0;
[GKAchievement loadAchievementsWithCompletionHandler:^(NSArray *achievements, NSError *error) {
if (error != nil)
{
// handle errors
}
if (achievements != nil)
{
// process the array of achievements.
for (GKAchievement *achievement in achievements) {
if ([achievement.identifier isEqualToString:identifier]) {
percentage = achievement.percentComplete;
NSLog(@"percent complete --> %f", achievement.percentComplete);
}
}
}
}];
NSLog(@"Percentage --> %f", percentage);
return percentage;
}
- (void) reportAchievementIdentifier: (NSString*) identifier percentComplete: (float) percent
{
GKAchievement *achievement = [[[GKAchievement alloc] initWithIdentifier: identifier] autorelease];
if (achievement)
{
achievement.percentComplete = percent;
[achievement reportAchievementWithCompletionHandler:^(NSError *error)
{
if (error != nil)
{
// Retain the achievement object and try again later (not shown).
}
}];
}
}
-(void) addCompletedGameToAchievements {
float oneGamePercentage = 0;
float tenGamePercentage = 0;
float fiftyGamePercentage = 0;
float hundredGamePercentage = 0;
float fivehundredGamePercentage = 0;
float thousandGamePercentage = 0;
int gamesComplete = 0;
oneGamePercentage = [self getAchievementPercentageForIdentifier:kAchievementGamesCompletedOne];
tenGamePercentage = [self getAchievementPercentageForIdentifier:kAchievementGamesCompletedTen];
fiftyGamePercentage = [self getAchievementPercentageForIdentifier:kAchievementGamesCompletedFifty];
hundredGamePercentage = [self getAchievementPercentageForIdentifier:kAchievementGamesCompletedHundred];
fivehundredGamePercentage = [self getAchievementPercentageForIdentifier:kAchievementGamesCompletedFivehundred];
thousandGamePercentage = [self getAchievementPercentageForIdentifier:kAchievementGamesCompletedThousand];
if (oneGamePercentage != 100) {
[self reportAchievementIdentifier:kAchievementGamesCompletedOne percentComplete:100];
}
if (tenGamePercentage != 100) {
gamesComplete = tenGamePercentage * 10;
gamesComplete++;
[self reportAchievementIdentifier:kAchievementGamesCompletedTen percentComplete:(gamesComplete * .10)];
}
if (fiftyGamePercentage != 100) {
gamesComplete = fiftyGamePercentage * 50;
gamesComplete++;
NSLog(@"fifty game reported %f ",(gamesComplete * .02));
[self reportAchievementIdentifier:kAchievementGamesCompletedFifty percentComplete:(gamesComplete * .02)];
}
if (hundredGamePercentage != 100) {
gamesComplete = hundredGamePercentage * 100;
gamesComplete++;
[self reportAchievementIdentifier:kAchievementGamesCompletedHundred percentComplete:(gamesComplete * .01)];
}
if (fivehundredGamePercentage != 100) {
gamesComplete = fivehundredGamePercentage * 500;
gamesComplete++;
[self reportAchievementIdentifier:kAchievementGamesCompletedFivehundred percentComplete:(gamesComplete * .002)];
}
if (fivehundredGamePercentage != 100) {
gamesComplete = thousandGamePercentage * 1000;
gamesComplete++;
[self reportAchievementIdentifier:kAchievementGamesCompletedThousand percentComplete:(gamesComplete * .0001)];
}
NSLog(@"100 game percentage -- > %f", hundredGamePercentage);
}
答案 0 :(得分:1)
很多问题......
gamesComplete
-getAchievementPercentageForIdentifier:
将始终返回0,因为GameKit方法是异步的。GKAchievement.percentageComplete
是百分比。你需要乘以100。我认为你必须做自己的成就通知。