解锁成就 - GameCenter iPhone

发布于 2024-10-08 05:49:58 字数 266 浏览 3 评论 0原文

我正在尝试解锁我为 iPhone 制作的游戏中的一项成就,但相当不成功。

从 Apple 自己的 GKTapper 项目示例(演示 Game Center 代码)中,我已将 GameCenterManager.h 和 .m 以及 AppSpecificValues.h 文件复制到我的项目中。我已成功加载成就和排行榜以供查看。

然而,我无法弄清楚或正确地了解如何真正解锁成就。有人可以指出如何使用这个或不使用 GameCenterManager 如何解锁成就吗?

谢谢。

I am trying to unlock an achievement in the game i am making for the iPhone but being rather unsuccessful.

From Apples own GKTapper project sample demonstrating Game Center code I have copied the GameCenterManager.h and .m and the AppSpecificValues.h files into my project. I have successfully got loading the achievements and leaderboards for viewing.

However I can't work out or get right how to actually unlock an achievement. Could some point out how using this or without the GameCenterManager how can I unlock an achievement please?

Thanks.

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

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

发布评论

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

评论(2

骑趴 2024-10-15 05:49:58
    - (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).
                  }
             }];
    }
}

像这样调用这个方法:

[self reportAchievementIdentifier:indentifier percentComplete:percent];

如果你只想解锁成就,请这样调用:

[self reportAchievementIdentifier:indentifier percentComplete:100.0];

你可以使用浮点来计算成就的百分比,如果用户达到 100,成就就会解锁。

您也可以这样做:

[self reportAchievementIdentifier:indentifier percentComplete:((actualpoints/neededPoints)*100.0)];

neededPoints 表示解锁该成就所需的积分。例如:
实际积分 = 300;
需要积分 = 600;

计算结果:300/600 = 0.5 * 100 = 50%

    - (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).
                  }
             }];
    }
}

Call this method like this:

[self reportAchievementIdentifier:indentifier percentComplete:percent];

If you want to just unlock the achievement call this:

[self reportAchievementIdentifier:indentifier percentComplete:100.0];

You can use the float for calculate the percent of the achievement, and if the user reaches the 100 the achievement gets unlocked.

You can also do this:

[self reportAchievementIdentifier:indentifier percentComplete:((actualpoints/neededPoints)*100.0)];

neededPoints means the points you need for unlock this achievement. For example:
actualPoints = 300;
neededPoints = 600;

It calculates: 300/600 = 0.5 * 100 = 50%

向日葵 2024-10-15 05:49:58

顺便说一句,如果您设置percentComplete=100,则“completed”属性并不总是设置为YES,至少不在同一会话中。我花了一段时间来调试为什么我的游戏多次授予成就,即使百分比已设置为 100。

Btw, the "completed" property isn't always set to YES if you set percentComplete=100, at least not within the same session. I spent a while debugging why my game awarded achievements several times even when percentComplete got set to 100.

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