Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

iOS and MacOS / a step by step tutorial:how to add GameCenter(leader board &Achievement) to your games.

Author
Message
halley
11
Years of Service
User Offline
Joined: 27th Apr 2011
Location: China
Posted: 21st Nov 2011 14:06 Edited at: 21st Nov 2011 14:26
1. first of all, you should edit leader board and achievement in the iTunes Connect.It's very easy.

2. second add gamecentermanager.(I attached a zip file in the attachment,include four files which you need to add into your games.)

gamecentermanager.h



gamecentermanager.m



you need not change anything in the two files.just add them into your project.

3.(optional, you need do it if your game is landscape) add two files to control the orientation of leader board and achievement.
GKLeaderboardViewController-LandscapeOnly.h



GKLeaderboardViewController-LandscapeOnly.m



4. add these code in the UntitledViewController.h

add three Delegate to UntitledViewController definition , such as


then add a variable and two functions in the UntitletViewController, you should know a little grammar about objective-c,then you can add follow code correctly.



that's all for UntitledViewController.h.

5. add these functions into the UntitledViewController.m file. It's very easy.

you need not to change these except -(void) showLeaderboard. Pay attention to this line:
leaderboardController.category = @"BallScore"; you should change @"BallScore" to your own ID which you defined in the iTunes Connect.

6. be patient. almost come to an end. there is only two steps left. Check if the device os can support Game Center and authenticate local user by following code.It's very important.

you should add these code into - (void)viewDidLoad function. That's all for UntitledViewController.m .

7. the last one is very simple. You just need to know where to call the functions which you added just now.Before it , you should define a global variable for UntitledViewController. Then you can call the functions in your cpp file.
a. report a score to Game Center. remember to replace the category with your own.

b. submit a achievement to GameCenter. the first parameter is the category, and the second is the percent of finished.

c. call it to show leader board.

d. call it to show achievements

That's all 7 steps. If you have any questions, you can post follow this thread. I'll answer as quickly as I can. For I'll know it immediately from my iPhone when there is a new post.

The Miracrea Games

Attachments

Login to view attachments
halley
11
Years of Service
User Offline
Joined: 27th Apr 2011
Location: China
Posted: 21st Nov 2011 14:22
I attached the sample about Game Center named GKTapper. I learned the usage of Game Center from this.

The Miracrea Games

Attachments

Login to view attachments
bjadams
AGK Backer
14
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 21st Nov 2011 16:18
Halley, this is a very useful tutorial & very easy to follow.

I am going to try it out now...
bjadams
AGK Backer
14
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 21st Nov 2011 16:24
5 stars for Halley for posting these useful tutorials!

halley
11
Years of Service
User Offline
Joined: 27th Apr 2011
Location: China
Posted: 22nd Nov 2011 04:06
@bjadams : Thank you. I'll give more tutorials in the future.

The Miracrea Games
bjadams
AGK Backer
14
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 22nd Nov 2011 08:26
Halley, do you have some simple code, so when you click on a button, you open the safari web browser on the iphone with a website?
halley
11
Years of Service
User Offline
Joined: 27th Apr 2011
Location: China
Posted: 22nd Nov 2011 08:28
@bjadams : sorry , I don't have any code about web browser control now.

The Miracrea Games
3d point in space
12
Years of Service
User Offline
Joined: 30th Jun 2009
Location: Idaho
Posted: 23rd Nov 2011 02:25 Edited at: 23rd Nov 2011 02:37
I bookmarked this page this is impressive. When you edit Connect what do you name the fields. So you can pass them to connect.

Do you name them:

percentComplete For showing achievements

Go through yourself at a wall.
3d point in space
12
Years of Service
User Offline
Joined: 30th Jun 2009
Location: Idaho
Posted: 23rd Nov 2011 03:27
Or is the achievement id

[g_View.gameCenterManager submitAchievement: @"300points" percentComplete: 100];

@"300points" is the id

Go through yourself at a wall.
halley
11
Years of Service
User Offline
Joined: 27th Apr 2011
Location: China
Posted: 24th Nov 2011 02:55
@3d point : yes.

The Miracrea Games
T8x
10
Years of Service
User Offline
Joined: 13th Dec 2011
Location:
Posted: 14th Dec 2011 05:03
@halley - thank you for you wonderful tutorial

i am a new dev and i am studying how to insert a leaderboard into an app however i cant go on to itunesconnect because i am just trying this particular app(not mine just an open source) is there a way that i can put a leaderboard on that? thanks
T8x
10
Years of Service
User Offline
Joined: 13th Dec 2011
Location:
Posted: 14th Dec 2011 07:19
i tried it but i got 35 errors ~.~
T8x
10
Years of Service
User Offline
Joined: 13th Dec 2011
Location:
Posted: 14th Dec 2011 07:23
@halley - nice tutorial it is very clear and understandable..... but when i tried it i ran into 35 errors. can u help me?
halley
11
Years of Service
User Offline
Joined: 27th Apr 2011
Location: China
Posted: 14th Dec 2011 09:29
I received the email which told me that T8x need my help, but I can't see his thread, why?

@T8x, can you see this thread, if you can ,I'll post answer here.

The Miracrea Games
T8x
10
Years of Service
User Offline
Joined: 13th Dec 2011
Location:
Posted: 14th Dec 2011 09:38
@halley yes i can see it ... i also dont know why my posts cannot be posted
halley
11
Years of Service
User Offline
Joined: 27th Apr 2011
Location: China
Posted: 14th Dec 2011 09:43
Because I can't see your thread in this page. I think email is a better way. What's your email address?

You can use leader board in a test project. GKTapper,You download this sample which I post in the second thread of the page. Then you can see leader board in it.

The Miracrea Games
T8x
10
Years of Service
User Offline
Joined: 13th Dec 2011
Location:
Posted: 14th Dec 2011 09:44 Edited at: 15th Dec 2011 02:39
my email address is ------ i have downloaded the GKTapper but it also have the same problem
T8x
10
Years of Service
User Offline
Joined: 13th Dec 2011
Location:
Posted: 14th Dec 2011 09:58
im waiting for your email did u send one?
T8x
10
Years of Service
User Offline
Joined: 13th Dec 2011
Location:
Posted: 14th Dec 2011 11:04
@halley - is gamecenter and gamekit only works on iphone 4.1 onwards?
halley
11
Years of Service
User Offline
Joined: 27th Apr 2011
Location: China
Posted: 14th Dec 2011 11:05
I think 4.2 onwards.

The Miracrea Games
T8x
10
Years of Service
User Offline
Joined: 13th Dec 2011
Location:
Posted: 14th Dec 2011 11:07
i see i have the xcode 4.2 now and the ios 5.0 but my mac is not compatible with it phew~
T8x
10
Years of Service
User Offline
Joined: 13th Dec 2011
Location:
Posted: 15th Dec 2011 05:06
i now installed xcode 4.2 but im still having like 14 or 15 errors @_@
halley
11
Years of Service
User Offline
Joined: 27th Apr 2011
Location: China
Posted: 15th Dec 2011 05:07
Can you post the errors? I don't know where is wrong.

The Miracrea Games
T8x
10
Years of Service
User Offline
Joined: 13th Dec 2011
Location:
Posted: 15th Dec 2011 06:28


i have:
- Extraneous ] before ; at the first line

-gView undeclared

- missing [ at start of message on the 2nd to the last line

on viewcontroller.h

i have cannot find protocol declaration of ADBannerViewDelegate and SKProductsRequestDelegate

those ones are the errors XD
T8x
10
Years of Service
User Offline
Joined: 13th Dec 2011
Location:
Posted: 15th Dec 2011 07:18
have u seen it already?
halley
11
Years of Service
User Offline
Joined: 27th Apr 2011
Location: China
Posted: 15th Dec 2011 07:19
Quote: "
i have:
- Extraneous ] before ; at the first line

-gView undeclared

- missing [ at start of message on the 2nd to the last line

on viewcontroller.h

i have cannot find protocol declaration of ADBannerViewDelegate and SKProductsRequestDelegate

those ones are the errors XD
"


1. you should define a global variable such as this
extern UntitledViewController* g_View; in .h
UntitledViewController* g_View; in .cpp

2. ADBannerViewDelegate is for iAd, a adverts service. and SKProductsRequestDelegate is for in-app purchase. you can delete them.

do these two things first, maybe there will be none errors later.

The Miracrea Games
halley
11
Years of Service
User Offline
Joined: 27th Apr 2011
Location: China
Posted: 15th Dec 2011 07:20
I'm really puzzled for one thing which I can't see your post here.

The Miracrea Games
halley
11
Years of Service
User Offline
Joined: 27th Apr 2011
Location: China
Posted: 15th Dec 2011 07:22
I just read your questions in the email.

The Miracrea Games
T8x
10
Years of Service
User Offline
Joined: 13th Dec 2011
Location:
Posted: 15th Dec 2011 07:23
may i know where is .cpp? XD
halley
11
Years of Service
User Offline
Joined: 27th Apr 2011
Location: China
Posted: 15th Dec 2011 07:24
sorry, I took a mistake. It should be .m file.

The Miracrea Games
T8x
10
Years of Service
User Offline
Joined: 13th Dec 2011
Location:
Posted: 15th Dec 2011 07:33
i implemented the things that you said but the extraneous is still there then i tried to erase the [ and ] at the first line and it seems ok. however is says that m_iScore is undefined?
T8x
10
Years of Service
User Offline
Joined: 13th Dec 2011
Location:
Posted: 15th Dec 2011 07:33
undeclared rather sorry
halley
11
Years of Service
User Offline
Joined: 27th Apr 2011
Location: China
Posted: 15th Dec 2011 07:46
sorry? m_iScore ? I only used it in ball.h and ball.cpp.

The Miracrea Games
T8x
10
Years of Service
User Offline
Joined: 13th Dec 2011
Location:
Posted: 15th Dec 2011 07:48
where can i find the one that i will replace with that?
halley
11
Years of Service
User Offline
Joined: 27th Apr 2011
Location: China
Posted: 15th Dec 2011 07:49
I'm a bit puzzled with your question. I think you can delete m_iScore.

The Miracrea Games
T8x
10
Years of Service
User Offline
Joined: 13th Dec 2011
Location:
Posted: 15th Dec 2011 07:50
what should i replace? i will only delete it and leave it blank? XD
halley
11
Years of Service
User Offline
Joined: 27th Apr 2011
Location: China
Posted: 15th Dec 2011 07:51
I think you can try what you said.

The Miracrea Games
T8x
10
Years of Service
User Offline
Joined: 13th Dec 2011
Location:
Posted: 15th Dec 2011 07:51
i deleted m_iScore and now its telling me that forCategory is undeclared identifier .
halley
11
Years of Service
User Offline
Joined: 27th Apr 2011
Location: China
Posted: 15th Dec 2011 07:53
May I ask what's the name of your project?

The Miracrea Games
T8x
10
Years of Service
User Offline
Joined: 13th Dec 2011
Location:
Posted: 15th Dec 2011 07:57
tweejump. it is ok now i deleted the reportscore and m_iscore the errors are gone all of it but theres still one error


this one waaa ~.~ im almost finished im feeling it but i dont know this one
T8x
10
Years of Service
User Offline
Joined: 13th Dec 2011
Location:
Posted: 15th Dec 2011 08:52
are u still there halley? im sorry if im disturbing u too much .
T8x
10
Years of Service
User Offline
Joined: 13th Dec 2011
Location:
Posted: 16th Dec 2011 09:44
@halley - where are u now? T_T i really need your help
halley
11
Years of Service
User Offline
Joined: 27th Apr 2011
Location: China
Posted: 16th Dec 2011 09:47
Is tweejump your test project? If you just want to learn how to use Game Center. I advise you to use GKTapper. You can find it the second thread of this page. There is no error in it.

The Miracrea Games
halley
11
Years of Service
User Offline
Joined: 27th Apr 2011
Location: China
Posted: 16th Dec 2011 10:39
I forgot one thing in the tutorial. In the first you should add GameKit.Framework. It's very important.

The Miracrea Games
T8x
10
Years of Service
User Offline
Joined: 13th Dec 2011
Location:
Posted: 16th Dec 2011 10:39
i am assigned to put an online leaderboard on tweejump... ~
T8x
10
Years of Service
User Offline
Joined: 13th Dec 2011
Location:
Posted: 16th Dec 2011 10:42
i added the gamekit framework first..
bjadams
AGK Backer
14
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
halley
11
Years of Service
User Offline
Joined: 27th Apr 2011
Location: China
Posted: 18th Dec 2011 10:09
I added Game Center into a new project ,only take a few steps ,I think it's very easy to add game center to your game. There must be something wrong. But I can't find it.

The Miracrea Games
bjadams
AGK Backer
14
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 18th Dec 2011 10:33
I still have not found the time to add gamecenter to my project.

as soon as i do it, based on halley's instructions, i will post back again, with some more info
T8x
10
Years of Service
User Offline
Joined: 13th Dec 2011
Location:
Posted: 19th Dec 2011 02:26
@bjadams - i tried that one . thats what i tried

Login to post a reply

Server time is: 2022-05-27 15:59:56
Your offset time is: 2022-05-27 15:59:56