3

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 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Both of those look fantastic - thanks for the links. Although both look like they require the game to tell them that an achievement has been "had". I still need to find a way of defining achievements (both in terms of trigger and dependencies/requirements) in an abstract kind of way.
Well for that you could use SQLite, this guy suggest ( reedolsen.com/how-to-develop-achievements-for-iphone-games ) something that you could imitate. Basically, you just track statistics with SQLite, and you could then create a trigger to check for achievements earned.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.