GameKit 成就问题

发布于 2024-11-17 16:48:50 字数 4096 浏览 2 评论 0原文

我的游戏中心成就出现在游戏中心中,因此我知道我的实施在报告中是正确的。

有几个问题。

首先,在游戏中心中,它没有在图像上显示百分比视图...即成就旁边的 2% 完成,即使我已报告 0.02。我知道正在报告该成就,因为如果我向其扔 100,它就会记录该成就。

其次,我的成就不会以奖励的形式呈现给用户。据我了解,此功能应该由游戏包自动处理。我的印象是,会出现小模式,让用户知道他们完成了一项成就。我现在认为我必须做一些事情,因为没有出现任何小模态。

我将附上我的代码,但大部分都是库存的。

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

提前致谢...

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

}

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

Couple of questions on that.

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.

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.

Thanks in advance...

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

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苍风燃霜 2024-11-24 16:48:50

很多问题...

  • 我对递增 gamesComplete 背后的逻辑感到困惑。
  • 您应该将它们存储在本地,而不是每次都询问 GameCenter。
  • -getAchievementPercentageForIdentifier: 将始终返回 0,因为 GameKit 方法是异步的。
  • GKAchievement.percentageComplete 是一个百分比。你需要乘以 100。

我认为你必须做你自己的成就通知。

Many problems...

  • 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文