我编写了一个简单的游戏,并希望将 GameCenter Achievements 与其集成。
我想尝试以一种干净整洁的方式来做到这一点,这样很容易添加额外的成就。
在我看来,成就具有以下内容:
- 触发器“组”(例如,在游戏结束时、碰撞时等)
- 依赖性(例如,在获得“5 金星”之前,您无法获得“10 金星”星星”)。
基于此,我尝试编写一个单例类,该类读取完整的成就列表(从 plist 中),每个成就都按触发器类及其依赖项分组。该单例允许其他类向触发器组注册类似于@selector() 的回调(例如,“在‘game_end’触发器上,调用此函数”)。然后可以在我的游戏中的定制点干净地调用这些触发器。这产生了一个简洁的、几乎“抽象”的系统,我可以在未来的游戏中使用它。
然后是灾难;我最终遇到了 EXC_BAD_ACCESS 错误,我只能假设这是因为我将非静态类的 @selector 回调绑定到静态单例类中。错误出现在这一行:
GCAchievementsHelper *h = [GCAchievementsHelper sharedInstance];
[h addEventListener:@"game_end" target:self selector:@selector(achievementHandlerGameEnd:)];
我假设这是因为“self”(游戏层)无法传递到静态单例中?!
我真的不想在我的代码周围散布大量重复的 IF 语句来检查成就所需的所有条件......如果可能的话!
总而言之,我的问题是:
有人知道成就框架吗?它不必与 GC/OpenFeint 甚至 ObjC 兼容 - 即使是伪代码也很棒。
I have written a simple game and am looking to integrate GameCenter Achievements with it.
I would like to try to do this in a clean and neat way which is easy to add extra achievements to.
As I see it an achievement has the following things:
- A Trigger 'group' (eg, on game end, on collision, etc)
- A Dependency (eg, you cannot get the "10 gold stars" until you have gained the "5 gold stars").
Based on this I tried to write a singleton class which read in a complete list (from a plist) of achievements, each one grouped by trigger class and with its dependencies. This singleton allowed other classes to register @selector()
-like callbacks to trigger groups (eg, "on 'game_end' trigger, call this function"). These triggers could then be invoked cleanly at bespoke points in my game. This produced a neat, almost "abstract" system which I could use in future games.
Then disaster; I end up with EXC_BAD_ACCESS
errors which I can only assume is because I'm binding @selector
callbacks from a non-static class into a static singleton class. The error appears on this line:
GCAchievementsHelper *h = [GCAchievementsHelper sharedInstance];
[h addEventListener:@"game_end" target:self selector:@selector(achievementHandlerGameEnd:)];
I'm assuming this is because "self" (the game layer) can't be passed into the static singleton?!
I really don't want to have to scatter tonnes of repeated IF statements around my code to check all the conditions I need for achievements... If at all possible!
To summarise, my question is:
Does anybody know of an Achievement Framework? It doesn't have to be GC/OpenFeint or even ObjC compatible - even pseudo code would be great.
发布评论
评论(1)
有几个 GameCenter 开源框架可以利用您的一些负载。
GameCenterManager 它遵循单例模式并且非常“轻”
iOS Game Center Cache 是一个全功能的 Game Center 框架。
我建议你看看它们......
祝你好运:)
There are a couple of GameCenter Open Source frameworks that can leverage some load from you.
GameCenterManager Which follows the singleton pattern and is quite "light"
iOS Game Center Cache is a full featured Game Center framework.
I would suggest you to look at both of them...
Good luck :)