Posts in Technology (62)
Find out which of your Facebook friends use iPhones, iPads and Android devices
So you've made a great iPad app, and you want to tell your friends about it. However, you can't remember which of your friends have iPhones, iPads, or Android devices. It's annoying to send your friend a link to an app which they can't run!
Facebook recently announced that the Graph API now includes a new field for users called "devices". This looks something like this:
"devices": [
{
"os": "iOS",
"hardware": "iPhone"
},
{
"os": "iOS",
"hardware": "iPad"
}]
It's an array of objects, each with a "os" (iOS or Android) and optional "hardware" (iPhone or iPad, for now).
I threw together a quick Facebook app called "Friends With Devices" using the Facebook Javascript SDK which will scan through your list of friends and sort them into three lists: iPhone users, iPad users and Android users.
Check it out: http://apps.facebook.com/friendswithdevices/
Building Flockwork: Creating targets for free and full versions in a single Xcode project
This is part in a series of blog articles explaining some of the interesting technical hurdles we encountered while building our new iPad puzzle game Flockwork.
![]()
We'll soon be launching a Free version of Flockwork, so I wanted to explain how best to set up your Xcode projects if you're planning to support two versions. The goals were:
- 1. Keep everything in a single Xcode project
- 2. Make it easy to share code and assets
- 3. Keep file sizes of the compiled apps as small as possible
1. Setting up a second target
The first step is to duplicate your existing target (for example MyAwesomeGame). Right/command click the target and choose Duplicate.

OK, what did Xcode just do?
- It created a new target called MyAwesomeGame copy
- It added a new Info.plist
- It autocreated a new scheme for building the project
First you'll want to rename things more sensibly. Press ENTER with the new scheme highlighted and name it MyAwesomeGameFree.

Next, go into Build Settings for the MyAwesomeGameFree target and filter for two settings: first change "Product Name" to MyAwesomeGameFree.

Next, change the "Info.plist file" setting to MyAwesomeGameFree-Info.plist.

Of course, now you'll also need to rename the file to match. You can also move it to a more sensible group, as Xcode dumps it in the root of the project by default.

Now is also a good time to modify the Info.plist, you may want to change:
- the Bundle Identifier (to match whatever you created in iTunes Connect)
- the icon files and default launch image
- Bundle display name
Finally you can rename the autocreated scheme - go to Product>Manage Schemes and rename the scheme to MyAwesomeGameFree.

Time to test it works! Choose the correct scheme from the dropdown, and run!

2. Detecting the target at runtime
It's likely there won't be too much difference between your paid and full versions: for example in Flockwork, most of the game is similar, but we only have 20 levels in the free version versus 80 levels in the paid version. For places in the code where you need different behaviour, you can do a runtime switch. We defined a boolean like this:
#define IsFree ([[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"] isEqualToString:BUNDLE_ID_FREE])
Then it's easy to write code like this:
3. Selecting which assets will be included in each target
Now you have multiple targets, you need to be careful when adding new files to the project. You've probably seen this dialog many times. When you add a new file to the project, you'll now need to ensure the correct targets are checked: make sure both targets are checked if its a file used in both versions, but only one target is checked if its only used in one version.

What about files which are already added to your project? If you go to Build Phases>Copy Bundle Resources you can see a list of all the files compiled into the target. It's important to remove any you're not using. For example, leaving in a full-screen splash from the full versions in your free version could easily add 2MB to your final app size. If you're trying to get under the 50MB over-the-air download limit, that's a lot!
Flockwork is available now in the app store! If you'd like to know when we launch Flockwork Free, sign up to our mailing list at ReignGames.
Building Flockwork: Retina iPad graphics in cocos2d
This is the first in a series of blog articles explaining some of the interesting technical hurdles we encountered while building our new iPad puzzle game Flockwork.
Shortly before our app launched, Apple announced the iPad 3 with retina display. We knew it would be important to support retina graphics in our app. Luckily, it didn't take too much additional effort to get our game ready for the "resolutionary" display!
We're using the cocos2d framework to build Flockwork, and it does have some built-in support for retina graphics. So first we had to:
1. Enable retina display mode
if( ! [director enableRetinaDisplay:YES] ) { CCLOG(@"Retina Display Not supported"); }
First, set enableRetinaDisplay to YES in your AppDelegate. If you build immediately after enabling this, your app will look a complete mess! You now need to provide alternative HD assets for all the static assets in your games: images, spritessheets, fonts, particle effects, and so on.
2. Upgrade your image assets
Every PNG file used in your app will now need an HD version, double the width and height of the original. If your original source files are in vector format, for example Adobe Illustrator files, this shouldn't be too hard. If you made bitmaps in Photoshop, there may be some extra work.
Cocos2d uses the convention of a -hd suffix, for example the hi-res version of a file called button.png (20x24 pixels) would be button-hd.png (40x48 pixels).

After adding the new file to your project, cocos will automatically load the HD version on a retina display. This is handled by the CCFileUtils class.
If your project has a large number of image assets, it can be easy to lose track of which files have been upgraded to HD. It's also very important to ensure that the -hd version is exactly double the size of the standard version. A cautionary tale: in Flockwork, we were using the pixel size of some assets to determine the size of Box2d physics bodies. Because some of our -hd assets were off by a few pixels, the physics of the objects changed in Retina mode, causing some very obscure bugs!
To avoid this, we wrote a little Python script to scan through our assets folders.
import subprocess,re,glob def dimensions(path): #get dimensions of an image from sips dimensionArgs = ['/usr/bin/sips', '-g', 'pixelHeight', '-g', 'pixelWidth', path] sips = subprocess.Popen(dimensionArgs, stdout=subprocess.PIPE) dimensions = sips.stdout.read() dimensions = re.findall(r'pixel(Height|Width): ([0-9]+)', dimensions) if len(dimensions) == 2: label, height = dimensions[0] label, width = dimensions[1] height = int(height) width = int(width) return width, height def parse(path): #parse all files and check that theres an HD version with the right dimensions files = glob.glob(path) for f in files: if "-hd" in f: w2,h2 = dimensions(f) w1,h1 = dimensions(f.replace("-hd","")) if w1*2==w2 and h1*2==h2: pass else: print f+" is not double the size of "+f.replace("-hd","") ratiow=float(w2)/float(w1) ratioh=float(h2)/float(h1) print (ratiow,ratioh) #parse everything in the specified folder parse('Resources/images/*.png')
Note that Flockwork is iPad-only. If you're trying to make a Universal app (iPhone and iPad) you may have to provide up to four sets of images for each asset!)
3. Upgrade your spritesheets
Spritesheets work similarly to images. First, you need to make HD versions of each of the frames within the spritesheet. Then, create a spritesheet double in size to the original (for example, a 2048x2048 sheet instead of 1024x1024). We used the excellent Zwoptex. In your HD spritesheet, you then need to add all the HD assets instead of the SD ones, save and publish. All being well you'll now have files named something like:
sprites_campaign_4.png (1024x1024) sprites_campaign_4.plist sprites_campaign_4-hd.png (2048x2048) sprites_campaign_4-hd.plist
Add the new .png and .plist to your project, and you're good to go.
4. Upgrade your fonts
If you're using any bitmap-based fonts, you'll also need HD versions there. We use GlyphDesigner to create our fonts files, which are then used by CCLabelBMFont. Make a copy of your GlyphDesigner project, and double the font size, for example a 35-point font would now be 70 points.

5. Test, test, test
Once all your images and fonts are in place, it's time to test. You can do testing in the iOS Simulator in Retina mode, but its likely you'll get a very slow frame rate. There's no substitute for getting a real iPad 3 to test on (even if that's a major challenge in China!).
Test all the screens and functionality of your app. It's likely you'll find some glitches or areas you've missed. For example, Flockwork uses particle effects: we needed to create HD assets of those too. We also found we'd got a few filenames for HD assets switched - this is something only a human is likely to spot!
Let us know your cocos2d retina war stories in the comments - and of course, if you haven't already, download Flockwork!
Sh*t iPhone Developers Never Say
Last month I attended Shanghai Barcamp 10. It's become something of a tradition for me to give a talk on a slightly offbeat topic at Barcamp, whether it's Love Hotels and Unicode or HTML5 and sarcasm.
Now, you're probably aware of the recent popular internet meme Sh*t Girls Say and its spinoffs like Sh*t Asian Girls Say.

The meme quickly got more and more specific.

As I am neither a Jehovah's witness, nor a Asian girl (well, except on Friday nights) I thought I'd try something a little closer to home, so: what phrases do iPhone developers never say?
First up,

Capturing hi-resolution video from an iPad
We recently wanted to create a trailer for our upcoming game Flockwork. You can see the end result here, but we thought we'd share some of the challenges we overcame to make the video.
