Building games one loop at a time…

What the iPad means to me.

March 14th, 2010

First and foremost, I’m biased.

One of the many things I do to keep myself amused is write iPhone/iPod apps. With that, the iPad is gold rush territory. New platform, that lets you build on the skills you already have, still offers backwards compatibility in several modes, and enough new functionality to make it exciting.

There is a lot of opportunity there for those that are bold enough to build iPad specific apps, and you’re going to have an audience of several hundred thousand, if not millions in a month that are desperate for things that make their shiny new toy shine even more. Of course I’m going to get one.

I can see dozens of innovative things that could be done with this, quite easily. I’m probably going to file patent applications on a number of them, ranging from the utterly off the wall, to the merely not been done before.

People are viewing it as an over-sized iPod touch. While it could be taken as such, there is much beyond that that could be done, and likely will be done.

It is that “beyond that” that excites me. Not because of the innovation of the artifact itself, but what it enables.

iPhone Development Books

March 10th, 2010

As a developer, I try to snag information from as many sources as possible.  One of these is books.  While they do get rather quickly out of date, they do have a lot of advantages.

I’m making a page here to act as a canonical list of iPhone Development books.  While it’s a relatively primitive list at the moment, I hope to have it converted to one where you can rate them soon.  Expect to see this list up and running in the next day or so – look for it in the pages section of the sidebar.

On the road…

March 1st, 2010

Travelling for my day job this week – I’m at SMX West – Search Marketing Expo, in Santa Clara, California.  I’m in the burgandy and blue striped shirt, if any of you are down here for this as well.  Will be interesting to talk to some of the advertising reps, and see what insights I can get, both for ads on my app, and for my blog.

iPhone twitter feeds

February 28th, 2010

Got a twitter feed that iPhone developers (and users) might find interesting? Leave a comment here, and I’ll assemble them into a concrete list.

Growing pains

February 27th, 2010

I’m sure this is something every blogger out there has gone through at one point or another – what do I want my site to look like. While it’s tempting to say the heck with it, and just use a bog-standard default Wordpress theme, that just doesn’t seem right. I’ve not found anything that seems to suit my wants and needs completely, so for the next day or two while I’m travelling, I’m going to slowly cobble together my own WP theme that does what I want it to do, and looks the way I want it to look.

Translation: Expect the way the site looks to shift radically over the next few days, as I refresh my PHP skills, and take apart a number of successful themes to see how they do things.

Memory, UIImage, and double buffering

February 27th, 2010

When building apps for the iPhone, memory is always a concern.  If you run out of memory, the OS will eventually kill your application off.  While most developers work hard to do the right thing, and manage memory correctly, even if you follow the rules, you can still run out of memory.

UIImage imageNamed: is a good example of this.  The method loads in an image from a file, and caches it, which gives you good performance.  Unfortunately, there is no way to clear out that cached image.  Even if you release the UIImage object, the cached bitmap will remain.

If you only have a small number of images in your program, and can handle having them all loaded in, this is not a problem.  If, on the other hand, you have more images than can fit in memory, you have a problem.  (Remember that the cache is storing the uncompressed images – which will be using WxHx4 bytes – if you have a 100×200 image, that’s 80K of memory.)  This gets far worse when you have animation sequences – a simple 24 frame animation (which might only last one second) would eat up nearly 2 meg of ram. And that’s memory you can’t get back.

So what to do?  There is a different instance method you can use with UIImage, namely initWithContentsOfFile: which will not do the caching.  Unfortunately, this also has a side effect, in that when you want to use the Image, it needs to be decompressed at that point.

If you are using a single image for something, that’s probably acceptable.  If you are using the images in an array to feed into an UIImageView via setAnimationImages, you are going to quickly notice a problem, depending on the size and number of your images.

The first time that you try to run the animation, the images will need to be uncompressed before they can be displayed. Worse, they will all need to be umcompressed before the first one is displayed.

This gets worse though.  Lets say you have 60 images, each of which is going to display for 0.08 seconds.  That’s 12.5 frames per second.  When I did this, it was with images at a size of 200×200 pixels.  I’d precooked the images so that they had numbers on them, so that I could see what showed up, and when.  I figured that the decompression stage would result in my animation being delayed until it was complete.  That was right.  What I hadn’t figured would be that the internal timer that was deciding which frame to display didn’t wait.

- (IBAction) testAnimation {
UIImageView *myAnimation = [[UIImageView alloc] initWithImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"1" ofType:@"png"]]];
myAnimation.center = CGPointMake(160, 160);
[self.view addSubview:myAnimation];
[myAnimation setAnimationImages:animationArray];
[myAnimation setAnimationDuration:0.8];
[myAnimation setAnimationRepeatCount:-1];
[myAnimation startAnimating];
}

The net effect was that there was a delay, while nothing was displayed, then the first frame to be displayed was frame 7.  If I ran the animation a second time, it displayed correctly, since the images had already been decompressed once.

Note that this was also only visible on the actual device (an 2nd gen iPod Touch).  On the simulator, things ran fast enough that it wasn’t visible.

If we are trying to switch between sequences of animations, we can’t afford the delay, or missing frames if we don’t cache the images, and we can’t afford the memory hit if we use the caching.

The solution is to handle our own animation cycle, and force the decompression of the images as needed, ideally taking place while the previous image is still being displayed.

Double buffering would do this quite nicely, but what can we use as a back buffer?  A simple thing would be to use an extra UIImageView, since that already knows how to do the decompression properly.

- (IBAction) startAnimationLoop {
self.showA = TRUE;
currentFrame = 0;
self.a = [[UIImageView alloc] initWithImage:[animationArray objectAtIndex:0]];
self.b = [[UIImageView alloc] initWithImage:[animationArray objectAtIndex:1]];
self.timer = [NSTimer scheduledTimerWithTimeInterval:0.08f target:self selector:@selector(advanceAnimation) userInfo:nil repeats:YES];
}

- (void) advanceAnimation {
currentFrame = (currentFrame + 1)%[animationArray count];
if (showA) {
[i setImage:[a image]];
[b setImage:[animationArray objectAtIndex:currentFrame]];
}
else {
[i setImage:[b image]];
[a setImage:[animationArray objectAtIndex:currentFrame]];
}
showA = !showA;
}

In the code shown above, we’re really doing triple buffering – We have two off screen UIImageViews – a and b, which we preload with the first couple of images.  we then alternate which one we pull the decompressed image out of, and copy it into the on screen UIImageView (i). Once we’ve done that, that frame of animation is visible.  We now have 0.08 seconds before the timer will trigger, and we need to have the next image ready to go.  We do that by asking the other UIImageView to set itself to the next image in the sequence.

Running with this, we wind up with no missed frames, and no noticeable delay before the first frame of animation starts to play.

I’ll clean up my complete project folder, and upload it to the Software Section later this afternoon.

Well, we’re visible now.

February 26th, 2010

27 minutes after updating my ping settings, my first spam comment arrived. Sigh. I love the web. Really, I do. Just not this aspect of it.

In real terms, it is still a problem – how to let others know about your site, while not being seen as a source of spam yourself.  The best way is to actually have relevant content, and keep others wanting to link to your site.

Back to writing useful stuff now – code samples for some animation will be posted tonight.

Finding information

February 26th, 2010

iPhone development, while not that hard, is non trivial when you don’t have decent documentation or examples to follow. This is not to say that the documentation produced by Apple is not good. On the contrary, it’s quite good. But it’s not enough. I’ve spent a fair amount of coin on building up an iPhone development library (and am likely to spend much more in the upcoming weeks), but finding info on the web is important as well.

The really big list of iPhone SDK development links is an awesome resource. They have gathered over 70 links to critical sites with information you need to be reading through if you want to build better software. I know that I’ve got them at the top of my bookmarks.

Advertising in your App

February 26th, 2010

I started a couple of discussions on LinkedIn asking for opinions on who to use for an advertising provider in my ad sponsored app.

I didn’t expect the range of responses that I got.

As a bit of background, I opted for AdMob, mostly due to having heard the most about them, and had gotten to the point of having their ad block integrated in to my app when I posted looking for alternatives.

I’ve been contacted directly by several providers – Quattro Wireless and InMobi.

It’s hard to know who is going to be the best choice, given that there are so many to pick from.

On one hand, you can go directly with a direct provider, such as AdMob (Google), or Quattro Wireless (Apple), or go with an network, such as AdWhirl, or MobClix.

An advantage of the single provider is that your revenues are concentrated – once you’ve reached their threshold dollar amount, then they will cut you a cheque.

A disadvantage of the single provider is fill rate – If they don’t have an ad to deliver to you, then you have no revenue opportunity on that use of your application.

The exact opposite applies to the networks.

With someone like adwhirl, you are still signed up separately with the individual providers, and need to wait until each hits their threshold before you get paid.  If you are pulling advertisements via them from 4 providers, then you are likely to take 4 times as long before you get your money.

Note that not all ad networks work like that – MobClix does not have a minimum payout, and you don’t need to wait for them to cut you a check. (Thanks Megan)

On the plus side, you are far more likely to have 100% fill rate – you go to the network to get an ad, and it tries all the providers you’ve picked from (potentially at a configurable ratio as to who to try first), and if that provider can’t supply an ad, they go to the next, and so on.  You’d need to fail to get an ad from all their providers for you not to get anything to display.

One more factor to keep in mind is reporting.  Each provider, and each network, provides a different set of metrics that they can provide to allow you to better tune your program to maximize your income, and to track the usage of your apps.

So what to do?

For my first app, I’m sticking with a single ad provider – in this case, AdMob (mostly because I’ve already gone to the trouble to integrate them in).  My next ad supported app, I’ll probably go for a network such as MobClix that covers a range of  providers.  Keep watching for more on this as things progress.

Getting things done

February 25th, 2010

I’m nearly at the point of getting my first iPhone application submitted to the App Store. It’s been quite an interesting process so far, and to be honest, quite an enjoyable one.  The iPhone SDK is only $100 and a 2.5 gig download away, well within the reach of most independent developers. (Well, to be fair, you need to add another $1,000 or so for a mac to work on, but even that’s not really that much.

Along the way, I’ve gotten advice and feedback from many sources, the iPhone groups on LinkedIn being a major source of help.

I’m slowly building up a collection of useful classes/code, and I’ll be sharing those via this blog as the days roll on.

I’ll be talking more about my first app once I’ve finished recording the sounds I need to finish it off, and have it safely submitted to the app store.