Remember the 90’s POGS craze? Now it is on the iPhone. Just remember to grip your device tightly when using it to throw the Slammer.
One cool technical note is that we are using iPhone basic 1.5.1 and we were able to integrate with the iPhone SDKs GameKIt !!! It is a completely custom solution we created but the key to making it work is reading and writing to player prefs. We run a loop in a separate thread to keep checking and then writing to player prefs when needed. It is basically the same way that Stinkbot’s Enhancement pack works for those of you that understand the Objective-c side of that code.
Basically to get the GameKit to work we took these steps.
Step 1
Created a separate class to manage the multiplayer Called COMMON_API
Step 2
In AppController.h we created an object called.
COMMON_API *commonAPI;
Step 3
In AppController.mm modified applicationDidFinsihLaunching
- (void) applicationDidFinishLaunching:(UIApplication*)application
{
printf_console("-> applicationDidFinishLaunching()\n");
[self startUnity:application];
// check for a command, but not on every frame
commonAPI = [COMMON_API global_api];
[commonAPI startLoop];
}
Step 4
Start loop function looks like this:
- (void)startLoop{
NSLog(@" ***************** startLoop ********************");
[[NSUserDefaults standardUserDefaults] setObject:@"" forKey:@"Player1PogsString"];
[[NSUserDefaults standardUserDefaults] setObject:@"" forKey:@"Player2PogsString"];
[[NSUserDefaults standardUserDefaults] setObject:@"" forKey:@"Player1Ready"];
[[NSUserDefaults standardUserDefaults] setObject:@"" forKey:@"Player2Ready"];
[[NSUserDefaults standardUserDefaults] setObject:@"" forKey:@"playerNum"];
[[NSUserDefaults standardUserDefaults] setObject:@"" forKey:@"sb_return"];
[[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"P1PogsWonCount"];
[[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"P2PogsWonCount"];
cmdTimer = [NSTimer scheduledTimerWithTimeInterval:.20 target:self selector:@selector(checkForCommand) userInfo:nil repeats:YES];
}
Step 5
Check for command looks like. (You will see some of the code we re used from the Enhancement Pack in the first few lines of code.)
- (void)checkForCommand {
NSString* cmd = [[NSUserDefaults standardUserDefaults] objectForKey:@"sb_command"];
// if nothing, return
if (!cmd) {
return;
}
if ([@"" isEqualToString: cmd])
{
return;
}
//a whole lot of code below this
}
The COMMON_API.h and COMMON_API.m are attached. Code is give as is so you use it at your own risk. If you don’t understand basic Objective-c this may be over your head.
Clever Coding
We do custom in-house development. We are also available for hire to do custom development for companies around the world. But only 2 of the 7 of our iPhone developers are also Unity Developers so most of our development is done in xCode.
231407–8291–$gamekitapi_v02_157.zip (5.65 KB)