本文介绍了GameKit成就问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Game Center中显示了Game Center的成就,因此我知道我的实现在报告中是正确的.

My game center achievements are appearing in Game Center, so I know my implementation is correct in reporting.

对此有疑问.

首先,在Game Center中,它没有在图像上显示百分比视图……即,成就旁边有2%完成,即使我报告了.02.我知道正在报告成就,因为如果我将其扔到100,它将记录成就.

First, in Game Center it is not showing the percentage view on the image... ie 2% complete next to the achievement, even though I have reported .02. I know the achievement is being reported because if I throw the 100 at it, it records the achievement.

第二,我的成就并没有显示给用户.据我了解,该功能是由Gamekit自动处理的.我给人的印象是,小模态会出现,让用户知道他们完成了一项成就.我现在认为我必须做些事情,因为没有小的模态出现.

Second, my achievements are not appearing to the user upon reward. As I understood, this functionality was suppose to be handled automatically by gamekit. I was under the impression the the small modal would appear letting the user know they completed an achievement. I now think there is something I have to do, because no small modal is appearing.

我将附上我的代码,但其中大部分都可以使用.

I will attach my code, but most of it stock.

我的最后一个问题是获取分数.我相信我将不得不存储自己的分数,因为我当前的实现看起来并不能很好地配合.

My last problem is retrieving scores. I believe I am going to have to store my own scores because my current implementation does not look like it will mesh well.

预先感谢...

- (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);

}

推荐答案

很多问题...

  • 我对增加 gamesComplete
  • 背后的逻辑感到困惑
  • 您应该将它们存储在本地,而不是每次都询问GameCenter.
  • -getAchievementPercentageForIdentifier:始终返回0,因为GameKit方法是异步的.
  • GKAchievement.percentageComplete percentage .您需要乘以100.
  • I'm confused by the logic behind incrementing gamesComplete
  • You should store them locally instead of asking GameCenter every time.
  • -getAchievementPercentageForIdentifier: will always return 0 because GameKit methods are asynchronous.
  • GKAchievement.percentageComplete is a percentage. You need to multiply by 100.

我认为您必须做自己的成就通知.

I think you have to do your own achievement notifications.

这篇关于GameKit成就问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 04:13