Building a Simple Game
1. Creating an Xcode Project
File → New Project
2. Creating the IVBricker User Interface
- Examining the Main Window File
For more information about the folder icons: check BIGD-2011-03-26 - Examining the View Controller File
For more information about the folder icons: check BIGD-2011-03-26 - Setting View Properties
Click the Hide or show the utilities icons, and choose the Attributes tab
- Adding Components to the View
Open a window called Library which displays the different types of components that can be laid out in a view in Interface Builder.
We will drag two labels to our view, to display the current score for our game in progress. Place it close to the top and right border. - With the new label selected, the property currently has a value of Label.
- The font Size property has a check box called Adjust to fit, deselect it to make the score display with a fixed font size.
- This will make the label truncate our five zeros, because it is not big enough to display the whole string.
- click ruler icon. This is the Size tab. (Don’t forget to select the center dot in the grid to the left if it’s not already selected, or the position of the label won’t be correct for these numbers.)
- To update the score label from our game code, we first need to add a property to the view controller. We will name this new property scoreLabel. After adding the property to the view controller, we will make a connection between the view controller’s scoreLabel property and the score label component in Interface Builder.
3. Adding Code to the View Controller
- The new code for IVBrickerViewController.h, which (1) declares the scoreLabel instance variable and (2) the property of the same name, as well as (3) an integer instance variable called score.

- The new code for IVBrickerViewController.m, (1) synthesizes the scoreLabel property and (2) releases it in the dealloc method.

- As you add @synthesize statements for your properties, you usually need to add matching release statements in the dealloc method.
4. Connecting a Property with a Component
- Right-click the File’s Owner. This will bring up a window that lists the File’s Owner Outlets and Referencing Outlets.
- Click and hold on the unfilled circle to the right of scoreLabel and drag to the Label component.
- Now that the connection is made, we can easily update the score label in our game with code like this in our view controller:
scoreLabel.text = [NSString stringWithFormat:@"%05d", score];