As some of you may know, I, among other things, also lecture on iOS programming. Due to the request of my students, I've spent some days on discovering the secrets of Game Center, which has been added to iOS in version 4.1 and is, consequently, pretty new and, apart from Apple's own documentation, very scarcely documented, let alone stand-alone, full demo application sources, of which I only know of GCPing, which is, for some reason, pretty much buried in the Apple developer forums. (I don't provide a link to GCPing because I don't know whether the developer wants to keep it pretty much private. Now that there's no NDA over Game Center any more, he may want to publish it to the public.) First, the sources. They're here: http://www.winmobiletech.com/sekalaiset/Pong.zip The contents of the ZIP file are ordered in three directories in the root: Local, GameKit and GC. All versions support, from ground up, all screen confgurations and are Universal. (The latter is needed if you want to play multiplayer games over Game Center between an iPhone and an iPad.) Apart from the four-player GC version, all remote capable games support coordinate transformation and rescaling between the iPhone (iPod Touch; of course, also ones with the Retina screen) and the iPad. The only exception is the 4-player GC versions, where I didn't want to bother with implementing this to keep the code (relatively) small and clean. The more advanced GC-capable versions also support voice transfer. There are two of them: "v3-4playersPlusAudio" only has a broadcast mode (everyone-to-everyone), while the most advanced one, "v4-UtilityApp", also supports private channels on top of the public (broadcast) one. You can set the target of your private channel in the flip view (by tapping the info icon) and can, after this, quickly switch between the two channels by using the newly introdued UISwitch in the gaming screen. If you do establish a private channel, make sure you tell the passive target of the channel to also select the other party so that his/her voice also gets thorugh the channel. The local version allows for 1, 2 and 4 players. I've "only" written these versions to demonstrate how easy it is to write a local multiplayer Pong under iOS. The one-player version has a slightly more advanced version, "1player-with shift", which allows for handling offset in controlling the paddle. As it makes the paddle coordinate computation considerably less easy to read (particularly with two or four remote players, particularly when the iPad and iPhone screen size difference must also be taken into account), I haven't implemented this in other versions. Also note that the skew computation is very simple: based on the distance between the center point of the pad and the ball, I simply add a computed movement x (with vertical paddles, y) offset to the original one. A somewhat more dedicate algorithm would have been needed to avoid the ball gradually speeding up. The GameKit version only supports two players and nothing fancy, except for rescaling when an iPad and an iPhone plays each other. The latter is also supported in the two-player GC version, but, to keep the code readable, not in the 4-player one. Note that I use GC auto-mathcing as I will only later teach GC achievements/invites/leaderboards etc. Have fun with the sources and let me know if you'd like to see a full step-by-step tutorial much easier to digest than Apple's own documentation on all these questions. When I have some free time (highly unlikely before 22/Nov), I will definitely publish one.
Glad you liked it My this year's last lecture is on Thursday / Friday this week; after that, at last, I'll have some free time to publish the full tutorial. In the meantime, feel free to play with the sources - they all work and are pretty clean.
Very interested, I'll have to try the source. I'd really like to do a game with multiplayer. One point of resistance for me has been the need for a central server, though I suppose this isn't necessary. With Game Center, do you simply use GC to help two clients find each other, than just talk directly to one another, without a central server? I've always been curious about sync issues for multiplayer games, but I suppose that's a more general networking question.
It refuses to compile for me - says Base SDK missing, tho I tried picking iOS in project settings, still won't help
Would be great to see a sample of it working across views, say a main menu witch moves to a multiplayer view with invites and making use of the GKMatchmakerViewController.
Thanksssssssssss for the sourceeeeeee code!!!!!!!!!!! GC: ps why my ipad with i os 4.2 say: this game is not recognized by Game center and then game closes and my ipod 2g with i os 4.2 load game center and then game closes too
you need to update the source to point your own gc setting i assume.. at least the bundle identifier should be changed.. and you need to logo into gc with your test account.. maybee i forgot something..
its really a nice gift from you, to share your source code, which probably can help a few coders like me... thanks a lot... will digg into it now.
Thank you all Unfortunately, I still haven't had the time to write a complete tutorial. I've been given the task to learn Samsung bada programming for future lectures and other bada work and I've spent all my time doing so...
Thanks for the great tutorial. How about the game center speed in real time multi-player game? For example is the bandwidth enough for a car racing game? Can they be implemented by game center, without any 3rd party dedicate server?
I was positively suprised by how fast and lag-less communication over GC was - actually, I had much better results most of the time as through local(!) GameKit Bluetooth. Also, most current car racer games (e.g., Real Racing) also solely use GC for multiplayer.