TouchTargets App

The TouchTargets application tutorial walks us through the creation of the simple game, TouchTargets. This simple game hides some not-so-simple custom classes, however, and we go through the new code line by line. The new classes allow us to pull out and reuse OpenGL program functionality, read in character sets in custom fonts for displaying text in OpenGL, and using manager classes to manage groups of related objects. We also create a singleton class and see what makes it special.

By the end of the tutorial, we have created a complete game in OpenGL ES 2.0 on the iPhone, and have passed an Instruments session with no memory leaks.

 

Chapter 1: Rounding Up OpenGL

We take a close look at what makes up the OpenGL ES 2.0 processing in the Xcode application template. By the end of the chapter, we have a solid idea of what we can pull out to use for our new custom OpenGL program class.

 

Chapter 2: Pulling Out OpenGL

Chapter 2 walks through the process of creating our new EDOpenGLProgram class, and making it abstract enough to be used easily from another class.

 

Chapter 3: Converting to the New EDOpenGLProgram class

With our new EDOpenGLProgram class created, we turn to the view controller and remove nearly all of the OpenGL ES 2.0 code for loading, compiling, and linking OpenGL ES programs and shaders. We upgrade the view controller to use our new class and make sure that everything still works properly.

Related Xcode project code
TouchTargets_ch3_comments.zip or TouchTargets_ch3_clean.zip

 

Chapter 4: Say “Hello, World!”, OpenGL

OpenGL is astoundingly pretty, but it sure doesn’t say much. In this chapter, we examine a few ways to remedy this, and spec out a new class that can import character sets from font sheets to facilitate the display of arbitrary text strings in OpenGL.

 

Chapter 5: Building the Importer

After thinking through our design in chapter 4, we now construct our new font importer class.

 

Chapter 6: Using the Importer

Once the coding of the font importer is complete, we take a break from the code to think through how we can use this new class, and how tightly it should integrate with the OpenGL coordinate system.

 

Chapter 7: Creating the Text String Class

Chapter 7 brings us through the entire process of creating the EDTextString class, a complicated and versatile class that makes full use of our new EDFontImporter class. We also take time to learn about converting coordinate systems between the iPhone screen and OpenGL space.

 

Chapter 8: Managing Our Text Strings

Chapter 8 introduces us to manager classes, objects designed to facilitate the handling of multiple instances of another class. The new EDTextStringManager class is constructed to allow a program to easily create and maintain multiple text strings in OpenGL. We also discuss a problem with creating new shaders from scratch in Xcode 4.

 

Chapter 9: Finally, OpenGL Says “Hello, World!”, and More

We finally implement all of the new font importing and text string handling code in the view controller, adding a new method to detect and process touches on the iPhone screen along the way.

Related Xcode project code
TouchTargets_ch9.zip

 

Chapter 10: Ready…

Well on our way to completing the project, we take a few moments to think through how our targets should behave. We also update our project to accurately reflect its OpenGL ES 2.0 only status.

Related Xcode project code
TouchTargets_ch10_comments.zip or TouchTargets_ch10_clean.zip

 

Chapter 11: Aim…

In chapter 11, we create both the target class and the target manager class. We also make our target manager a singleton class, and discuss exactly what that means on the iPhone.

 

Chapter 12: Fire!

Finally, we have something that’s starting to look like a game. By the end of this chapter, we have targets popping up on the screen and registering hits, complete with floating score text. We even take a few moments to talk through a few tricks for generating random numbers on the iPhone.

Related Xcode project code
TouchTargets_ch12.zip

 

Chapter 13: Who’s Keeping Score?

Now that we have a program that can register target hits and misses, it’s time to make a scoring mechanism. We also fix the annoying problem of new games being started too quickly.

Related Xcode project code
TouchTargets_ch13.zip

 

Chapter 14: A Little Background

It’s amazing what kind of difference a bright and cheerful background can make to an otherwise bland and simple game. Add a little scrolling action to the background, and we’re looking good.

 

Chapter 15: Finishing Touches

No one ever gets it completely right the first time through, but that’s good – that’s how we learn. In this chapter, we learn how to use Instruments to find and correct a few memory leaks and one interesting bug.

Related Xcode project code
TouchTargets_ch15.zip