iPhone Game Development - Chris Craft [38]
FIGURE 3.15
Choosing the level of difficulty from the polished menu screen
FIGURE 3.16
Choosing the level from the polished menu screen
We could leave it alone now because it looks good, but let's add just a bit more excitement. When a button in clicked, add a little animation to the process to make the click feel more interactive. Figure 3.17 shows the animation midway through its progress, but you really need to run the app to get the full effect.
FIGURE 3.17
Button animation still from the polished menu screen
For one final touch as part of polishing the menu, you can add a default.png image to your project. When you launch your app, the iPhone OS displays this image while the player is waiting for the app to load. Apple asks that you do not use this image as a splash screen. Apple prefers that you use an image that looks like the first page your player will see. The best way to do this is to take a screen shot of your root menu screen and save it in your project with the name default.png. If you have never taken a screen shot before, it's easy. Hold down the Home button and then click the on/off button located at the top of your device. You should see the screen flash, and then you will find the screen shot in the Camera Roll of the Photos app.
Once you have a screen shot you can add it to your app as a resource with the name Default.png.
Apple recommends that you use an image that looks like the first page users will see. However, this may make the app feel unresponsive to users during initial startup, because they will see a screen where they expect to be able to tap buttons yet they cannot because they are looking at an image instead of a UI. We have found placing the text “loading. . . ” in the center of the screen helps players understand what to expect.
Programming the Game View
Now that we have some content on the info screen, a way to persist and retrieve game data, and a menu, it's time to build the Game View. For simplicity we will place most of the game logic for AmuckSlider in the class MainViewController and a little view logic in the class TileView. In more complicated examples you will want to take time to break up your concerns into relevant classes.
Tip
Notice the pattern of having a View and a ViewController. As a general rule, try to place your game or business logic in the ViewController. Game logic would be collision detection, processing user input, calculating moves, and so on. Likewise, try to place all of your view logic in the View classes. View logic can include animations, setting backgrounds, colors, and things of this nature.
Go ahead and review the classes MainViewController and TileView from the unpolished version of the source code. (Again, this source can be found at http://appsamuckcom/amuckslider.) Now we will review all the key pieces of game and view logic found in these files. When you are done you will understand what makes AmuckSlider tick.
Reviewing the TileView class
The TileView class wraps up all the view logic necessary to give our tiles the desired appearance and behavior for our requirements. We decided that a tile could be blank or contain an arrow. When a TileView is created, an arrow UImageView is added as a subview:
UIImage *arrowImage = [UIImage imageNamed:@”arrowImage.png”];
UIImageView *imageView = [[UIImageView alloc] initWithImage:arrowImage];
// make the arrow image half the size of the TileView so that when it is
// rotated it will not wander outside the bounds of the tile.
imageView.frame = CGRectMake(aSize/4, aSize/4, aSize/2, aSize/2);
[imageView release];
[imageView setHidden:true];
[self addSubview:imageView];
self.arrowView = imageView;
[self updateArrowPoint];
This code can be found in the initialization method initWithIndex. The last line above calls out to updateArrowPoint. The method rotates the arrow image so that it points in the direction of its home location, or hides the arrow if the tile is in the home location. Also note that if the tile is not an arrow, this