Search code examples
iphoneframeworksgame-centerachievements

iPhone Game Dev : Achievement Framework?


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.


Solution

  • 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 :)