There are no active ads.

Introduction to iOS Development: Programming Pong (Part 2)

How do you develop apps for iOS? It’s a common question that many computer enthusiasts ask, and one we here at TechnoBuffalo hope to answer with this series of posts.

Learning how to develop software can be one of the most intimidating prospects for the average computer user, and with the growing saturation of applications in mobile marketplaces, it is becoming increasingly difficult to get your work noticed. That’s what this series is for, helping you learn iOS development from a conceptual perspective. No prior knowledge of computer programming will be necessary. Over the coming weeks, we’ll examine the iPhone’s ability to deliver immersive, intuitive content, a unique opportunity for both developers and consumers.

Today, we’ll be continuing last week’s lesson, recreating the classic game of Pong. When we parted last, we were linking our resource images to the code that we inserted into the initialization file.

1.  The next part of the tutorial is going to be a bit tedious. To ensure that the program can actually keep track of scores, you’ll need to create image views for every number for both the computer and the player. Each image is 30 by 30. Be sure to turn off the opaque option. Connect all of the images to their corresponding owners by going to the connections pane and dragging from New Referencing Outlet to File’s Owner and selecting the corresponding variable.

2.  Next, you will need to align all of the images. You will have to stack them up on top of one another, another tedious task. This will mark the end of the work that we will have to do in Interface Builder. Back to coding!

3.  Now, we are going to move on to animating the paddle’s movement. Head on over to the implementation folder (PongViewController.m) and begin to type the code as it is written below. We’re going to be using the touchesBegan method, which essentially tells the application how to respond to touch interaction.

———————————————

———————————————

4.  Now, we must go through a bit of housekeeping. Remember when we used @property (nonatomic, retain) in the initialization file? Because we made the decision to retain those variables we have to synthesize them in the implementation file. This can be done by listing all of the variables using commas. To help you out, feel free to copy paste this text:

———————————————

@implementation PongViewController

@synthesize playerPaddle, computerPaddle, ball;

@synthesize playerScoreText0, playerScoreText1, playerScoreText2, playerScoreText3, playerScoreText4, playerScoreText5, playerScoreText6, playerScoreText7, playerScoreText8, playerScoreText9, playerScoreText10, playerScoreText11;

@synthesize computerScoreText0, computerScoreText1, computerScoreText2, computerScoreText3, computerScoreText4, computerScoreText5, computerScoreText6, computerScoreText7, computerScoreText8, computerScoreText9, computerScoreText10, computerScoreText11;

———————————————

That’s it for today. Next week, we’ll be jumping into game states, which will help us pause and start the game, and we’ll be introducing you to game logic.

Questions?

If you have any questions about the topics discussed in this lesson, feel free to voice them in the comments below. We will do our best to ensure that you have a relatively painless experience developing for iOS. Stay tuned for the next installment of this series, which is released weekly.

To read previous installments from this series, check the links below.