Converting Sound to caf for use with OpenAL
Nov 10th
When creating my first game, Pub Pong, which you can download from here by the way, please do it will mean food for a week, but anyway, I was trying to create a fast and reliable audio system. Wavs, Mp3’s were all trialled in my sound engine, but there always seemed to be a trouble whilst loading them in. They were too big, and also the key point to remember about the apple audio toolbox is that if the file is not in caf, it will convert the audio file to it before use, which can cause a small lag in the time from loading to playing.
The best way to imagine it, is that if you had talking in your game, with lip sync, the converting of the files in run time would cause the lips to be out of sync and look a lot like the film Kung Pow. So it is best to convert before compiling.
What this mini tutorial will do is show you how to convert the files using the terminal, a device that Linux users have surgically attached to themselves. Right lets ride this wave:
- First of all, open up terminal. That should be a case of either opening it from the spotlight bar or clicking on it from within the dock.
- For those who are not familiar with the terminal, we will not be using many commands, just a few.
- You first have to get to the lcoation of the files that you are going to want to change.
- First of all list out all the items that you can currently see in terminal, type ls, then hit return:

- From there, you need to to go to the directory where all your files are, mine are in a folder called Audio, so cd Audio will get me there. If yours are in a folder of a different name, it would be cd insertfoldernamehereyeah.
- Then it gets nice and simple as it is an ease to access the converter.
Pub Pong on Sale Now!
Nov 9th
If you like any of the code, and you really want to see how it all works then download it from the app store. The link for which is located here:
This will make my day and also mean that if you buy it, i can buy some Christmas presents for my family and make sure that they are not eating re-caramelized carrot skin on Christmas day.
I also have some promo copies to give out to some people who feel like commenting.
Best iPhone apps at AppStoreHQ
View Transitioning and Animation
Oct 27th
Hello campers!
Don’t you just hate it when you find yourself with a UIViewController and a handful of those UIViews and you’re using the ol’ addSubview removeFromSuperview jargon and its like they disappear but its so fast and short lived and really you want to wave off and greet those gorgeous UIViews properly. I know I do!
Anyway what I’m waffling on about is how to use Core Animation transitions. So heres a quick learnings on how to fade in a UIView from within your view controller.
Behold below the magical code for fading a UIView onto your screens!
‘theWindow’ is a UIView declared in the header used as a temporary variable to access the current view controller via the ’superview’ function. The second line of code is where you add the UIView you want to the screen. In the next 4 lines we get an instance of ‘CATransition’ and assign it the properties we want for our animation. Replace ‘0.5′, ‘kCATransitionFade’ and ‘kCAMediaTimingFunctionEaseInEaseOut’ accordingly to get your desired affect. Then assign the animation to the layer using the last line of code. Voila! Fading in UIView. Blooming marvellous.
An Idiots Guide to Setting up iPhone Peer Picker – Part 1
Oct 19th
This tutorial will guide you through setting up a view controller so it will be ready for use with a peer picker. In reality, it is pretty simple. What you need to bear in mind though is that the peer picker itself is very temperamental sometimes. Also it takes around 30 seconds for your first connection to be made as the Bluetooth antenna uses the same antenna as the Wi-Fi one does in the iPhone. Hence, Bluetooth works best when the Wi-Fi connection is turned off.
I recommend having a device ready for this tutorial as there are huge difference between testing on simulator and a device, especially where the Bluetooth connection is concerned. In the simulator, the ‘Bluetooth‘ connection is not done via the integrated mac Bluetooth but over the wi-fi network. It basically poses as ‘Bluetooth‘. So when making a multiplayer game, you really need to test it on devices.
Ok , first up download this template that basically is just a view controller. All the frameworks that you need have been included, but i will run through them. PeerPickerTutorialBase
- Lets start at the start. Open Xcode with this downloaded template. It is empty as you can see apart from a single view controller. Hit CMD+Enter to launch it in the Simulator. You s hould have an empty view with just the word FooBar on it.
- Now, go to the view controller for this project, named PeerPickerTutorial View Controller. Rolls off the tongue doesn’t it. Within the implementation file (THE M FILE) de-comment out viewDidLoad. Maybe even put a log in there just so you know that it has loaded.

- Right that is a nice easy part. Now i want you to import the GameKit.Framework into the frameworks folder. But don’t copy the files into your project. That is just bad news.
- Add import code line to the top of your view controller .h file.
- Also, make sure that the header file is the delegate of GKSession and PeerPicker Controller. If you don’t understand delegation I suggest you look further back into other tutorials. If you want to carry on though, the code looks like it does below.

- In your View Controller h file, it is now time to set up the varialbes that the peer picker will be using. First you need a GKSession variable, call this anything you like, mine is called gameSession, for ease of remembering.
- You will then need an NSString variable to hold your peers devices name in, call this opponentId.
- You then need a heartbeat variable which is of type NSDate. This is taken from the apple documentation and this variable is used to determine packet loss etc.
- Finally two integer variables, called gameUniqueID and gamePacketNumber

- Those are the variables that you need to get the peer picker up and running.
- Set gameSession, opponentID and peerName is preoperties and don’t forget to synthesize them. This is important as these variables are important.
- Now onto the m file. The apple GKTank source code can give you all the code for the next bit, but I recommend that you don’t just copy and paste it out and then raise your hands in celebration. It is better to understand what goes on with the PeerPicker. Read the apple documentation here.
- First of all you need to be able to get the peer picker up and running. this involves a new function that can be called from say a button, or touching a screen. I prefer a button, so that is how we are going to do it.
- In Interface Builder, drag a button onto the view. Type the title ‘Search’ on it. Now create an IBOutlet in the header so we can link to this button and call it searchButton. The function created is called startPicker and this function needs to be an IBAction and here is what you put inside of it.
- NOTE: If you are trying to connect and it is not appearing in Interface Builder, make sure that the function is declared in the header. That is a common error. Right take a breather or something as you are going to need it. It now becomes code intense.
- The peer picker will not work or be of any use until you implement its delegated functions. These are as follows:
- -(GKSession*) peerPickerController: (GKPeerPickerController*) controller sessionForConnectionType: (GKPeerPickerConnectionType) type;
- - (void)peerPickerController:(GKPeerPickerController *)picker didConnectPeer:(NSString *)peerID toSession:(GKSession *)session;
- - (void)peerPickerControllerDidCancel:(GKPeerPickerController *)picker;
- - (void)session:(GKSession *)session peer:(NSString *)peerID didChangeState:(GKPeerConnectionState)state
- Those four functions are delegate functions and respond to data sent back from the peer picker. So what you put in these functions determines the functionality of the picker. You can these functions available in any delegate, they do not have to be the view controller, that is if you wanted your peer picker to appear on a different view. Anyway i digress.
- These functions are now full of amazing code as you can see from the final tutorial file, that is if you skipped ahead you naughty chickens. If you haven’t skipped ahead, enter the following into your functions:
Those Pictures are the biggest i can get them without becoming too grainy. Click on them to get full size!!
- Right with that code in your .m file, you should be ready to give it a go. The hostGame and joinGame are functions that I will come to in the next tutorial, so for now, just comment them out.
- For now, you can test this in the simulator, run it and hit your button. You should see the following,
Congratulations, your peer picker is active. Now if this code is installed on another mac with a simulator the two devices will be able to connect. Give it a go is all i say. Any comments to make or areas of confusion drop us a comment or an email.- Alas, here is the final code as well. PeerPickerTutorial
If you like any of the code, and you really want to see how it all works then download it from the app store. The link for which is located here:
Derren Brown – Lets look at this logically…
Sep 12th
Everyone will be sick of this topic in no time but I thought I’d get my two cents in while its still buzzing around. I’m talking of course of how Derren Brown predicted the lottery. The explanation was released last night and I, like many others don’t really believe it. Now I’m no Deborah Meaden myself, but the lottery is something that (trusting in Camelot’s technology of course) to be truly random. Its not like betting on a horse or predicting a football match, by definition it is impossible to accurately predict the outcome. You can monitor which balls appear to come out more often than others but this does not in anyway increase they’re likelihood of coming out the next time.
So essentially what I’m saying here is Brown’s claim cannot be true so the purpose of this post is to look through the options logically to see what is in fact going on here. So lets start from the beginning…
Derren Brown – Mathematical Genius?
He’s no dummy thats for sure but lets get the facts straight here, he’s a world renowned magician not mathematician… So we’ve already poo-pooed this theory ^^^, on to the next…
Camelot Are Pulling The Strings
The implications of this one should mean we can rule it out straight away. Camelot are fixing the lottery. Lets think about that for a second, Camelot are fixing the lottery so kindly ask Derren Brown to accurately predict the numbers leaving them wonderfully exposed. This doesn’t make a lot of logical sense so lets sweep it under the carpet eh.
Camera Trickery, Magical Fantastic Ink etc.
You’ve probably heard of the specifics of these, this excellent youtube video demonstrates the camera trickery pretty well:
We won’t dawdle too much in this section, but if we are to draw any conclusion to how the man did it it would probably have to be one of the solutions here.
Ok so we’ve ruled out Brown’s actual explanation, we’ve ruled out rigging and we’ve settled on some form of other trickery whether it be to do with cameras and voodoo ink, either way it doesn’t really matter. I’m a big Derren Brown fan and I don’t like the idea that he is not being entirely truthful with us this time, yet I think it through back and forth logically in my head and can think of no other explanation. Regardless of the answer though, he has achieved what we can only imagine to be his primary aim, everyone in the whole damn country is talking about this right now, its a publicity dream (Channel 4 win).
If it all comes out that Derren Brown did somewhat bend the truth in the big reveal yesterday at least it won’t be as big a fail as this poor magician’s failed stunt:
Do a barrel roll my friends. Do a barrel roll.
When NSMutableArray and NSUserDefaults became friends…
Sep 2nd
So if you’ve ever tried putting an NSMutableArray in the NSUserDefaults you may have come across this fancy pants error:
-[NSCFArray replaceObjectAtIndex:withObject:]: mutating method sent to immutable object’
Or something along those lines, perhaps ‘replaceObjectAtIndex’ is ‘addObject’ or some other method of the NSMutableArray class, either way, just add in this magic bit of code to your workings accordingly and fingers crossed the error will vanish into the night in Batman style via the Batclaw aimed at a conveniently placed grate (Arkham Asylum for the iPhone anyone?):
NSUserDefaults* current = [NSUserDefaults standardUserDefaults];
yourNSMutableArray = [[current objectForKey:@"YourKey"] mutableCopy];

Warning: local declaration hides instance variable
Sep 2nd
So you are programming away nicely and this warning rears its ugly face.

What does it mean and why does it occur? The reason for this is, in the example above, is that ‘gameHandler‘ is being in-instantiated again and is using the same name as a variable that has already been named in the class instance. There are two reasons for this error appearing and there are two ways to change it depending on what you were originally trying to do.
First:
You may be passing in the parameter handler into your function and you want a local variable to take the properties of it. This is perfectly possible, but the structure of the code would be the cause for this. In the example above, the allocation of the variable type is before the parameter is copied to the new instance variable. If you allocate after the passed variable has been passed, then the variable will start with that functionality.
Second:
The simpler change, there are variables that are called the same as the parameter being passed in. The best way to stop this occuring is to create a naming convention for all parameters, just to differentiate them from the class variables. For Example:

By creating a parameter convention, it keeps a flow of what parameters are called and also means one is not trying to remember what variable ‘BigLongStuff’ actually does. Hope that helps those when they come across this warning.
Meanwhile, here is a picture of a horse.

My Lovely Horse
Remember to Always Save Interface Builder
Aug 12th
Just made a massive fail, always need to remember to save anything on interface builder.
Also
Make sure that you link the view controller to the file owner, otherwise then it will not work and the application will just crash.
I am a retard.
Views, View Controllers and a Head Full of Recipies for Pie
Aug 12th
Great Deborah Meaden’s beard! I probably know more about pie cookery than I do about view controllers. I’ve been programming bits and bots for the iPhone for a fair bit now but I still find myself starting off apps in the same old way. I crack open a can of Interface Builder and delete that mofo View Controller mjobber via this window hither:

Deletion via Asda's homebrand...
I throw another view in via the Library and make sure its placed inside the ‘Window’. Inside the identity toolbar I give it a class name of ‘MainView’ and then go File > Write Class Files.

Main View in Main Window
Job done. The header and methods files are created in X-code and that is where I begin writing my app. My View Controller files remain curiously sparse and I question what purpose they serve at all. I’m sure they do something and any enlightenment on the matter would be muchly appreciated.

Interface Builder








