Home
Fusion 2.5+
Firefly+
Tutorials+
Videos+
Guides & Tips+
Extensions
Versions
Teaching


Faulty Flap: Annex. Game Center

Annex. Making the game social with Game Center

This tutorial was written by:
Olivier Behr

Implementing social features in your game is important, they foster its viral distribution.

 

Prerequisites:

 

Leaderboards

Name Score Format Type Sort Order
High Scores Integer High to Low

 

 

 

 

Achievements

Name Pre-earned Description Earned Description Hidden Achievable More Than Once
First Score Score for the first time. You scored for the first time. No No
1-Stripe Medal Score 30 points or more. You scored 30 points or more. No Yes
2-Stripe Medal Score 60 points or more. You scored 60 points or more. No Yes
3-Stripe Medal Score 90 points or more. You scored 90 points or more. No Yes
Super Loser Lose 100 times or more. You lost 100 times or more. Yes No

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Frame Editor Icon In the Frame Editor open the Create new object Dialog by double-clicking on an empty place of the Frame. Then select the 3 objects below and drop them anywhere outside of the Frame.

 

  • Game Center Connect: manages the connection to Game Center
  • Game Center Leaderboard: manages the leaderboards
  • Game Center Achievements: manages the achievements

 

These objects allow your application communicate with Game Center.

 

Select Game Center Connect and click on Properties > Settings tab. Make sure that Authenticate at start of frame is checked.

 

Build And Run Icon Build and run the iOS application. The game automatically attempts to sign you in, from the first moments.

 

Frame Editor Icon In the Frame Editor select Game Center Leaderboard and click on its Properties > Settings tab. Copy yourLeaderboard ID and paste it in the Identifier field, so that the object refers to the corresponding leaderboard in subsequent events. Also uncheck Send score at start and Get scores and name at start.

You can find the identifier of your leaderboard(s) at any time in iTunes Connect > My Apps > Your Application > Features > Game Center.

Event List Editor Icon In the Event List Editor modify the following event in the Game.Outro group:

Game.Outro
Best score
  • (hud-score-big.Counter) > bestScore

+ Only one action when event loops

: Set bestScore to value( " (hud-score-big.Counter)" )

(hud-best.Counter) : Set Counter to bestScore

: Create (hud-new.Active) at (12,13) from (hud-panel.Active)

(hud-new.Active) : Flash during 00"-20

(Game Center Leaderboard) : Send score bestScore to server

What happens with this event? In addition to what we already did at Step 6, now we also submit the score of the player to Game Center.

Now we need to provide the player with a way to display the scores stored into the leaderboard. At the same time we will also provide him with a way to display his achievements.

 

Frame Editor Icon In the Frame Editor > Layers Toolbar make sure that Layer 3 is selected. From the Library Window drag the 2 objects below anywhere outside of the Frame.

 

  • btn-leaderboards.Active: "Leaderboards" button
  • btn-achievements.Active: "Achievements" button

 

Because we only need to display these objects at the end of the game, they are set to not Create at start.

 

Event List Editor Icon In the Event List Editor add the following event in the Game.Outro group:

Game.Outro
Init
  • (Game Center Connect) Local player is authenticated

+ Only one action when event loops

: Create ( btn-leaderboards.Active) at (326,518) layer 3

: Create ( btn-leaderboards.Active) at (156,518) layer 3

What happens with this event? Once that the Game.Outro group is activated, if the local player is authenticated we display the "Leaderboards" and "Achievements" buttons.
If the local player is not authenticated, i.e. connected to his Game Center account, it is unnecessary to display the buttons because they would have no effect.

Now add the following events in the Game.Outro group:

Game.Outro
Display leaderboard and then achievements
  • User clicks with left button on (btn-leaderboards.Active)

(Game Center Leaderboard) : Display default leaderboard

  • User clicks with left button on (btn-achievements.Active)

(Game Center Leaderboard) : Display default achievement panel

What happens with these events? When the player clicks on the "Leaderboards" button we display the leaderboards built-in UI, and when the player clicks on the "Achievements" button we display the achievements built-in UI. Simple.

Build And Run Icon Build and run the iOS application. When you lose the game, and provided that you're signed in to your Game Center account, the two additional buttons appear.
Tap on the "Leaderboards" button and you should see your greatest score. Tap on the "Achievements" button and you should see that all of them are locked.

 

Event List Editor Icon Let's reward the player with these achievements. In the Event List Editor add the following event in the Game.Outrogroup:

Game.Outro
Init
  • (hud-score-big.Counter) > 0

+ Only one action when event loops

(Game Center Achievements) : Send achievement "FIRSTSCORE_ACH_ID", percent 100

What happens with this event? If the score of the player is greater than zero we unlock the "First Score" achievement. Because this achievement can only be unlocked once, as setup in iTunes Connect, it doesn't matter that we unlock it every time that the player loses.
Replace the dummy identifier by the one corresponding to your achievement.

Build And Run Icon Build and run the iOS application. When you lose the game the "First Score" achievement is unlocked.

 

Frame Editor Icon The "Super Loser" achievement requires more work. In the Frame Editor open the Create new object Dialog. Then select the object below and drop it anywhere outside of the Frame.

 

  • Ini: allows to store persistent data

 

We use this object because the data stored into it are persistent, they remain from one game session to the other. Read on to find out why we need persistent data.

 

Event List Editor Icon In the Event List Editor add the following event in the Game.Init group:

Game.Init
Ini
  • Start of Frame

(Ini) : Set current file to "save.ini"

(Ini) : Set current group to "game"

(Ini) : Set current item to "times_lost"

What happens with this event? At the beginning of the game we initialize Ini by setting its current file, group and item.

Add the following events in the Game.Outro group:

Game.Outro
Init
  • Only one action when event loops

(Ini) : Set item value value of(" (Ini)" ) + 1

  • Value of( " (Ini)" ) = 100

+ Only one action when event loops

(Game Center Achievements) : Send achievement "SUPERLOSER_ACH_ID", percent 100

What happens with these events? Once that the Game.Outro group is activated we increment by 1 the value stored into Ini. In other words we keep track of how many times the player loses. And once that this value is equal to 100 we unlock the "Super Loser" achievement.
Replace the dummy identifier by the one corresponding to your achievement.

That's the reason why we use Ini. The value stored into it being persistent, it will increase from one game session to the other and will eventually reach and even exceed 100.
If we had used a value stored in a non-persistent way this achievement would have been too difficult to unlock, since losing 100 times in the same game session is very long.

 

Build And Run Icon Build and run the iOS application. If you lose the game 100 times the "Super Loser" achievement is unlocked. For faster testing you could change the value of the increment.

 

Event List Editor Icon We're almost done with the achievements. In the Event List Editor modify the following events in the Game.Outrogroup:

Game.Outro
Medal
  • (hud-score-big.Counter) >= 30

+ Only one action when event loops

: Create (hud-medal.Active) at (-80,8) from (hud-panel.Active)

(Game Center Achievements) : Send achievement "MEDAL1_ACH_ID", percent 100

  • (hud-score-big.Counter) >= 60

+ Only one action when event loops

(hud-medal.Active) : Set direction to 1

(Game Center Achievements) : Send achievement "MEDAL2_ACH_ID", percent 100

  • (hud-score-big.Counter) >= 90

+ Only one action when event loops

(hud-medal.Active) : Set direction to 2

(Game Center Achievements) : Send achievement "MEDAL3_ACH_ID", percent 100

What happens with these events? In addition to what we already did at Step 6, now we also unlock a different achievement depending on the score of the player.
Replace the dummy identifiers by the ones corresponding to your achievements.

Build And Run Icon Build and run the iOS application and try to unlock the remaining achievements!




Spread the word!



You can share this document using the following buttons.




Submit your own User Tip