Online Book Reader

Home Category

iPhone Game Development - Chris Craft [66]

By Root 1627 0
Image View to AmuckRacer


Next, you will assign the car.png to the second Image View. Click on the second smaller Image View that is located near the bottom of the screen in the center. From Xcode's Tools menu, choose Inspector. On the Image View Attributes toolbar tab, set the Image field to car.png. From the Inspector's Image View Size tab, resize the car's Image View to 48 pixels by 102 pixels. The W field is for width; set this to 48. The H field is for height; set this to 102. You'll probably have to reposition the car's Image View after making these changes. This time you can decide where to place the car; just be sure to have it on the road. If you run the code in Xcode now, you should see something like Figure 5.12.

FIGURE 5.11

Adding the car's Image View to AmuckRacer


Wiring up the user interface

You will now use Interface Builder to wire up the user interface. Drag the road image over a little to the left so you can see the Main View's gray background. Click the Main View's background. Then choose Tools⇒Inspector. On the last tab, named Main View Identity, locate the Class Outlets area. Click the small button with a plus sign on it to add two new class outlets; name the first car and the other road. Double-click under Type and to the right of the car class outlet and set the Type to UIImageView. Do the same for the road.

Right-click on the car image and drag the small circle to the right of the New Referencing Outlet label and release it above the Main View's gray background. You should see a list with the car and road class outlets you created previously; be sure to choose the car option. Now do the same for the road image, and assign it to the road option.

FIGURE 5.12

The AmuckRacer car on the road


You can now take advantage of Interface Builder's Write Class Files feature. To do this, first move the road image back to where it fills the entire screen. Make sure the Main View window now has the focus by clicking the title bar at the top of the window. Go to the Interface Builder's File menu and choose Write Class Files. You should see a dialog box with the text of MainView set for the Save As field. Click the Save button to have Xcode save its changes to the generated class files. You should see a dialog box that states that MainView.m and MainView.h already exist. You are asked whether you want to replace these files. Click Merge to combine the newly generated code for the car and road Image Views with the preexisting code for the Main View form. Click Save to save your changes and then click Close to exit Interface Builder.

Removing the Status Bar

You probably noticed that the iPhone Status Bar is still at the top of the screen. While this will not hurt the functionality of the application, many players find this unrelated user interface distracting. For a game to be truly immersive, players must be able to suspend their disbelief. Some will find this difficult if they are being reminded of remaining battery life, current time, and signal strength changes. By removing the iPhone Status Bar you can give the player a full-screen experience without any nongame distractions.

Tip

Remember, it's the attention to details that separates a good game from a great game!

To remove the Status Bar from the top of the screen, you need to add one line of code:

-(void)awakeFromNib {

[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];

}

This line of code needs to be added to the MainView.m file, which is located in Xcode's Groups & Files. Choose AmuckRacer⇒Main View⇒MainView.m. Once you have found the MainView.m file, you will need to add the code from the previous awakeFromNib function to it. Once you have finished, your MainView.h file should match Listing 5.1.

Cross-Reference

To download all of the code listings in this chapter, go to www.wileydevreference.com and click the Downloads link.

Listing 5.1

AmuckRacer MainView Listing

#import “MainView.h”

@implementation MainView

-(void)awakeFromNib {

[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];

Return Main Page Previous Page Next Page

®Online Book Reader