iPhone Game Development - Chris Craft [54]
FIGURE 4.15
The Bonfire application
Once again, open Xcode and create a new project using the iPhone OS Utility Application template. Name this new project Bonfire. Go ahead and create a Default.png now and add it to your Bonfire project. To do this, right-click on the Resources folder below the Bonfire project folder in the Groups & Files panel in Xcode. Choose Add⇒Existing Files. Find the Default.png file you created, select it, and then click the Add button.
This time we choose to let the Default.png file we created match the first frame of the Bonfire animation. This way the application appears to load faster (almost instantaneously) for the end user. You can see the Default.png file we used in Figure 4.16. You can either use the one we provided or create one of your own if you want something more like a splash screen to show.
FIGURE 4.16
The Bonfire application's Default.png
It is always best to add a Default.png early on in the iPhone application-making process, even if you only make a temporary Default.png image that has the text “Temporary Default.png” on it, because that way you are less likely to forget to create one in the end. Once you get more involved in the application-making business, it's easy to overlook little details such as including the Default.png image file.
When you created the iFlame application earlier in this chapter, you used the MPMoviePlayerController class to play videos, but we mentioned that you could create animations and play movies that way as long as you had an animation image sequence available of the movie. The Bonfire iPhone application takes this approach to movie playing so you can see how it's done.
The key to making Bonfire is creating the animation image sequence. There are many ways you can create an animation image sequence. One way is to use QuickTime Pro, as we mentioned earlier, to convert an existing video into a sequence of images. You could also take an animated GIF file that you have rights to use and use a program that can pull out each frame of the animation and save it as a separate image.
Of course, you can either have someone create the animation for you or create one of your own. You might think hand-drawn animation would not have the quality required for an iPhone application. But there are many iPhone applications coming out that focus on the fact that they are hand drawn and the characters are stick figures. It has become a genre and style all its own.
Once you have the image sequence you are going to use for Bonfire, you will need to add these images to the Bonfire project. We created an animation sequence consisting of 17 images that, when played in a loop, creates a great animation of a burning campfire. Feel free to use this animation sequence for your own Bonfire application.
You may want to create a new folder to keep all of these animation images in. To add a new folder in Xcode, right-click on the Bonfire project's Resource folder and choose Add⇒New Group. This creates a New Group folder, which you can promptly rename Images. Right-click on the Images folder and choose Add⇒Existing Files. Find your images, select them, and then click the Add button in the bottom-right side of the dialog box. Once you have added all of your images to your Bonfire project, Xcode should look something like Figure 4.17.
After you have prepared your Bonfire project with all the resources you need to create the Bonfire iPhone application, your main task is to add the code required to make the Bonfire animation play. Open the MainViewController.m file in Xcode, located under the Main View folder under the Bonfire project in the Groups & Files panel. Find the viewDidLoad method. The viewDidLoad method is implemented by all UIViewController objects, of which the MainViewController class you are in is one. This method is invoked or called when the view is finished loading.
Tip
Don't forget you can use transparency in your animations. You can use images that contain