Blog Archives

One-game-a-month update

After a good start in January, I have to admit that not much has come of my plan to push out one new game each month. Shame on me!

February: I started work on a clone of Defender of the Crown (an Amiga classic), or at least the strategy portion of it. Alas, I got no further than the very basics:

My February game for One Game a Month

The goal is to conquer all enemy territories by sending out your campaign army. You only have one army and you don’t know where the enemy armies are.

As far as strategy games go, this one is pretty simple. But as I’ve never made a turn-based strategy game before, starting with something simple won’t hurt. I do want to revisit this game at some point because I like the idea.

March: No work on a #1GAM game but I did give a 15-minute “blitz talk” at NSConference, which was really cool to do. The topic: why making 12 games in 12 months is a good idea. :-)

My argument was that doing a challenge such as One Game a Month is good for learning to finish projects instead of just starting and abandoning them a week later. In addition, imposing constraints on yourself – such as an extreme time limit — help you become more creative.

My blitz talk at NSConference

If you’re into iOS development you should really buy the NSConference videos, they are great. And visit the conference next year!

April: I don’t know if this counts, but I did a remake of Juicy Breakout. This game is from a talk by Martin Jonasson and Petri Purho titled Juice It or Lose It. They show how to take a boring breakout game and make it really awesome, not by changing the gameplay but by adding tons of cascading animations and other effects.

The original game was done in Flash and their presentation isn’t really about the actual code, so I thought it would be cool to remake the game in Objective-C and Cocos2D for the iPad.

Juicy Breakout for iPad

Pssst, here’s a little secret: I’m making a tutorial video out of this for RayWenderlich.com. Stay tuned for that. :-)

Now available in print!

If you still haven’t caught up with all the new APIs in iOS 5 and iOS 6 — which wouldn’t surprise me as these releases added a ton of new stuff — then do yourself a favor and get the books iOS 5 by Tutorials and iOS 6 by Tutorials.

Of course, I’m biased because I co-wrote these books, but if you enjoy reading the tutorials from www.RayWenderlich.com, then you’ll enjoy these books too. It’s the first place I go to when I want to learn a new API.

Both are now available as printed books and they are huge, two volumes each:

Print versions of the iOS by Tutorials book

If you already bought the PDF version, then you get a discount on the printed books. Sounds like a pretty good deal to me (log in to the private forums for the instructions).

This is a good opportunity to get up-to-date on the latest and greatest that the iOS SDK has to offer — at least until iOS 7. :-)

Grab your copy at the raywenderlich.com online store

iOS 6 by Tutorials

Good news! iOS 6.0 was just released and that means I and my co-authors can finally make our latest ebook, iOS 6 by Tutorials, available!

iOS 6 by Tutorials book

If you want to take advantage of all the new features from iOS 6, such as Auto Layout, Pass Book, UICollectionView, the new Social Framework, and much more… then this is the book for you.

In fact, there is so much to tell that the book ended up being over 1500 pages! That should keep you busy until iOS 7 comes out. ;-)

You can get iOS 6 by Tutorials exclusively from RayWenderlich.com.

And there is no better time than now, because we’re running a launch special that gets you a nice discount, especially if you buy it in combination with our previous iOS 5 by Tutorials ebook.

As part of the launch celebration we’re currently giving away a lot of free stuff in the “iOS 6 Feast” at raywenderlich.com, so head on over and see if you can score some!

P.S. I also updated my iOS Apprentice series for Xcode 4.5 and iOS 6. It doesn’t really go into depth on all the new features of iOS 6 — that’s what iOS 6 by Tutorials is for — but it does give you instructions for working with the latest versions of Xcode, so it’s totally up-to-date again.

If you’ve already purchased The iOS Apprentice (thanks!) then you can find the latest downloads in the forums.

Have fun playing with iOS 6! I know that we did when we were writing this book. :-)

iOS Apprentice Tutorial 4 Available

I’m happy to announce that the latest ebook from my popular iOS Apprentice series is now available. :-)

The StoreSearch app

In this tutorial you’ll build StoreSearch, an app that lets you search the iTunes store for songs, movies, books and software. You’ll learn about making your mobile apps talk to web services, iPad programming, internationalization… and lots more!

You can get the iOS Apprentice at the Ray Wenderlich store.

Transparent JPEG Images

When you distribute images with your app you usually pick the PNG or JPEG format. The advantage of JPEG is that it often compresses better — especially for photos — but unlike PNG it unfortunately does not support transparency.

The transparency in a PNG file comes from the so-called “alpha channel”. For every pixel not only red, green and blue values are stored but also an “alpha” value that determines how transparent that pixel is. A value of 255 means this pixel is fully opaque, 0 is fully transparent, and anything in between will mix the pixel’s RGB values with the underlying color.

This is probably an old trick, but by saving a JPEG image not as one but as two image files you can still have transparent images. The first image is the regular JPEG with as much compression as you can get away with, the second image is the alpha channel. This is a grayscale image with black representing fully transparent, white fully opaque, and gray everything in between.

 

Source image and its alpha channel
We can combine these two images at runtime to make the image transparent again. Because of the JPEG compression we lose a little bit of clarity but if you tweak the compression settings you can usually get away with it.

I wrote a simple category on UIImage that lets you do this.

Preparing your images

1) Export your image from Photoshop as a PNG with transparency.

2) Export the image again as a JPEG, using suitable compression settings. The background should have a solid color, typically white or black but any color will do.

3) Save the alpha channel to a separate JPEG or PNG image. I couldn’t find an easy way to do this from Photoshop, but the ImageMagick tool can do it without problems.

If you have ImageMagick installed, open a Terminal and go to the folder that contains the exported PNG image. Then type:

convert -alpha Extract -type optimize -strip -quality 60 +dither Source.png Alpha.jpg

This extracts the alpha channel from the PNG image and saves it as a JPEG file. You can tweak the level of compression with the -quality parameter. If you specify “Alpha.png” instead of “Alpha.jpg”, ImageMagick saves the alpha channel as a grayscale PNG-8 file. You should use whichever one makes the smallest file size.

Combining the images

1) Add the two JPEG images (the non-transparent source image and the alpha channel) to the app.

2) At some point, call the mh_combineWithAlphaImage:backgroundColor: method to combine these two images into a new, transparent, image.

3) Depending on your app you may want to do this only once and then store the transparent image as a PNG in your app’s Caches folder.

That’s it, quite easy.

Some notes

The alpha image does not have to be a JPEG, it can also be a PNG file. If it is a JPEG then it can have different quality/compression settings from the main image.

The current implementation works well but is not as fast as it could be. It also uses more memory than is strictly necessary. I might rewrite this at some point to use the Accelerate framework or Core Image.

Not all images compress better as JPEG. You should use JPEG only where it makes sense.

Check out the source code at Github.

Bird image by Sias van Schalkwyk