GLBasic forum

Codesnippets => Userlibs [ *.gbal] => Topic started by: Dark Schneider on 2011-Aug-03

Title: Game Center (testers and help needed)
Post by: Dark Schneider on 2011-Aug-03
Hi, I am currently working on Game Center integration in GLBasic, and some help would be fine.

Inside the ZIP, there are 2 folders:

- GameCenterWrapper: here is the source code for XCode, it is yet incomplete because I want to test before.

- GCTest: a simple GLBaisc project to test it.

I thnk each function is self-descriptive, with a notation about "lastErrorCode", as access to GC is asynchronous, we need a way to know when has been completed in GLB, then I use the lastErrorCode for that, I set it to -1 while working, and when is <>-1 we can see the result (see source code of GCTest). For NO ERROR, lastErrorCode passes from -1 to 0 (0 is NO ERROR). I think there is no error =-1 in Apple documentation, for that I use it, if there is any, simply change it.

With GCisSupported + GCisAuthenticated + GCgetLastErrorDomain + GCgetLastErrorCode IMO there is full to know about if there is success or any error, only looking at Apple documentation. In example, if  GCgetLastErrorDomain="NSURLErrorDomain" this is internet connection problem, look at Apple docs for more info.


Well, after this, what I need are testers, Game Center doesn't works on jailbroken devices for development purposes, so you need an original iOS device with Game Center support.
(http://photos.appleinsider.com/gamecenter-100907.jpg)

In the simulator it works perfectly, I have tested on a jailbroken device (it is not mine) and it says "This game is not recognized by Game Center", this is GOOD because it seems that it tries to authenticate, and this is exactly what should be seen on jailbroken devices for developer compilations (including AdHoc ones), but for better results, it would be good that someone with an original device test it.

To use:

- Create a project with Game Center in your iTunesConnect, you can use any name, as they are going to expire, I recommend something like MyDomainGameCenterTest01, so when expires you can use MyDomainGameCenterTest02, etc, etc. Get all needed certificates and blahblah (see at Apple documentation).

- In XCode: once we have our XCode project from GLBasic, simply follow these steps:
1) Add GameKit framework to frameworks. Before this you need to select the "Release" configuration.
2) Add the folder "GameCenterWrapper" to the project, i.e. in "Other Sources" section.
3) Configure you target settings, in "Properties" set the "Identifier" to your APP ID, remember that wildcards doesn't work for Game Center.
4) Build and Run  ;)

IMPORTANT: remember to create a Sanboxed Game Center profile for testing purposes. this can be done by logout with the current profile and then starting the Game Center development app, and click on Create New, use a new e-mail that will be attached to an Apple ID by its own with a verification mail, so there is no need to create an Apple ID for this before, simply a non-used email by other Apple ID.


Comment here if it works (you see the Game Center authentication notification). Modify the GCTest or create your own for deeper tests.

Note: the files to modify are the GameCenterWrapper.h and .m, and maybe the GameCenterWrapperFunctions.m

Update: lastest code in the attached file, including an example project.

[attachment deleted by admin]
Title: Re: Game Center (testers and help needed)
Post by: Dark Schneider on 2011-Aug-04
I think GCgetLastErrorDomain() is not working, maybe someone could fix it.

At this moment the more important thing is to test if the "report" functions work properly, as the "show" can be made using the Game Center app because if it is recommended to show them in your app, is not required, and more having a multi-task iOS. It could be added in the future.
Title: Re: Game Center (testers and help needed)
Post by: Dark Schneider on 2011-Aug-04
New version, now the leaderboards shows correctly, when showing achievements it can crash, but I think is because if we show achievements for a "not supported" game (then there are no achievs) the object "*achievements" using the Apple Game Center function can be the problem, and should be tested with a real supported game with real achievements created on iTunesConnect. If the game has no achievements, there is no sense in showing them.
I say this because in the simulator it works fine always.

Now the GCgetLastErrorDomain() is in the form:
Code: (glbasic) [Select]
void GCgetLastErrorDomain(char *errorDomain)the problem is that if we want to return a char*
Code: (glbasic) [Select]
char *GCgetLastErrorDomain()in GLB we must define the function like GCgetLastErrorDomain$() and then we have errors or must use a conditional compilation ?IFDEF for any use, so filling a buffer is better solution IMO.
But I think is not working yet.
Title: Re: Game Center (testers and help needed)
Post by: blackway on 2011-Aug-04
Hi Dark Schneider.
First I want to say thank you very much for your work!! I really appreciate what you are doing about Game Center (I think that Game Center is a must these days).  :good:

Sadly I can't help you testing because my Ipod touch is jailbreaked  :-[

Keep it the good work!
cheers,
Title: Re: Game Center (testers and help needed)
Post by: spacefractal on 2011-Aug-08
My phone is not jailbreaked and have not need to do that (3GS).

I Can help and test, but Fortuna i have still not brought a dev account yet (only registred) and my game is still a bit early...

I guees its would been happens few weeks so i finally can test on
My phone. I do want gamecenter and/or openfeint support for it.

But cant help right now in this momment, but i look when possible.

Sad I would test this soon (so I should do that this week anyway....)
Title: Re: Game Center (testers and help needed)
Post by: Dark Schneider on 2011-Aug-12
Well currently is fully functional for reporting, but the problem is to show the Leaderboards and Achievements, the current code doesn't work on iPad  :blink:

I attach the XCode project, there is no need of an original iOS device and there is no need of a GC account because there is no need to be authenticated to show the tables, nothing. The project is a GLBasic one, you only need to test it by pressing the 2 last buttons in the bottom row, they have the "Show" text (detects when we leave the finger over its position). If you press on another ones, you will see how the most rigth number at bottom increases, ignore it.

So anyone can use it to find the way these tables should be shown. The file to modify is the GameCenterWrapper.m, functions showLeaderboardCategory and showAchievements.

Take a look at it, earlier they work, earlier we have a full GC features.

Updated: changed the "show" functions so currently they work on an iPad executed in iPhone mode, I need someone to test them on real iPhones, the 3GS and on iPhone 4 and view what happends. So at this moment we can detect the device and in case of iPad show a message "Open the Game Center App", but on iPhones we could show the Game Center tables inside the application, as most game buyers are iPhone users its better than nothing.

But other developers can modify it so they work too on iPad.

Note: the showAchievements works on iPad if we change in the dissmissdelegate:
.view.superview removefromsuperview
to
.view removefromsuperview

so we could modify it to conditional execution depending on device type. Bu this should be done when leaderboards were working IMO to have a full working Game Center on iPad.
Title: Re: Game Center (testers and help needed)
Post by: Dark Schneider on 2011-Aug-12
Moved the last attached file version to the first post, also now the showAchievements function should be fully functional, as said it detects the device type, including when we run the app in iPhone mode on an iPad (for non-Universal apps).

Now we need to test it on iPhone models, but I don't have any iPhone supporting Game Center.
Title: Re: Game Center (testers and help needed)
Post by: Crivens on 2011-Aug-12
I have a 3GS (4.3.5), an iPod Touch 4G (4.2 I think), and an older iPod Touch 2 or 3G (I forget which). All non-JB. Oh, and plus a developer licence obviously.

I'm a bit busy at the minute so if that GCTest attachment project is pretty quick to just compile and then setup in Xocde then if I have a moment over the weekend I will put it on my iPhone. No promises as I have a busy weekend.

Cheers
Title: Re: Game Center (testers and help needed)
Post by: Crivens on 2011-Aug-12
Quick thing though. I just downloaded the zip from the first post so it is ready when I have a spare minute, but I can't find any GLB files. Is the GLB project files in a different download?

Cheers
Title: Re: Game Center (testers and help needed)
Post by: Dark Schneider on 2011-Aug-12
A great collection  ;/

At this moment is the XCode project, only to test if the leaderboards and achievements tables are shown correctly on iPhones, because I only have an iPad to test it, and assuming than an iPad running in iPhone mode is he same than an iPhone is not good at all  :S

Once tested, I will put the entire project including the GLBasic one to see how to use it in GBasic (this phrase is not a bit redundant?  :zzz: ).
Title: Re: Game Center (testers and help needed)
Post by: Crivens on 2011-Aug-12
Ah, ok, sorry I misunderstood when you said it contained a simple GLB project.

I'll try and get a moment to try it out this weekend. Busy one this time so might not get the chance till next week.

Cheers
Title: Re: Game Center (testers and help needed)
Post by: Dark Schneider on 2011-Aug-22
Project updated (look at the first post), what I have tested:

- Device not supporting GC: all fine, there is no crash.

- Device suppotring GC: iPad. All reporting features works well, tested with a real app project with GC configured and the scores and achievements reports work fine, both on iPad and on iPhone mode. Note: when I talk about iPhone mode it means runing the app compiled as iPhone only on an iPad, not a real iPhone.
Showing tables:
iPad mode: leaderboards doesn't show, achievements works fine.
iPhone mode: both shows correctly, no animation when hiding.

I have tested it trying to force it to crash, with a long sequence of continuous show/hide, show/hide..., sliding the finger while showing and while hiding, etc. But all tests was on iPad (both iPad and iPhone modes).

I have simplified the project so it only have 3 buttons, "Add score", "show leader" and "show achievs" for evading crashes for using reports to an undefined/unconfigured GC app.
Then what I need is someone to test ONLY the "show" (both) on a real iPhone, trying to force it like I said before (show/hide, show/hide, show/hide, sliding fingers while shows/hides, etc.) and report the results.
The "add socre" button is used to see if continue to having control over the app when hiding a panel. The buttons respond to the event "lift up" the finger, because I noticed the boards can block the control if we have pressed on the screen at the moment they appear. So responding to this event we are sure there is no finger on the screen when we show the board.
Title: Re: Game Center (testers and help needed)
Post by: Crivens on 2011-Oct-13
How is this going? Have you got any further? Is it still just in XCode or have you linked to a project in GLB? I'm sure a fair few people here are hoping it works out well.

Cheers
Title: Re: Game Center (testers and help needed)
Post by: pinete on 2011-Dec-01
Hi,
completely agree with Crivens!
how is it going? this project seems quite interesting! it would be great to have it done to boost the games of the community! :)
let us know something more about it!!!  :nw:
best of lucks!
Title: Re: Game Center (testers and help needed)
Post by: Crivens on 2011-Dec-01
Heh, completely forgot about this. Yeah, any news?

Cheers
Title: Re: Game Center (testers and help needed)
Post by: Nobiag on 2011-Dec-14
im very interested in this too. any news about it now? :)
Title: Re: Game Center (testers and help needed)
Post by: Crivens on 2011-Dec-14
If you click on the original posters details he hasn't been active in months. So looks like unless someone else steps up to the challenge then we are right out of luck at least for a while.

It's a shame because I think he did release a game center game so obviously he succeeded. Doubt it used the multiplayer Apis but just the high score system would be brilliant...

Cheers
Title: Re: Game Center (testers and help needed)
Post by: Dark Schneider on 2012-Jan-04
I have been absent some time, sorry.

When I have some time I will organize the code in its current state (the one used in Rapids Rider) and post it.

I left the topic because I asked for testers but passed much time with no results, and when I released the game it has no testers yet so I left the topic.

The current state is the last mentioned, all reports works but there are no leaderboards show on iPad, and the Game Center app must be used.
Title: Re: Game Center (testers and help needed)
Post by: Crivens on 2012-Jan-04
Cool. That would be great. A definite brilliant resource for the GLB community. Is it the highscore stuff or does it also include the Multiplayer capabilities?

I think the lack of testers was because there wasn't a GLB project to use. An simple attached project would definitely get people involved I'm sure.

Cheers
Title: Re: Game Center (testers and help needed)
Post by: Dark Schneider on 2012-Jan-05
Leaderboards and achievements, both working fine.
Title: Re: Game Center (testers and help needed)
Post by: Crivens on 2012-Jan-05
Nice. Can't wait till you have a spare moment then!

Cheers
Title: Re: Game Center (testers and help needed)
Post by: bigtunacan on 2012-Jan-06
Thanks; I would love to have access to Game Center for my apps :)
Title: Re: Game Center (testers and help needed)
Post by: Dark Schneider on 2012-Jan-06
I have updated the attached file in the first post, I don't think anything is missing. Copied from the Rapids Rider last update folder project, so is the lastest version.

What can be outdated is the GLB project "GCTest" included, it has not been modified since much time ago, but I think the functions names have not changed so it probably can work fine.

But you can take a look to the source code itself, it has been written reasonably clear IMO. Another point is that can be useful as "tutorial" of "how to include Objective-C in GLBasic", because is very simple:
- Create what you want in Objective C, use all you want like classes, etc.
- Create a wrapper, a "C" file (".m") with "C" functions that are what GLBasic can IMPORT, and do all the work with this "C" functions with the Objective-C code.

i.e. see how I use a class for GC, and simply using the "GameCenterWrapperFunctions.m" we can here create, initialize and work with any Objective-C class.
Title: Re: Game Center (testers and help needed)
Post by: trucidare on 2012-Jan-07
Try to use ARC for your new Libs and disable garbage collector.
Title: Re: Game Center (testers and help needed)
Post by: Dark Schneider on 2012-Jan-11
I think really there is no need, garbage collector is not available on iOS, and there is no need to destroy the objects, at least in this case.

We create the objetcs in the initialization, use them, and when we exit the App the iOS frees al the memory used by that App.

Other case is if you want to have Objective-C objects to create and destroy in real time, but thanks anyway.
Title: Re: Game Center (testers and help needed)
Post by: Crivens on 2012-Jan-11
Hopefully I can finish my damn game and then try testing this out. Honestly the last few things take the longest...

Cheers
Title: Re: Game Center (testers and help needed)
Post by: tatakamucher on 2012-Jan-11
I used your iOSAuxFunc for my game and now i implemented game center, thanks  :good:
Title: Re: Game Center (testers and help needed)
Post by: tatakamucher on 2012-Jan-12
Hi again  :|  :P, i tested with ipod ios 5.0.1 and works fine one time, example: you show leaderboards one time and works fine  :enc:, close leaderboards and try to open again and dont works, if you press home button and hide the game and show again the game the gc works again one time, i was think i have some wrong in mi code but i tried your file and have the same result.

The same problem is when you show the achievements.  :x
Title: Re: Game Center (testers and help needed)
Post by: Dark Schneider on 2012-Jan-12
Hi again  :|  :P, i tested with ipod ios 5.0.1 and works fine one time, example: you show leaderboards one time and works fine  :enc:, close leaderboards and try to open again and dont works, if you press home button and hide the game and show again the game the gc works again one time, i was think i have some wrong in mi code but i tried your file and have the same result.

The same problem is when you show the achievements.  :x

Ops, I forgot to mention, use the "show" functions when "lift up" the finger, and not when touch the screen. If not the input focus is lost by the app.

See that in the attached test project "GCTest" I use the InputCheckPressedUp() function, that checks if you "lift up" the finger from screen. "readme" updated with that info.

Quote
I used your iOSAuxFunc for my game
And that remembers me that I not included the GLBasic wrapper to use them, now is included  ;/

And REMEMBER EVERYONE, showLeaderboard() can't be used on iPad, I don't know why on iPad the focus is always lost.
Title: Re: Game Center (testers and help needed)
Post by: tatakamucher on 2012-Jan-12
I downloaded the last files from the post and don work  :blink:

A video with the error




Title: Re: Game Center (testers and help needed)
Post by: Dark Schneider on 2012-Jan-13
I downloaded the last files from the post and don work  :blink:

A video with the error




What version of iPhone do you have?, maybe if is an iPhone 4 has the same problem than the iPad. Try with achievements instead leaderboards. As I said it has a problem of input focus loss on iPad with leaderboads, and maybe with the lastest iPhones is the same.

But is rare because running it on an iPad, but compiling in iPhone mode, works fine.

To solve, try diferent things (combinations) in leaderboardViewControllerDidFinish() function, lines:

[self.gcViewController dismissModalViewControllerAnimated:YES];
change YES to NO

[self.gcViewController.view.superview removeFromSuperview];
No much idea about the changes here, but is the other line that handles the leaderboard controller remove from view.
maybe can try:
[self.gcViewController.view removeFromSuperview];
without the last ".superview".
if we look at the achievementViewControllerDidFinish() function, it has two ways depending on device, but I think I tested it for leaderboards but it didn't work (not sure).

Try posible combinations until it works, if it works. And if you find the solution remember to post it here for everyone.

There are really many problems with leaderboards tables on 3rd party libraries, like GLBasic, Cocos2D, and others.
Title: Re: Game Center (testers and help needed)
Post by: kaotiklabs on 2012-Apr-09
any changes on this?

I have tried and as you stated is working on iPad (iPhone Mode) but not on iPhone (ver 5.0.1)
I tried to change what you sugested but focus is still lost.