RSS

BIGD-2011-04-10-Building a Simple Game-01

10 Apr

Building a Simple Game

1. Creating an Xcode Project

File → New Project

2. Creating the IVBricker User Interface

  1. Examining the Main Window File
    For more information about the folder icons: check BIGD-2011-03-26
  2. Examining the View Controller File
    For more information about the folder icons: check BIGD-2011-03-26
  3. Setting View Properties
    Click the Hide or show the utilities icons, and choose the Attributes tab
  4. 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.
  5. With the new label selected, the property currently has a value of Label.
  6. The font Size property has a check box called Adjust to fit, deselect it to make the score display with a fixed font size.
  7. This will make the label truncate our five zeros, because it is not big enough to display the whole string.
  8. 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.)
  9. 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

  1. 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.
  2. The new code for IVBrickerViewController.m, (1) synthesizes the scoreLabel property and (2) releases it in the dealloc method.
  3. 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

  1. Right-click the File’s Owner. This will bring up a window that lists the File’s Owner Outlets and Referencing Outlets.
  2. Click and hold on the unfilled circle to the right of scoreLabel and drag to the Label component.
  3. 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];

 

 

About Dong

I'm dong.
Leave a comment

Posted by on April 10, 2011 in 有文化

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.