iPhone Game Programming Tutorial – Part 1

January 15th, 2009 Posted by: brandontreb - posted under:Tutorials

This is the first in a multipart series where I will be teaching you to create an iPhone game from the ground up.  As many of you know, OpenGL and Quartz have quite a steep learning curve.  This tutorial will simplify the development process and not use either one of those technologies.  For our graphics, we will simply use UIImageViews.  

In this tutorial series, I will teach you about every aspect of developing an iPhone game.  The game will include graphics, sounds, game mechanics, and even some simple computer AI. 

The game we will be creating is called iTennis.  It is essentially Pong with a tennis theme.  It will follow all of the same rules and mechanics of Pong.  I chose this as a first game tutorial as iTennis does not require any special animation.  If there is significant interest, I will move on to a more complex game in a later series. Here is a screenshot of the game we will be making:

 

screenshot_011

Let’s get started… Here are the images you will need for the project. (I know my Photoshop skillz are weak, so be easy on me).  Click the link below to download the zipped images.
   

 

iTennis_Images.zip

 

Open up XCode and create a View Based Application. Name this application iTennis.

 

screenshot_01
After you unzip all of the images, drag them into the project Resources folder.  After you have done this, the resources folder should look like this.
screenshot_02
Now we are ready to start coding.  We need to first establish our IBOutlet connections so that we can interact with our images in code.  We will also add some of the game variables that we will be using in this tutorial.  Open up iTennisViewController.h and add the following code:
screenshot_05
As you can see, we have quite a few IBOutlets.  This is because there are many objects we need to interact with.  For now, ignore the ballVelocity and gameState variables.  Now, we are ready to build our interface.  Double click on the file iTennishViewController.xib to open it up inside of Interface Builder.  Here is a video of me setting up the interface.

[qt:http://icodeblog.com/wp-content/uploads/2009/01/Game_1.mov 640 416]

Now that you have made the connections, close Interface Builder and return to XCode.  We need to set up some constants.  You can hardcode these values in somewhere, but making them constants makes them easier to change when you are tweaking the mechanics of your game. Open up iTennisViewController.m and add the following code.
screenshot_06
Let me explain the purpose of the constants.  The first 2 are game states.  We use these to determine what is to be shown on screen.  Is the game paused, is it running, is it at the title screen?  We will add more states later on in the game.  The next 2 variables are speeds for the ball to travel.  Since the game is 2D, the ball can have an X and Y speed to make up its velocity vector.  The next line synthesizes the variables we will use to create their getter and setter methods automatically.
Now let’s write the viewDidLoad method. Add the following code:
screenshot_07
First, we are setting our game state to a paused game state.  This is so the game doesn’t start right away when the view loads.  Next, we create a vector for the ball’s velocity.  Adjust the constants that we defined earlier for a faster or slower ball speed.  Finally, we create an NSTimer instance.  The first parameter is the timestep.  We have set the time step to 0.05 seconds.  Adjusting this will change the speed of the entire game. Next we set the target.  This is telling the timer where the callback is located.  The callback is the next parameter.  Basically, we are telling the timer to call self.gameLoop every 0.05 seconds.  We don’t need to worry about the userInfo param.  The last parameter just tells the timer to repeat.
Now that we have initialized our game, let’s create the game loop.  Add the following method:
screenshot_08
First, we are checking to see if the game is in a running state (we don’t want to move the ball in a paused state).  If the game is not running, we will show the tapToBegin label.  This is just the label defined earlier that tells the user to tap the screen to begin.
If the game is running, we start by moving the ball according to its velocity vector.  The next few lines do some bounds checking.  If the ball hits the side of the screen, we want to reverse its velocity so that it “bounces”.  Without this code, the ball would fly off the screen.
The last bit of code we will need to write is the touchesBegan method.  We will use this method to start the game when the game is in a paused state.  Add the following code:
screenshot_09
What this does is first checks to see if we are in a paused state.  If so, we hide the tapToBegin label and set the game in a running state.  This will get the game running.  Eventually, we will write the code to control the player paddle in this function.
Finally, being good iPhone developers, we need to clean up the resources that we allocated.  Add the following code to the dealloc method.
screenshot_10
That concludes part 1 of our game development tutorial series.  If you have any questions or comments, feel free to leave them in the comments section of this post.  You can download the source code here. Happy iCoding!
  • frosty

    Hey Brandon

    congrats on your new job :) .

    any approximate idea how many tutorials you will publish in this series and how long it will take. Just some approximate ideas so that we can buckle up for the ride.

    One small suggestion, maybe you can post some small assignment type questions so that we can do play around on our own too :) .

  • Mike

    Cant wait for you to finish the tutorials. Congrats by the way.

  • David

    This is exactly the kind of think I am looking for. I am totally new to Objective-C and the OSX and iPhone Frameworks. (only did windows development before)

    I think pong is an excellent “hello world” for writing games as it contains many basics. As you already pointed out however it doesn’t include any animation/sprite type examples. Any chance you could toss in a small animation example? Maybe have the raquets change color or something when they collide with the ball or something simple?

    I look forward to the rest of this series!

  • Ben

    Thanks for writing this, I look forward to reading more game tutorials.

  • Andre

    Hi Brandon!

    I’m also new to the Mac “world”, your tutorial came in the right moment.

    I’m having trouble though, when I run iTennis it crashes and generates a report to send to Apple. Can you help me find out what am I doing wrong? The build shows no errors nor warnings.

    Thanks and keep up the good work!

  • Andre

    Just to give you more information, look what I’ve found on the report it generates to Apple:

    *** Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘-[UIViewController _loadViewFromNibNamed:bundle:] loaded the “iTennisViewController” nib but the view outlet was not set.’

  • http://blog.wheelerstreet.com Paul Rangel

    Great tutorial as always. I’m looking forward to seeing more of the obscure aspects of game programming as well. Especially sound and Quartz programming on the IPhone. Thanks!

  • Chintan

    Hi Brandon,

    I have to develop an iPhone application at my company which would sync data to and from PC/Mac. Can you guide me as to how to start and proceed with this? Would appreciate a tutorial on this but since you seem to already have some tutorials of your own lined up, only an overview will do. Just tell me which classes/methods etc should i use. Thank you.

  • Tylor

    Yes! I have been searching the net for a single iPhone game tutorial! This is exactly what I need! Keep up the great work!

  • techy

    Cool! when will the next tutorial in the series come out?

  • i-n00b

    This is just what I was looking for! As a game developer trying to transfer my knowledge of simple game loops, this provided a really good foundation.

    Please, please, please give us more :D

  • Aaron

    Really great tutorial- looking forward to the next in the series.

  • Gp

    Please please please continue this wonderful tutorial! Thank you so much. I have learned a lot about Objective C by just doing this tutorial.

    g

  • brandon

    Great tutorial, but I also have the same problem where it crashes when I go to launch. Any one know why?

  • http://www.speer.me kuyote

    This was a great tutorial. I can’t wait for the next in the series. I will try to get the paddle working on my own until then.

  • Tylor

    Just F.Y.I, you can get a better screen capture of the iPhone simulator if you press Command+Shift+4 (you will get the cross hairs), then you press space bar to get a camera icon. Click on the iPhone simulator and you won’t have borders or background. It will even add a nice drop shadow!

  • narender

    Hi,
    It is really a nice one,
    great tutorial, cant wait for its part 2,
    when it will be here on icodeblog,
    thanks for all your efforts.

  • narender.mudgal

    hi Andre ,

    *** Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘-[UIViewController _loadViewFromNibNamed:bundle:] loaded the “iTennisViewController” nib but the view outlet was not set.’

    I think you have not set your iTennisViewControllers view to the delegate. please check wheather it is set or not. you just open iTennisViewController.xib file, click the file owner , open the inspector ( apple + shift + i) go to the second tab. there you will find connections. check if the connection is made or not. or somewhere you have missed something.

  • iphonenew09

    great tutorial but same like ball from standford, pls finish next part , thanks

  • naren

    hi brandon,
    I am waiting for the next part,
    please let me know how much more time will it take,
    truely i cant wait for that
    for a long time i m searching for a game tutorial,
    but i didnt get it, through this i will be able to learn a lot.
    please reply
    thanks a lot

  • Andre

    narender.mudgal, thanks a lot, that did the trick. Thanks!

    Looking forward for the next part of the tutorial!

  • DN

    Hi Brandon.

    I’d like to see declaration & usage of objects/methods/functions… reading and passing arguments from said classes.

    Most iPhone blog/books only discuss programming the interface and the books I have on cocoa are written for Mac. The code is not 100% compatible with iPhone.

    For example… I have HilleGass’ book on ‘cocoa for mac’ I can write classes and function and pass arguments that work excellent on the mac but comes up with tons of errors when you try it on the iPhone.

    It’s just that the syntax for the iPhone is a little different so basic examples that demonstrate how to do it would work fine.

    Thanks

  • http://www.freshapps.com Brandon

    @DN,

    I’m not sure I understand what you are asking. If you look at my site, all of the tutorials involve writing code for the iPhone…

  • Imran

    Hey, thanks for the tutorial. It’s a great start and put together nicely. I’m looking forward to seeing more.

  • ck

    hey,
    great tutorials! you’re blog has become my one-stop guide for the app i am working on! keep up the great work!

    btw, great wallpaper on the video ? can I download it somewhere ??
    ck

  • DN

    Brandon,

    I’m sorry you didn’t understand my first post. I was hoping you could do a primer on “How to create objects and methods – and implement them” tutorial.
    I just reviewed the Fruit App and it’s a great intro. The reason I’m asking is because you are great at explaining stuff so we can understand it.

    Thanks for the great tutorials!!!!

    Examples of the primer:

    How to create an object…
    How to pass a message to an object…
    Methods that return multiple values…
    Methods that return no value…
    Creating an instance…
    How to get an object’s data…
    Creating pointers to objects…

    It’s a kind of ‘how to do anything with objects’ thing.

    Thanks again.

  • Joe

    Thanks a lot Brandon! This is my second day of learning IPhone programming and I think your site is one of the easiest to follow.

    So, I know this is probably totally wrong and off, but for those who were wondering about how to simulate collision and move the paddle this is what I did:

    1) In the Interface Builder, make sure you select the paddle and then in the Image View Attributes window, check the “User Interaction Enabled” checkbox.

    2) I added this function to iTennisViewController.m:

    -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch = [[event allTouches] anyObject];
    CGPoint touchLocation = [touch locationInView:self.view];

    if([touch view] == raquet_yellow) {
    raquet_yellow.center = touchLocation;
    }

    }

    3) in the gameLoop function, I changed it to:

    -(void)gameLoop {
    if(gameState == kGameStateRunning) {
    ball.center = CGPointMake(ball.center.x + ballVelocity.x, ball.center.y + ballVelocity.y);

    if(ball.center.y > self.view.bounds.size.height || ball.center.y self.view.bounds.size.width || ball.center.x < 0) {
    ballVelocity.x = -ballVelocity.x;
    }

    CGRect raquet_rect = CGRectMake(raquet_yellow.center.x, raquet_yellow.center.y, 100, 20);
    if(CGRectContainsPoint(raquet_rect, ball.center)) {
    ballVelocity.y = -ballVelocity.y;
    ballVelocity.x = -ballVelocity.x;
    }

    } else {
    if(tapToBegin.hidden) {
    tapToBegin.hidden = NO;
    }
    }
    }

    Is there some sort of Javadoc format website for the classes in the IPhone? I use XCode and the “Jump To Definition” menu link, but I figure there must be a better way?

  • masterjcl

    Thanks for tut but the video doesnt work

  • http://freshapps.com Brandon

    @masterjcl

    Thats means you don’t have the latest version of quicktime. Download that and the video will work.

  • http://freshapps.com Brandon

    @ck

    Found it on google images… Not exactly sure where.

    @DN

    That’s a good idea… Apple has a pretty good doc on this, I think it’s called objective C primer.

    @ Joe

    There is, it’s actually built right in to XCode.

    Press Apple-option-shift-?

    This should bring up the doc. It’s not quite as good as Javadoc, but it’s still pretty helpful.

  • http://www.lotofwallpapers.com Chintan

    Hi, Brandon…

    i found the answer to what i asked…

    Such an application is not possible to develop. Since OS 2.1 update, applications are not allowed to read or write other applications data…

    Its not possible for any 2 applications on an iphone to communicate with each other in any way. Except for Apple’s own apps… :)

  • Tylor

    Hey, I just finished up the tutorial and when I Build and Go, I get the loading screen and then just a white background… No errors or warnings. Any ideas??

  • SquirrelKing

    Awesome tutorial!

    I can’t wait for the second part. Do you have any idea as to when you’ll post it?

    Thanks again for the tutorial!

  • rey

    I know this will sound like a stupid question, but if you get a phone call will this app close? or is there some code you need to implement some sort of “got a phone call” method?

  • Naren

    Yes offcourse application will quit, becuase in iphone only one application will run at one time, so if you get a phone call this application will quit untill we override applicationWillTerminate method, there we need to store our current face so that after phone call or sms ends application will run from the point where you got a call or sms. correct me if I am wrong.

    Thanks

  • narender

    Hi Joe,
    i tried with your code,
    in touch moved are you sure

    if([touch view] == raquet_yellow) {
    raquet_yellow.center = touchLocation;
    }

    is working , i tried and debugged this condition is not getting setisfied. if you want that whenever you touch the screen and move you finger then only yellow racquet will move then replace

    if([touch view ] == self.view) or if you want that when you touch then only raquet will move then try

    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{

    UITouch *touch = [touches anyObject];
    if(CGRectContainsPoint([racquet_yellow frame], [touch locationInView:self.view]))
    {
    [self moveSquare:racquet_yellow toPoint:[touch locationInView:self.view]];
    }

  • http://www.lotofwallpapers.com Chintan

    @Rey…

    Any app will automatically exit when you get a phone call. This is implemented by iphone OS by itself. So there is no way you can keep your application running if you get a call.

  • naren

    Ok so I implemented some thing to work, it is working ,but you try it and make some changes as per your comfort, make your own rules. I just try to implement working of yellow racquet, ball is coming touching to yellow racquet, and diverted towards the green racquet, did not code for green racquet. so lets start. first you need to declare one more variable in tennisviewcontroller.h

    IBOutlet UILabel *player_score;
    declare its property like
    @property(nonatomic) NSInteger pscore;

    synthesize it in .n file,
    synthesize pscore;

    now implement
    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{

    UITouch *touch = [touches anyObject];
    if(CGRectContainsPoint([racquet_yellow frame], [touch locationInView:self.view]))
    {
    [self moveRacquet:racquet_yellow toPoint:[touch locationInView:self.view]];
    }
    }

    and make some changes in gameloop method.
    I made it like

    -(void)gameLoop{
    if(gameState == kGameStateRunning)
    {
    ball.center = CGPointMake(ball.center.x + ballVelocity.x, ball.center.y + ballVelocity.y);
    if(ball.center.x > self.view.bounds.size.width || ball.center.x self.view.bounds.size.height || ball.center.y < 0 ){
    ballVelocity.y = -ballVelocity.y;
    }
    if(CGRectContainsPoint([racquet_yellow frame], ball.center) )
    {
    self.pscore += 10;
    player_score.text = [NSString stringWithFormat:@"%i",self.pscore + 10];
    // ballVelocity.x = -ballVelocity.x;
    ballVelocity.y = -ballVelocity.y;
    if(ball.center.x <= self.view.center.x)
    {

    ballVelocity.x = 3;
    }
    else
    {
    ballVelocity.x = -3;
    }

    }
    }else{
    if(tapToBegin.hidden){
    tapToBegin.hidden = NO;
    }
    }

    }

    and here is the moveRacquet method
    -(void)moveRacquet:(UIImageView *)view toPoint:(CGPoint)location{
    view.center = location ;
    }

    declare this method in .h file like

    -(void)moveRacquet:(UIImageView *)view toPoint:(CGPoint)location;

    now run the project move your racquet , still there is a lot to do. please comment and correct my work.

    Thanks

  • naren

    one thing i left
    in viewdidload

    self.pscore = 0; initialize the playerscore with zero i will continue with green_racquet functionality

  • naren

    I completed the functionality of computer’s racquet o.e green racquet. first make a variable like pscore. declare its property and synthesize it.
    open your iTennisViewController.xib file and move your green racquet to the left corner and ball from center to top left corner below your racquet . this will give you a feel that computer is serving you the ball to play make sure that ball and racquet are not overlapping,maintain some distance between them, now open iTennisViewController.m file, you already have synthesize the cscore, in view did load method
    write cscore = 0;

    now make changes in gameloop method. here is the code, compare it with previous.

    -(void)gameLoop{
    if(gameState == kGameStateRunning)
    {
    ball.center = CGPointMake(ball.center.x + ballVelocity.x, ball.center.y + ballVelocity.y);
    if(ball.center.x > self.view.bounds.size.width || ball.center.x self.view.bounds.size.height || ball.center.y < 0 ){
    ballVelocity.y = -ballVelocity.y;
    }
    if(ball.center.y <= self.view.center.y)
    {
    CGPoint ballx = CGPointMake(ball.center.x,racquet_green.center.y);
    [racquet_green setCenter:ballx];
    }
    if(CGRectContainsPoint([racquet_green frame], ball.center))
    {
    cscore += 10 ;
    computer_score.text = [NSString stringWithFormat:@"%i", self.cscore + 10];
    ballVelocity.y = -ballVelocity.y;
    if(ball.center.x <= self.view.center.x) {
    ballVelocity.x = random() % 9 ;
    }else{
    ballVelocity.x = -(random() % 9) ;
    }
    }
    if(CGRectContainsPoint([racquet_yellow frame], ball.center) )
    {
    self.pscore += 10;
    player_score.text = [NSString stringWithFormat:@"%i",self.pscore + 10];
    ballVelocity.y = -ballVelocity.y;
    if(ball.center.x <= self.view.center.x) {
    ballVelocity.x = random() % 9;
    }else{
    ballVelocity.x = -(random() % 9);
    }

    }
    }else{
    if(tapToBegin.hidden){
    tapToBegin.hidden = NO;
    }
    }

    }

    also increase the ball’s speed

    #define kBallSpeedX 10
    #define kBallSpeedY 25

    Thanks

  • Naren

    In my previous post where i posted the code for yellow_racquet
    i told you to declare the variable and i missed that to paste there, that variable is
    NSInteger *pscore;
    and other is NSInteger *cscore;
    initialize them in viewDidLoad as
    pscore = 0;
    cscore = 0;
    I am using these scores only that user can understand our ball is hitting to racquets. these are for temporary use. if you dont want to show you can leave this step.
    please update, if any other mistake or the code is throwing error anything please let me know.
    Thanks.

  • thomas

    When will part 2 be out? I really wana finish this.

  • rey

    @Chintan “So there is no way you can keep your application running if you get a call.”

    I don’t want to keep it running. In fact I just wanted to make sure it would not keep running. I don’t have an iphone but rather plan on getting a ipod touch to test with, so I won’t be able to test what happens if I get a call. So I just wanted to check.

  • http://www.lotofwallpapers.com Chintan

    @Rey..

    If you dont want to keep it running then you dont need to worry about it.. Like i said, iPhone takes care of that by itself.

  • Clad

    Im having a problem when I launch in iPhone Simulator when its LOADING it stops and says “The application iTennis quit unexpectedly and says Ignore , report, Relaunch.” So thats the deal I made sure the connections are made. There is a few that are not and I dont know if they nee to be they are ” view, tabBarItem,navigationalItem.”
    SO if they need to be please let me know as I am very new to programing and apps. I have very carefully checked and rechecked the code so I dont think it’s there, but I could very well be wrong. Thanks for your help.

  • Kevin

    Clad,

    Your problem is in the code somewhere. In order to help you you need to give more information. When you launch you application make sure your console is displayed, Run > Console or Shift Command R. This will give you debugging information about why you app is crashing on launch.

  • Robert

    thank you for this… i hope you continue. I am having a basic problem with IB. When I drag the second Image View onto the View Controller it replaces the ‘court’ image and does not go on top of it. I also have more icons in my MainWindow.xib folder.
    I have…
    file’s owner
    First Responder
    iTennis App Delegate
    iTennis View Controller
    Window
    these are more than what you have in your video. ANY help would be greatly appreciated. Is the view controller delegate supposed to be a delegate to the file’s owner? If so, i cannot set it that way. right now, view controller is delegate to app delegate and app delegate is delegate to file’s owner….
    help????

  • Robert

    ok… fixed that problem I think, by restarting IB through xcode….wierd. Now I get this in the console…
    *** Terminating app due to uncaught exception ‘NSUnknownKeyException’, reason: ‘[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key raquet_yellow.’
    Not sure what is wrong with raquet_yellow. I’ve checked the code and there are no build errors, and the connections seem ok.

  • mayhem_nz

    @Brandon:
    First of all love your tutorials and have be searching for a basic game tut for some time. Can’t wait for the next installment.
    I was just wondering if you could include some standard features that most games include like a splash screen and menu. I know iTennis doesn’t really need it but it would relate well to the many people who would use this series of tutorials in creating their games.

    Cheers
    mayhem_nz

  • Naren

    @Robert
    please check that you have defined properties properly, like for racquet_yellow
    IBOutlet UIImageView *racquet_yellow;
    then
    @property(nonatomic,retain)IBOutlet UIImageView *ra……;
    and in the .m file
    @synthesize racquet.
    check might be some spelling mistake, or pointer is not there or in .m property you have put pointer there. check for these issues.

  • Robert

    Thanks for the reply Naren.. I have checked all these things, and they are ok. In fact, it builds fine. the problem is in the launch. I am going to go through this entire blog from the beginning and then go back to this example. perhaps then I will have some insight.

  • CLAD

    is this done half way? It dont seem to be finished because mine crashes every time in the launch stage. I am 100% sure the code is perfect I’ve checked and rechecked this all seems fine but the launch crashes every time …

  • CLAD

    hmmm well I reworked the code and I got it going but I dont have any movement in the paddles and the ball is going everywhere . Thanks for your replies.

  • techy

    hey Naren…
    can you upload the project so we can download it with your changes?

  • Naren

    @techy

    one thing i wanted to tell you that in gameLoop there is some code that is missing . it is not my fault. i pasted the whole code but the page is not showing that part. if i will paste again there will be the same problem. this is not my page so i cant even upload. I have completed this game almost. but left some thing to make it final. and i dont even have any way to tell it to others. Brandon is also not replying.

  • techy

    ok thanks for replying =D

  • Jhsw77

    Is there a way to create the ball and paddles the old fashioned way with code and WITHOUT Interface Builder?

  • Mark

    You are the MAN! If only Apple had guys like you writing their tutorials for them…

  • josh

    THANKS!!! My final project for my undergrad is a iPhone game your tutorial saved me so much time and a lot of headache. You are very clear and your directions are great. If you haven’t written a book you should consider it.

  • Jo

    @Joe

    If I use your code, the ball does just collesise with the paddel at the right end and not with the hole paddel. Could you help me??

  • http://www.feroc.de Feroc

    Thanks a lot… hope you continue this soon. :)

  • Naren

    @Jo,

    Actually if you have just copy and pasted the code of game loop then this problem will happen , because he might have pasted the correct code but because of some reasons some thing is missing. like first condition where we are directing the ball from walls that whole if condition is wrong. i also tried to paste my code but i saw that two if conditions are merged together and one wrong condition is made and that was effecting our application. wait let me help you.
    in gameloop…
    maintain the code written by brandon…
    and then copy Joe’s part from
    CGRect raquet_rect = CGRectMake(raquet_yellow.center.x, raquet_yellow.center.y, 100, 20);

    the first two if conditions of brandon’s should not be changed.other than that see what joe has pasted .
    hope it will work.

  • http://www.bwsciencelabs.com Brennon

    Brilliant! However, when I ran it just to see what would happen I got 2 warnings and 24 build errors! :D

  • Bruce

    Thanx a Million, to Brandon, Naren and Joe. You guys have done a great job putting this together for us NOOBs. Much appreciated.

  • BdR

    Thanks for the great tutorial. :)

    At first, I also got this error when building and running
    *** Terminating app due to uncaught exception

    For me it was a spelling error in this part:
    [NSTimer scheduledTimerWithTimeInterval:0.05 .. etc.

    Seems to me that the compiler doesn’t really check this kind of messaging, which can easily cause errors.

    I have a question though about the touchesBegan method.. do you really have to type in that entire syntax? Are you supposed to know this as a programmer? I mean, shouldn’t xcode generate a stub for it somehow? Or maybe this is because I made the view to the file’s owner connection only AFTER I started writing code?

  • Ricky

    Hey,

    I’m adding the Reference Outlets to the racquets and ball. THe two racquets and the ball go fine, but when I go to drag the Reference Outlet line for the scores over to File’s Owner, all I see is “view” no player_score or computer_score. What did I miss?

    P.S.
    If I select a racquet and add a Reference point, I see player_score and computer score.

    What gives?

    Thanks

    Ricky

  • Kyle

    Brandon,

    Great site and awesome tutorial! I’m having only one issue – once the ball starts downward in motion it redirects before it goes all the way down to the bottom. I’ve tried a number of various things trying to pinpoint where the issue is… I’ve checked my code versus yours and it’s the same, I’m thinking it’s something I’m doing wrong with interface builder. Does anyone have any ideas?

    Thanks,
    Kyle

  • Kyle

    @Ricky

    Check to make sure you declared your two score labels as “IBOutlet UILabel” and not UIImageView like the ones before them

  • Ricky

    @Kyle,

    Well, I checked and it was ImageView, changed it to UILabel and it still doesn’t work. I guess I’m getting close. ANy more ideas? THanks

  • Ricky

    Did a relaunch, it asked me to save, and presto! Thanks Kyle and good luck with the ball bouncing too soon. Any idea when Part 2 will be up? Thanks

  • Kyle

    @Ricky

    Don’t forget to take care of them below for the @property portion

  • Kyle

    @Ricky

    Glad it worked – yeah I have no idea what’s wrong on my end

  • Ricky

    Thanks. Just redid the @property. Why do I need IBOutlet AND @property? Sorry, I know nothing about programming, really want to learn though. Thanks.

    Oh, BTW, have you finished your app up to actually playing it? Or are we still waiting on Part 2? I’m curious when it will be out.

  • Kyle

    urgh – had a width mixed with a height. It’s working now.

    Looking forward to part two!

  • Jo

    @Naren

    Sry I think I dont understand you right(I think ist my false), because it dosent work. I woukd be greate if you could have a look at my gameloop:
    -(void)gameLoop
    {
    if(gameState == kGameStateRunning) {

    ball.center = CGPointMake(ball.center.x + ballVelocity.x , ball.center.y + ballVelocity.y);

    if(ball.center.x > self.view.bounds.size.width || ball.center.x self.view.bounds.size.height || ball.center.y < 0) {
    ballVelocity.y = -ballVelocity.y;
    }
    CGRect raquet_rect = CGRectMake(racquet_yellow.center.x, racquet_yellow.center.y, 100, 20);
    if(CGRectContainsPoint(raquet_rect, ball.center)) {
    ballVelocity.y = -ballVelocity.y;
    ballVelocity.x = -ballVelocity.x;
    }
    } else {
    if(tapToBegin.hidden) {
    tapToBegin.hidden = NO;
    }
    }
    }

    thanks for your help anyway

  • Naren

    Hi all guys,
    Might you will find something helpful and new in this post.
    I wanted to share some things to you. I will try to make it clear to you.
    first problem is collision detection. how to check whether two images are colliding or not. there are two methods
    CGRectContainsRect and CGRectContainsPoint, but try to use this one CGRectInersectsRect([ball frame],[racquet_yellow frame] == 1). It will work exactly and properly.
    second thing is how to manage the ball diversion with the balls, you need not to put two if condition like that.
    do it like
    after first line of game loop
    put
    if(CGContainsRect ([self.view frame], [ball frame]))
    {
    // your all necessary code which should work when ball is inside the boundaries
    }
    else
    {
    //try putting the conditions here to divert the ball
    }

    third is how to divert the ball when collides with the racquet or other ball.

    you use cgintersectsrect function when ever it is true inside that.
    ballVelocity = CGPointMake(ball.center.x – racquet_yellow.center.x , ball.center.y – racquet_yellow.y);
    it will divert the ball automatically depending on where the ball strikes.
    hope it is clear to you. this is all the logic, use your skills to match it.
    Thanks

  • Naren

    ok ok .. I am writing the function here, you people take care of the caps or small , i m not copying and pasting I am directly writing here. so might be some spelling mistakes.

    -(void)gameloop
    {
    ball.center.x = CGPointMake(ball.center.x + ballVelocity.x , ball.center.y + ballVelocity.y)
    if(CGRectContainsRect([self.view frame],[ball frame]))
    {
    //ball collision to yellow racquet collision
    if(CGRectIntersectsRect([ball frame],[racquet_yellow frame])==1)
    {
    ballVelocity = CGPointMake(ball.center.x – racquet_yellow.center.x , ball.center.y – racquet_yellow.center.y);
    }
    // ball to racquet_green collision detection

    if(CGRectIntersectsRect([ball frame],[racquet_green frame])==1)
    {
    ballVelocity = CGPointMake(ball.center.x – racquet_green.center.x , ball.center.y – racquet_green.center.y);
    }

    // code to move the computer racquet automatically
    if(ball.center.x = 320 || ball.center.x – ballRadius = 460 || ball.center.y – ballRadius <= 0)
    {
    ballVelocity.y = -ballVelocity.y ;
    }
    }
    }

    i did not check with the gameState , you manage yourself , but this code should be inside where gameState == kGameStateRunning.
    hope you all got it. try to make it work.
    Thanks a lot.

  • Naren

    Hey not again a lot of code is missing, what is happening . i dont understand again i m trying… to paste

    this is the code followed by this line replace with this code…i dont want that you people try with the missing code and face problems .. sorry for increasing the page length Brandon…

    // code to move the computer racquet automatically
    if(ball.center.x = 320 || ball.center.x – ballRadius = 460 || ball.center.y – ballRadius <= 0)
    {
    ballVelocity.y = -ballVelocity.y ;
    }
    }
    }

  • Naren

    this time also missing…
    hufff … ok i will paste one by one…

    // code to move the computer racquet automatically

    if(ball.center.x <= self.bound.size.height / 2)
    {
    //racquet_green’s x only will change not y, y will be the same

    racquet_green.center = CGPointMake(ball.center.x , racquet.center.y);
    }
    }

  • Naren

    oh ok now it is here , code continues…..
    else
    {
    if(ball.center.x + ballRadius >= 320 || ball.center.x – ballRadius < 0)
    {
    ballVelocity.x = -ballVelocity.x;
    }
    continues…

  • Naren

    and it ends with it

    if( ball.center.y + ballRadius >= 460 || ball.center.y – ballRadius <= 0)
    {
    ballVelocity.y = -ballVelocity.y ;
    }
    }
    }
    this all code is under gameState = running condition.
    again Brandon sorry for the long post and using your page.

  • Naren

    I have used one variable ballRadius either use statically 8 for statically, or use

    NSInteger ballRadius = ball.bounds.size.width/2;
    it will give you the ball’s radius.

  • Naren

    ooops,
    my posts are deleted .
    ok great. I will not post more stuff now onwards.
    Thanks a lot.

  • Ricky

    Hey,

    This as been out for a month! When is Part 2 coming out? Thanks Brandon! Great Tutorial thus far

    -Ricky

  • miah

    Hello everyone. I am completely new to xcode and am in need of some help. I keep getting the following errors in:
    iTennisViewController.m
    iTennisAppDelegate.m

    error:property ‘gameState’ with ‘retain’ attribute must be of object type.

    error:property ‘ballVelocity’ with ‘retain’ attribute must be of object type.

    What did I do wrong? I’m not even going to attempt a rational thought here because it will only show my complete noob-ness. Thanks!

  • miah

    nevermind. i just figured it out. i was using a ‘retain’ in the @property

  • miah

    ok, the app starts but crashes due to an error with the NSTimer. It doesn’t detect any errors initially only when simulation starts.

    Help would be appreciated.

  • http://www.codecurry.com Sameer Gupta

    Hi,

    I am new ti iPhone. Working on a small game. I can compile the file the project that you explain but I get an error.

    I need help to make this project run.

    The error occured in line 14 of main.m: int retVal = UIApplicationMain(argc, argv, nil, nil);

    I am able to run your sample, but I need to know what is the above error for my own understanding.

    Thanks for help.

    Best
    Sam

  • chris

    Great tutorial! REALLY looking forward to the next one. Thanks

  • http://www.haungo.com Hau

    Thanks for the great tutorial! I can’t wait to try it out. Looking forward to the rest of your series!

  • http://lhunath.lyndir.com Maarten Billemont

    Hey!

    I’m really glad some decent guides are finally popping up lately! I remember when I was trying to get my first game started, no Objective C knowledge, never developed on a Mac before, and with great ambitions; I found myself perplexed with the lack of decent information out there. This was when Apple still had the NDA up.

    So, I decided that when my game finished, I’d make it open source, such that *everyone* would benefit from it.

    Gorillas () is now in the App Store, and a second update is coming out soon. And all the while, the entire development process and source code can be found and followed at:

    So, I invite everyone to check it out if they’re wondering how a fully featured OpenGL/ES game looks like in source. Any questions about it you can always direct my way (contact info on the website).

    Hoping to serve the community,
    Lhunath

  • mingxin

    Can someone please send me the movie file or post it on a file host? The country I am in blocks this website and while I can access it through a proxy server, I can’t access the video :(

    Here’s the direct link to the video: http://icodeblog.com/wp-content/uploads/2009/01/Game_1.mov

    Thank you!

  • http://bob3@hotmail.com bob

    thanks for explaining in such an easy detailed manner that a beginner like myself can understand – you give great examples and i look forward to more!! thank you.

  • http://www.haungo.com Hau

    Hi Gang,

    I am a complete n00b, so please go easy on me.

    I followed the instructions listed above and copied the code (as best as I can) into my project. However, I run into errors when I click on the “Build and Go” button.

    Can I ask one of the experts here for their help? I’m certain that I’m missing something fairly basic, but I am very new to the iphone SDK.

    I have posted screenshots of the error on my page:

    Thanks in advance!

    Hau

    P.S. Brandon, what program did you use to record your tutorial? I would like to create a few tutorials for my area of work as well. Thanks!

  • http://www.haungo.com Hau

    Hi Lhunath,

    Congratulations on creating the game!

    Also, thanks for releasing the source code. I’m sure a lot of the beginners like myself will learn from your example.

    Thanks!

    Hau

  • Mat

    Great guide! When will part 2 & 3 be out?

  • Owen

    Hey, I’m having what is probably a very simple problem…when I select new referencing outlet for any of the paddle images, and drag it to file’s owner, the menu of image names that opens in the video opens, but instead of a list of names, it just says ‘view’. I’ve checked the code and it seems to be in order, but seeing as this is my first time with xcode, I’m most likely missing something obvious.
    This might not be related, but when I was entering the IBOutlets, the code was not turning blue, as it was in the picture above…

    any help would be appreciated! thanks..

  • Steve

    This is brilliant. Exactly what a lot of aspiring Mac developers are looking for. Thank you for providing this for us!

  • Frank

    I was able to make the app show up after following the tutorial but only saw the background image (the tennis court), all other added views were missing. I guess I missed something but couldn’t find out where. Any advice would be highly appreciated.

    Thanks in advance

  • Ravi , japan

    best tutorial i have ever found on internet !!
    Thanks a lot !! really supperb for starter…..
    with a very simple and much easier language….
    please teach us more complex game…

    Thanks a lot again..

  • Doug

    I’m afraid I’m having the same problem as Frank- the tutorial video never mentions connecting the background (court) view to anything, but if I don’t I get a crash error telling me the view outlet was not set. However, if I hook it to the “view” connector, the background court image is the only thing I can see. Any guidance would be appreciated!
    Thank you.

  • Amit

    Hey! Thanks for this site, you are the greatest! I am learning loads from your tutorials!

    I have a few questions about C Objective and Xcode

    What is the differennce between .h and .m???

    iTennisViewController.h

    and

    iTennisViewController.m

    and @property(nonatomic,retain)

    what does nonatomic,copy and retain do?

    How do I know which one to use?

    @property(nonatomic,retain)

    or

    @property(nonatomic)

    or

    @property(nonatomic,copy)

    Many Thanks!

    Amit

  • http://mdreeling.wordpress.com/2009/03/11/iphone-dev-gamesapps-top-bookmarks/ iPhone Dev – Games/Apps – Top Bookmarks « Java Developer / Fledgling iPod Touch Developer

    [...] iPhone Game Programming Tutorial – Part 1 | iCodeBlog [...]

  • Nick

    I’m having the same issue Owen is having. I’ve tried both typing in the code and copying and pasting from the example and neither seems to be working. Is it an issue with dragging over the images to the resources file?

  • http://afruj.wordpress.com/2009/03/24/iphone-tutorials/ iPhone development Tutorials « The Brook Song – ঝর্ণার গান

    [...] 33. iPhone game programming [...]

  • http://werchris.com Chris Anderson

    You are a God-send! I have purchased several books trying to learn this stuff, but none of them have made sense. Your tutorial is so well laid out and things are incredibly easy to follow! Thank you so much!

  • http://www.servingmed.com/CV/Roland Roland Combes

    For those still getting the splash screen flashing briefly and then displaying white before fading to the court image 2 seconds later, check that you are not using Default.png instead of Splash.png. It took me awhile to figure it out since I had skipped the step of downloading the Splash.png image having already seen it in the Default.png image.

  • http://www.iphonefootprint.com/2009/04/iphone-game-development-guide-on-the-go-tutorial/ iPhone game development guide: On the go tutorial | iPhone Footprint

    [...] tutorial has three parts, the first part deals with the creation of different folders within the main project folder.  The second part [...]

  • iNewbie

    Hi guys,

    I am so glad to see such a great example of a basic iPhone game. I followed the tutorial carefully, but what I got is a working splash screen followed by a empty court that doesn’t respond to clicks in the simulator. I had a friend tried my code but ended up with exactly the same thing.

    What I have missed?

    Thanks!

  • iNewbie

    Anyone can help? The only things stood out to me was the info said the different UIImage (like the paddles and the ball as well as the view (court)) are being clipped.

  • Francisco

    I cannot connect the images to the file owner, seems that the only available option is VIEW. A couple of people is having the same problem but I see no anwser in the posts. what are we doing wrong?

  • iNewBie

    I got it. It’s because I didn’t connect something, something the tutor didn’t talk about explicitly…

  • The Kellen

    For those that cannot connect the image to the file owner -

    Before you can connect then, you have to build the project. Do this in XCode by clicking on build in the top menu bar. Choose to save, and then you can connect the image.

  • Francisco

    Great! thats works perfectly.

  • alex

    hi, at the start of the coding, where we have to put in
    iboutlet uiimage view *ball;

    the colour of the word ball stays black, it doesnt go the light green colour. whats the problem?

  • Francisco

    I dont know were to post this; I want to writte an small program that allows me to pass attendace. I have no idea where to start, seems pretty easy in my mind but I need some pointers of what I will need.

  • Lee

    Hello,

    Here is a very odd thing.

    In the code for ‘viewDidLoad’, I have the following:

    [super viewDidLoad];
    self.gameState = kGameStatePaused;
    ballVelocity = CGPointMake(kBallSpeedX,kBallSpeedY);

    WHen I compile, this last line is throwing the following(vague) error:

    error:syntax error before ‘;’ token.

    I downloaded and ran your source codes with no problems. I even copy and pasted the code from yours to mine, but it caused the same error.

    take care,
    lee

  • Jonathan

    Hey Brandon,

    I’m having the same problem as Alex up there ^^^. When I enter in the required code, the “*ball” part stays black, and so do the rest of the similar parts of code. Why does that happen? This is my first time using Xcode, so i might be making a dumb mistake, but can someone just correct me then?

    - Jonathan

  • Mario

    I just wanted to reiterate how much I appreciate this tutorial. I am starting out programming for the iPhone and this is so much more fun than most dinky starting tutorials!!!

    Thanks!!! You Rock!!!

  • Wolter

    Cool tutorial, but when I try to do what you are doing in the video, it doesn’t work the same way.

    I can drag the Image View onto the iTennis View Controller, and then set the background image no problem.
    If I try to drag over another Image View (for the paddle), it doesn’t show a small outline like in the video; rather it is a big outline the same size as the iphone display. If I drop it in, it replaces the background image, and if I try to resize it, it stays stuck in the middle of the screen (I can’t move it around, and the background behind it is striped gray-white).

  • rich

    I have a question about the dealloc method, I thought I read it in some book that since the UIImageViews and UILables were created by the nib, the releases are taken care by the nib, is it wrong?

    Thanks.

  • mkppk

    @Lee
    About your vauge error “error:syntax error before ‘;’ token.”… I bet you have semi colons on your #define lines – you shouldn’t.

    Bad:
    #define someVar 3;

    Good:
    #define somVar 3

  • Jonathan

    Thank you for this wonderful tutorial. I’m knew to iPhone / Mac development and this answered most of my basic questions. This is definately the most complete tutorial I’ve seen on game development for the iPhone and you’ve saved me hours (perhaps even days) of thrashing. Thank you so much and please know that I am definately interested in reading / watching more tutorials by you on iPhone development. I would certainly be interested in reading / watching an OpenGL and Quartz tutorial.

  • Dcybele

    WONDERFUL Tutorial, thanks so much Brandon!

    Just a minor note, there’s a typo in:Double click on the file iTennishViewController.xib to open it up inside of Interface Builder.
    This is just before your video.

    I believe it should be iTennisViewController.xib (no h) ;)

    Again, though, thanks SO MUCH! Great work!

  • http://www.idevgames.com Carlos

    Great series. I’ll add a snippet about it to our news.

  • http://joehenry.name Henry

    Awesome tutorial set! Thank you so much!

    Just one question real quick:

    I was just wondering why you didn’t add the gameState and ballVelocity variables to the dealloc method?

    I’m very new the objective-c programing so I apologize for misused terms and such.

    Thanks again!

  • Joe

    You’re awesome, dude! Great tutorial and thanks a bunch!

  • Al

    This tutorial is amazing! Thanks for posting it!

    Unfortunately, I have a bit of a N00b question: only the court will show up when I try to build and run the program, even when I have all the other UIImageviews on screen and defined. I have checked and rechecked all of the connections for the UIImageViews in both the code and IB, as well as looked over your source code multiple times. I have seen absolutely nothing different between the two, but there is clearly something wrong with mine. Does anyone have any idea of what is going on?

    Thanks in Advance.

  • Al

    Fixed it! Never mind! Excellent tutorial! Can’t wait to try the others!

  • Al

    Fixed it, so never mind! Excellent tutorial, Brandon! Can’t wait to try the others!

  • http://greatstuff Anthony

    wow, helped me allot. im looking forward to reading more of these tutorials. keep up the great work man! =)

  • Graham

    This is exactly what I was looking for, thanks a lot!

  • iBots

    Hmm… I’ve looked over the tutorial and all the replies here but I can’t find the solution to my problem.

    I click on ‘Build and Go’ and I see the iTennis loading screen but then the app crashes with:

    *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’

    …In my code I see a yellow warning at the bottom of my viewDidLoad method, right under the NSTimer: “NSTimer may not respond to ‘+scheduledTimerWithTimeInterval:target:selector:userInfo:repeat:”

    Help?

  • http://iphoner.org.ua/blogs/akrakovetsky/archive/2009/07/05/100-iphone.aspx 100 ресурсов для iPhone-разработчиков – Краковецкий Александр: заметки программиста – iPhone Community в Украине

    [...] iPhone Game Programming Tutorial: This multipart tutorial offers a way to learn OpenGL and Quartz for iPhone development. [iCode] [...]

  • http://KRAPPS.com/2009/07/09/itennis-iphone-app/ Developer Steals iPhone App Code, Submits As Own | KRAPPS | a different and funny iPhone app review site

    [...] of Brandon’s most popular articles is the “iPhone Game Programming Tutorial” in which he gives step-by-step instructions on how to build an iPhone game called iTennis (a [...]

  • http://www.applebloog.com/?p=18760 Apple Bloog » Blog Archive » Lifted tutorial code winds up in $0.99 App Store tennis game

    [...] ripoff of code provided by the iCodeBlog, a site known for its free iPhone coding tutorials. The original tutorial, written by Brandon Trebitowski, was apparently compiled and submitted by Peter Sheen of [...]

  • http://www.iphonefirmware.com/2009/07/09/lifted-tutorial-code-winds-up-in-099-app-store-tennis-game/ Lifted tutorial code winds up in $0.99 App Store tennis game | iPhone Firmware

    [...] ripoff of code provided by the iCodeBlog, a site known for its free iPhone coding tutorials. The original tutorial, written by Brandon Trebitowski, was apparently compiled and submitted by Peter Sheen of [...]

  • http://infofork.com/lifted-tutorial-code-winds-up-in-0-99-app-store-tennis-game/ Lifted tutorial code winds up in $0.99 App Store tennis game | InfoFork.com

    [...] ripoff of code provided by the iCodeBlog, a site known for its free iPhone coding tutorials. The original tutorial, written by Brandon Trebitowski, was apparently compiled and submitted by Peter Sheen of [...]

  • http://news.appleusers.org/tuaw/lifted-tutorial-code-winds-up-in-0-99-app-store-tennis-game/ AppleUsers.org News » Lifted tutorial code winds up in $0.99 App Store tennis game

    [...] ripoff of code provided by the iCodeBlog, a site known for its free iPhone coding tutorials. The original tutorial, written by Brandon Trebitowski, was apparently compiled and submitted by Peter Sheen of [...]

  • http://iwyre.net/?p=1558 iWyre

    [...] ripoff of code provided by the iCodeBlog, a site known for its free iPhone coding tutorials. The original tutorial, written by Brandon Trebitowski, was apparently compiled and submitted by Peter Sheen of [...]

  • http://appleusersblog.com/lifted-tutorial-code-winds-up-in-099-app-store-tennis-game/ Apple User’s Blog » Lifted tutorial code winds up in $0.99 App Store tennis game

    [...] ripoff of code provided by the iCodeBlog, a site known for its free iPhone coding tutorials. The original tutorial, written by Brandon Trebitowski, was apparently compiled and submitted by Peter Sheen of [...]

  • http://shaiperednik.com/2009/07/lifted-tutorial-code-winds-up-in-0-99-app-store-tennis-game/ Lifted tutorial code winds up in $0.99 App Store tennis game » Shai Perednik.com

    [...] ripoff of code provided by the iCodeBlog, a site known for its free iPhone coding tutorials. The original tutorial, written by Brandon Trebitowski, was apparently compiled and submitted by Peter Sheen of [...]

  • http://iphonepulse.com/2009/07/free-tutorial-code-sold-as-99c-app-on-the-appstore/ Free Tutorial code sold as 99c App on the AppStore » iPhonePulse

    [...] Yeah, that’s right: stolen code. The code came from a tutorial site called iCodeBlog, and the tutorial containing this code was written by Brandon Trebitowski. A company on the App Store called [...]

  • PLi

    Can anybody explain what the fault is when you only see the backgrodun image (the court) and not all other objects? I overlooked it now several times but for some reason I don’t get it ;-)

    Thanks,
    PLI

  • PLi

    Can anybody explain what the fault is when you only see the background image (the court) and not all other objects? I overlooked it now several times but for some reason I don’t get it ;-)

    Thanks,
    PLI

  • vconrad

    Great tutorial, thanks. I’m having the same problem as Taylor though. The splashscreen fades away to a blank white screen and nothing happens. Since I get no errors or warning from the build Im a little stumped. Did anyone manage to fix this?

  • vconrad

    Doh – fixed my white screen problem.

    If anyone else has this problem like Taylor and I, check that you put:

    viewController.view.alpha = 1.0;

    inside the finishedFading method.

  • http://lesma.net/iphone/?p=1429 Lifted tutorial code winds up in $0.99 App Store tennis game

    [...] ripoff of code provided by the iCodeBlog, a site known for its free iPhone coding tutorials. The original tutorial, written by Brandon Trebitowski, was apparently compiled and submitted by Peter Sheen of [...]

  • Sam

    For making the size of the UIImageView small enough to have the ball hitting the correct place you can go Layout->Size To Fit while it’s selected.

  • http://www.bubidevs.net/2009/03/11/devtutorial-13-creiamo-il-nostro-primo-gioco-pong-parte-i/ DevTutorial #13 – Creiamo il nostro primo gioco, Pong! (Parte I) – Bubi Devs

    [...] Devs”. La versione originale inglese del tutorial è disponibile a questo indirizzo: “iPhone Game Programming Tutorial, Part 1 – iCodBlog“. I meriti quindi relativamente alla versione inglese, sono del legittimo [...]

  • Vince

    For those with the problem of dragging the uiimageView onto the layout and then not being able to drag any more uiimageviews onto the layout, make sure you’re using the right .xib file. Don’t use mainwindow.xib. Use the itennisViewController.xib.

  • Vince

    If you have problems getting your reference outlets to work, MAKE SURE that you followed his code to the LETTER in your .h file. The IBOutlets I had defined in mine were the wrong type. I had created pointers to “UIImage”s instead of pointers to “UIImageView”s. Once I did that I could properly drag my connections over to the file’s owner box and see the iboutlets I needed to. Download his source and copy his .h if you still have problems. Run a file comparison to yours if you have to. His tutorial works.

  • Vince

    Oh yeah. And the crashing issue. Mine crashed at first, but then I realized I messed up the original reference outlet of the view connecting to the view.

    Download his source and look at his xib in interface builder to see what I mean. I started with his screencast tutorials. I took those for granted. They really do make it easier to make sure you follow along correctly. Perhaps seeing him type in every letter reinforces to you, the subtle differences in the code lines.

  • http://developer.thomasnicholson.com/2009/08/18/quick-post-iphone-game-development-tutorials/ Quick Post: iPhone Game Development Tutorials | Thomas Nicholson iPhone Developer Newbie

    [...] iPhone Game Programming Tutorial – Part 1 [...]

  • ThinkMud

    This is great man, thanks for the tuts and info. I’m a long time windows .net developer, but total n00b to macs and iphones, and i’ve learned tons already by walking through your tutorials.

    I’d suggest anyone that really wants to learn should go through these and manually create everything, and not just download the source. I seem to learn much faster by typing the code.

  • Gary

    Great Job….

    It’s been very detailed, can’t wait to have my Mac to follow to follow your instruction…

  • Lane

    Ummmmmmmmmmm can i do this on a windows vista??

  • http://triffort.com afzal

    will u give full game

  • http://triffort.com afzal

    good works ben, i like it

  • http://www.shuguo.org/2009/09/02/iphone-ipod-touch%e6%b8%b8%e6%88%8f%e5%bc%80%e5%8f%91/ iPhone/iPod touch游戏开发 | SHUGUO

    [...] iTennis这个教程还不错,虽然没用上什么华丽复杂的功能,但是一步一步跟着做下去,对于怎么做出一个iPhone游戏还是很有帮助的。这也是我除了Hello World之外第一个自己尝试的iPhone App了。虽然Object-C的挺多语句还不很习惯,也有一些不理解的地方,但确实感受到了,开发iPhone的项目门槛并不高。这也给自己树立了信心,有机会好好学习和开发iPhone软件。如果有时间,我也自己写一个关于自己开发软件的教程。 [...]

  • http://eiphonestudy.com/2009-09/look-familiar.html Look Familiar? | Iphone Study Blog

    [...] might recognize this “game” from a tutorial that I wrote about writing an iPhone game (link).  One thing to note here is the company name is BlaBlaIncTech (not iCodeBlog) meaning I did not [...]

  • http://grannycoder.blogspot.com Granny Coder

    Hello dear, thank you for useful article. It cleared me a lot of things. Love, Granny.

  • Amy

    Hi Brandon,
    Thanks for the great tutorial. I have a quick question:
    how to add speed to this game? Your answer will be
    highly apprecited. Thanks.

    Amy

  • Amy

    Hi Brandon,
    Thanks for the great tutorial. I have a quick question:
    how to add speed to this game? It will be very helpful.
    Thank you.

    Amy

  • http://www.uright.ca/?p=115 iPhone Game Programming Tutorial Suggested Link « Uright Tech Blog

    [...] Part one explains basic use of xCode and Interface Builder. He also demonstrated some basic game design framework. Part two talks about user interactions. Part three discusses about putting a Splash screen to an applicaiton. [...]

  • http://ueepa.wordpress.com unt

    Great, totally awesome tutorial! Please, please continue to make more :)

  • http://www.property-search-cannes.com Annie ( Period Property ) Wagner

    Excellent blog this icodeblog.com well done and I was really pleased to find : this it’s just what I needed to know.
    It’s taken me literally 3 hours and 48 minutes of searching the web to find icodeblog.com (lol) ;)
    But seriously I am really interested in Bulgaria Property normally and so I shall be very pleased to become a regular visitor

    Thanks

  • http://www.myfirstiphoneapplication.com/2009/10/some-great-resources/ Some Great Resources! | My First iPhone Application

    [...] iPhone Game Programming Tutorial: This multipart tutorial offers a way to learn OpenGL and Quartz for iPhone development. [iCode] [...]

  • jonk

    hey brandon,

    im new to this, xcode and interface builder,
    and im already stuck on the connections part, where u explained in ur video, when i try making a new referencing outlet for my two rackets, it only shows ‘view’, instead of all the .png files, any help?

  • Ami Schreiber

    Disregard my last post. I figured it out.

    Nice job!

  • ash

    im having trouble with the labels connection, when i drag down toward the file owner it only come up with View, and that it there is no player score or computers score, i dont know why this has happened, it works with the images but it wont work with the labels and even the texts

    please get back to me a soon as possible

  • Remi

    Thanks very helpful !

  • Tommy Myers

    Hi,

    how can i modify the app to play against your friends through bluetooth?

    Tommy

  • http://cs-me.com/2009/11/21/the-ultimate-toolbox-for-iphone-development/ The Ultimate Toolbox for iPhone Development – Creative Solutions

    [...] iPhone Game Programming Tutorial: Part 1 Here’s a complete tutorial for creating a Pong-like iPhone game. [...]

  • Aussie96

    Hey guys,

    Im having trouble Connecting “New Referencing Outlet” and “File’s Owner”, which is displayed in the video. This is needed to connect the racquets, scores and ball. Obviously this is one of the most vital parts in this application, though I cant do it.

    All help will be greatly appreciated!

  • http://mundoimd.com/2009/11/30/enlaces-para-desarrollar-en-el-iphone/ Enlaces para desarrollar en el iPhone | El mundo de IMD

    [...] iPhone Game Programming Tutorial: Part 1 Here’s a complete tutorial for creating a Pong-like iPhone game. [...]

  • Simon88

    In answer to a lot of the problems with

    *** Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘-[UIViewController _loadViewFromNibNamed:bundle:] loaded the “iTennisViewController” nib but the view outlet was not set.’

    The chances are you followed the tutorial but havn’t set the view connection itself.
    If you look through your connections, all your major objects should be connected, but i found with mine that I was missing the “view” connection at the bottom. You want to drag this one to the “view” box in your iTennisViewController.xib window.

    Once this is connected, save, and rebuild and run your project!

  • Nick

    Hey Brandon,

    You da’ man!.. Amazing walk-through Xcode.. As a first time app developer I was pretty intimidated..(still kind of am actually), but this tutorial definitely opened my eyes… Props! and I could help notice the inconsiderate moron that tried to sell your exact game to apple..lol.. hope you have him on his knees begging for mercy.

    N.

  • http://learningtechie.wordpress.com/2010/01/21/my-first-iphone-game/ My first iphone game! « Learning techie

    [...] I named this application “Galactic Pong” but in essence it is just a edited version of “iTennis” but the author of that tutorial. You can access that tutorial here. [...]

  • http://www.casdra.com/blog/?p=1641 CasdraBlog » Blog Archive » links for 2010-01-29

    [...] iPhone Game Programming Tutorial – Part 1 | iCodeBlog (tags: iphone programming) [...]

  • http://sickmacaddict.wordpress.com/2010/01/29/iphone-game-programming-tutorial-part-1/ iPhone Game Programming Tutorial – Part 1 « Evolving Minds

    [...] up XCode and create a View Based Application. Name this application iTennis. After you unzip all of the images, drag them into the project [...]

  • Andy

    Great writeup!

    Question, I’m trying to change the game from portrait to landscape, I’ve already rotated my images and switched interface builder to landscape, but what do I need to alter in the code? P.S. when I simulate it, it is in portrait with the court squeezed into landscape. Thanks!

  • http://fansibo.com/?p=240 The Ultimate Toolbox for iPhone Development | c'est la vie

    [...] iPhone Game Programming Tutorial: Part 1 Here’s a complete tutorial for creating a Pong-like iPhone game. [...]

  • http://fansibo.com/?p=240 The Ultimate Toolbox for iPhone Development | c'est la vie

    [...] iPhone Game Programming Tutorial: Part 1 Here’s a complete tutorial for creating a Pong-like iPhone game. [...]

  • Chimpy

    Hi Brandon,

    how would you limit the width that the paddles could move ?
    so the ball could squeeze between the paddle and the side of the screen ?

    thanks

    Chimpy

  • http://N/A Mike

    Greta site man! Keep the tutorials coming!

  • http://daveelliottonline.com dave

    Hello,
    I am new to xcode and c programming and iphone programming. I have sucessfully “built” this tutorial but it says that it “failed to launch simulated application: iPhone Simulator failed to install the application.” I have it set to iPhone Simulator 3.1 and have tried 3.0 as well.

  • Chris

    @Brandon quicktime movie wont play to show the setting up of the UI!

  • Salim

    Hii,
    Can u please send me the whole code on my E-mail address that i can study n learn more thing.

  • Salim

    Hi Narender,

    I will Try to do this And its working. can you please send me the racquet_yellow code….
    on my email add please.

  • http://iphoneapp.us/the-complete-iphone-development-toolbox/ The Complete iPhone Development Toolbox | iPhoneApp Dev Blog

    [...] iPhone Game Programming – Part one of a 4-part series on creating your first iPhone Game. Create a simple pong style game and learn about collision detection, sounds, AI and user interaction in the process. [...]

  • cooldaddybeck

    Andy, for adjusting from portrait to landscape (to be used in your tennisViewController.m and SplashViewController.m files):

    // Override to allow orientations other than the default portrait orientation.
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
    }

  • Sylvain

    Hello,

    Why do we call :

    self.gameState = kGameStatePaused;
    ballVelocity = CGPointMake(kBallSpeedX,kBallSpeedY);

    et not : (missing “self”)

    self.gameState = kGameStatePaused;
    self.ballVelocity = CGPointMake(kBallSpeedX,kBallSpeedY);

    then here (missing self)

    if(gameState == kGameStatePaused) {…
    end not

    if(self.gameState == kGameStatePaused) {….

    Thank you.

  • Matt

    Hey Everyone,
    I’m still not able to get anything to show up other than the court image… I’ve looked through the threads, people seemed to have documented that they figured it out, but have not posted any solutions… any help for a noob?

    thanks in advance!

  • J. Cohen

    I completed this first tutorial. The program builds and loads into the iPhone simulator without problem. It briefly shows the load screen, then displays the tennis court which I built according to the video. However, nothing happens when I click to continue! I might be wrong, but it would seem that, based on my understanding of the code, that it should start the ball moving.

    Should it?

    Or do I have to do step 2 before anything actually happens?

    I’m reluctant to continue before I know that I have completed these steps properly. Thanks!

  • J. Cohen

    Well it was a – instead of an = that was making it fail… works now :)

  • Matt

    I have the problem where only my tennis court shows up. Anyone know what I’ve done wrong? Thanks in advance for any tips!

  • Tom

    In response to ash’s question, i had the same problem but by saving the iTennisViewController.h file when you’ve added the code, then entering Interface Builder it works just fine.

  • http://www.coachrickthemittologist.com James Ricky Coward

    Hey Brandon, great tutorial, very helpful and easy to understand. I have an idea for an iPhone game, sports training related. I know you probably get this a lot, lol, but I do not want to go into too much detail on a blog, but if you could take a moment and check out my website, listed above, you will see the type of training I do, it may give you a hint as to what I am looking to develop. Please feel free to email me at my email address listed above and I can go into more detail.

    Thanks
    Rick

  • Doug Stafford

    Great tutorial.

    I have finished part 1, but the tennis ball is not moving?

    Any ideas?

    Thanks

  • macmandev

    i downloaded the source code but the points don’t count up and the racquet wont move?
    thanks

  • darius

    Hey, I finally got all the coding to be working and debugged!

    But now when I build and run it, all the simulator shows me is the court pic. I’ve tried messing around in the interface builder but nothing seems to let me see any other object.

    Is there some sort of arrangement order that I need to setup?
    If anyone could help that would be awesome!

    Thank you.

  • http://CrawfordWorks.ca Andrew Crawford

    Hey Guys,

    I’d like to start off by saying AWESOME tutorial(s) I’ve been finding out more things I can do via the apple developer program now.

    One problem though:
    I’m attempting to reproduce a game like this with a few more complications but am running into an interface error. The code appears to be correct (producing no errors according to Xcode 3.2.2. When the app starts up in simulator, it loads the default.png image without a problem and then the splash.png image. At first there were some fading errors but I managed to fix those when I upgraded Xcode from 3.1.3 to 3.2.2. In any case it still fades the splash screen to a solid white display. I’ve attempted to find help via apple’s technical support, ect. and have no success. Has ANYONE here ever had this problem and if so how did you find a solution?

  • http://CrawfordWorks.ca Andrew Crawford

    Hey Guys,

    I’d like to start off by saying AWESOME tutorial(s) I’ve been finding out more things I can do via the apple developer program now.

    One problem though:
    I’m attempting to reproduce a game like this with a few more complications but am running into an interface error. The code appears to be correct (producing no errors according to Xcode 3.2.2. When the app starts up in simulator, it loads the default.png image without a problem and then the splash.png image. At first there were some fading errors but I managed to fix those when I upgraded Xcode from 3.1.3 to 3.2.2. In any case it still fades the splash screen to a solid white display. I’ve attempted to find help via apple’s technical support, ect. and have no success. Has ANYONE here ever had this problem and if so how did you find a solution?

    If you have an answer you can contact me via my business site at CrawfordWorks.ca
    Thank you in advanced !

  • David

    1. this is supposed to be for a tutorial- he/she has gone to the trouble of making it for you- how much more can you ask for???
    2. bluetoothing is incredibly hard

  • http://vaclav.vancura.org/weekly-digest-for-may-2nd Weekly Digest for May 2nd — Hello. My name is Václav Vančura.

    [...] iPhone Game Programming Tutorial – Part 1 | iCodeBlog [...]

  • Mark

    Hi. I’m trying to add the court.png file to the imageview– the first step of the video. however, when I try to click the dropdown menu to get court.png, none of my pictures are there.

    It’s like my iTennisViewController.xib isn’t linked to the resource images that I imported. Is there some sort of linking step that I’m missing? I can’t type it manually either because I just get a giant blue question mark.

    Thanks!

  • http://www.silenceit.ca/2010/05/31/introduction-to-iphone-applications/ Introduction to iPhone Applications | silenceIT Web Design and Marketing, Rich Internet Applications, e-Business IT |

    [...] If you’ve never developed using Xcode before it can seem overwhelming since there is a lot available. Personally, as a web developer, I prefer a leaner coding environment; but I quickly realized that a lot of the tools given are indispensable. A lot of great fundamentals can be at the Apple Developer Center, but if you’re like me and just want to jump into something to play around, there are simple tutorials available online. I chose to build a game. [...]

  • http://site-design.co.nz mazen

    This is great, you are the best of the best :) thanks alot

  • Chris

    Anybody else having problems with the video part of the tutiorial (building the interface) buffering? I cant seem to view the movie due to it only buffering a few seconds.

    Are there any other ways to view the movie?

    Just starting this tutorial and would be a real shame to not be able to continue.

    Please reply, Thanks.

  • Michele

    @Simon88
    Thanks a lot for your tip! You save my night :)

    @author
    very very well work
    grazie anche dall’Italia

  • Chris

    Never mind. My Quicktime is playing up on my mac so loaded it up on my PC instead and hey presto its worked.

    This doesnt make PC’s better than Macs in anyway though lol.

  • http://robobros.net Nate

    Tom’s answer may have worked, but are you dragging from the label to the file’s owner, or the file’s owner to the label? The only way it works it to drag the file owner’s outlet to the label.

  • http://robobros.net Nate

    Also, try right clicking on the file owner and dragging to the label.

  • http://robobros.net Nate

    Try right clicking on the file owner. If you did the stuff in the iTennisViewController.h, then you should be able to see them there.

  • http://robobros.net Nate

    don’t use the New Referencing Outlet

  • http://robobros.net Nate

    press control, and then a side arrow key in the simulator. That rotates it.

  • Noe

    Hi I write the code perfectly but i hate this error:
    Code Sign error: The identity ‘iPhone Developer’ doesn’t match any valid certificate/private key pair in the default keychain

    Is it real that i need to get the paid version?
    or i can correct that?

  • CJ

    How? I’m getting the same problem.

  • CJ

    Followed the tutorial and all I see is the court.png no ball or racquets. I’ve seen others with the same problem and they said they fixed it but how did they do it?

  • Anonymous

    Just to let everybody who is having the problem when they link to the File’s Owner, you must select the object e.g the racquet, then drag the line across.

  • Anonymous

    Hi

    Easy to understand tutorial, well done!

    However, when I do build and go, I get 18 errors, I deleted most of the stuff where the errors were coming from but I think they were the most important bits, but I wanted to try build and go again, but I got one error saying:

    Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1

    Any ideas what I might be doing wrong?

    J.F

  • Camel

    @those where only the court shows up.

    I had the same problem and solved it like this.

    Open the interface builder. In the window with 3 icons (File’s owner, First Responder, View), click on the View icon.
    Go to the View Connections tab and make a new connection to the File’s Owner.

  • Camel

    @those where only the court shows up.

    I had the same problem and solved it like this.

    Open the interface builder. In the window with 3 icons (File’s owner, First Responder, View), click on the View icon.
    Go to the View Connections tab and make a new connection to the File’s Owner.

  • http://kerempalabiyik.com/2010/02/27/iphone-uygulamalari-gelistirmek-isteyenler-icin-ucretsiz-100-kurs-ve-rehber/ iPhone uygulamaları geliştirmek isteyenler için ücretsiz 100 kurs ve rehber « Kerem PALABIYIK

    [...] iPhone Game Programming Tutorial: This multipart tutorial offers a way to learn OpenGL and Quartz for iPhone development. [iCode] [...]

  • ashok yagnik

    hi
    suddenly i am facing problems with my iphons games that is wheneevr i click on the game icon for a second it opens a game but automatically it gets close so please help me with it

  • http://www.iphoneappacademy.com/7/iphone-game-tutorials/itennis-iphone-game-tutorials/ iTennis – iPhone Game Tutorials – iPhone App Academy

    [...] iTennis iPhone Game Tutorial – Lesson 01 [...]

  • http://sites.google.com/site/ubomagicland/index Patrick

    So nice tutorial , I can run this game on iphone simulator successfully. Thank you very much

  • Xander PK

    hey where’s the part 2 of the tutorial ???
    X-(

    PS. part 1 was really great! :D

  • http://animaltracker.wordpress.com/2010/07/23/a-period-of-learning-part-2/ A period of learning (Part 2) « Animal Tracker (iPhone Game) Blog

    [...] trawled the Web looking for tutorials and came across a few interesting ones. One was a simple iTennis game written in Cocoa Touch by Brandon Treb, but it didn’t follow the MVC design pattern. So, [...]

  • http://andygerth.blogspot.com Andy

    Have you tried saving everything, including your xCode files?

  • Giovanni Di Russo

    Hi, great tutorial! I want to know one thing for future reference, though: what (if any) is the difference between UIImage and UIImageView? I know this is a simple question, but I would greatly appreciate an answer.

  • Gio

    Sorry to double post, but there is a problem with mine:
    when I run it, the ball moves even though it is paused and clicking the screen on the simulator does not get rid of the label. Any help would be very appreciated.

  • http://www.theapplelounge.com/tutorial/app-development-per-ios-i-tutorial/ App development per iOS, i tutorial – TheAppleLounge

    [...] iPhone gaming programming (parte 1). Ottimo tutorial suddiviso in 4 parti sulla creazione di un videogioco per iPhone. Un semplice Pong style che ci consente di apprendere di più sulla collisione di oggetti, Ai, processi di interazione degli utenti (parte 2), creazione di splash page (parte 3) e gestione dei suoni (parte 4). Una panoramica generale su tutto ciò che c’è da sapere sullo sviluppo di game per iPhone. Se volete sviluppare videogame per iphone, questo tutorial è assolutamente indispensabile. [...]

  • andy

    how do you put this on the iphone/itouch

  • andy

    your a douche

  • joe

    andy thats not nice

  • joe

    cool andy that is so cool it smells like chocolate and limes at the same time

  • http://icodeblog.com/2010/09/09/iphone-game-programming-series-blackjack-part-1-the-deck/ iPhone Game Programming Series: Blackjack – Part 1: The Deck | iCodeBlog

    [...] has been quite some time since our last iPhone video game series and now we are ready to start a new one.  Given the success of our iTennis tutorial series, we [...]

  • http://www.ios4jailbreak.com/2010/09/iphone-game-programming-series-blackjack-%e2%80%93-part-1-the-deck/ iOS4 Jailbreak » iPhone Game Programming Series: Blackjack – Part 1: The Deck

    [...] has been quite some time since our last iPhone video game series and now we are ready to start a new one.  Given the success of our iTennis tutorial series, we [...]

  • http://icode.dreamvision-soft.com/blog/?p=81 iPhone Game Programming Series: Blackjack – Part 1: The Deck | iCode

    [...] has been quite some time since our last iPhone video game series and now we are ready to start a new one.  Given the success of our iTennis tutorial series, we [...]

  • Eddie

    Thanks a lot for this article! You might want to add: For people who do not own a Mac, you can install Mac OS Snow Leopard in a virtual environment with VirtualBox and get this to work. Google “mac os snow leopard virtualbox”.

  • Dave

    Hey, any1 got the links to the other parts of this? Would be greatly appreciated :D

  • Dave

    Hey, any1 got the links to the other parts of this? Would be greatly appreciated :D

  • Neil Cooper

    Brandon
    Can you please help. I have got to the first stage of your tutorial where you add the court.png image but no files appear in the drop down menu. On looking at previous questions I see that others have had this problem but I have tried saving and even doing the whole thing from scratch again but I just cannot get this image to go to view. Any suggestions as to what I am doing wrong? Regards Neil

  • diaz

    i got a problem with the interface built, cause the video you provide cut off when add UILabel “taptobegin”. The rest of the video is missing. Please tell me what the rest contain.
    ^^

  • Dr. Rolf R. Fink

    Good stuff, but where is part two ?

  • http://blog.roychowdhury.org/2010/10/20/writing-a-professional-looking-bricks-game-for-the-iphone-part-i/ iConverged » Writing a professional looking Bricks game for the iphone (Part I)

    [...] to get me started. Of specific mention, I found two resources that were of help: a) The tutorial on ping pong gaming. b)  And also, “Beginning iPhone Game Development” by Apress which has a very [...]

  • Unixx

    10x but the video file for the outlets connections is missing!!

  • http://iphonetuts.com/?p=107086 iPhone Game Programming Series: Blackjack – Part 1: The Deck | Iphone tutorials

    [...] has been quite some time since our last iPhone video game series and now we are ready to start a new one.  Given the success of our iTennis tutorial series, we [...]

  • http://blog.roychowdhury.org/2010/10/25/tutorial-iphone-game-programming-professional-bricks-part-i/ iConverged » Tutorial: iPhone Game Programming- professional Bricks (Part I)

    [...] Ping Pong tutorial [...]

  • http://techwonders.blogspot.com PT

    Excellent and unselfish tutorial! Great Stuff!

  • Will

    I have had the exact same problem. The fade only works for the default or splash image but for no other image. I even photoshopped an image to get the the same pixel dimensions as the court.png and still no luck

  • Johnny6

    Love this cant wait to see more

  • Vishakha

    I have completed the tutorial and build and run successfully.But my problem is when I click on Tap To Begin Label,the ball starts moving but can’t stop it once it started moving and the racquets are not moving also the player’s and computers score’s are still the same as 0. Can you please help me to solve this problem or we need to write code for this to work properly ?

  • Joe

    Hey man great tutorial, but I got all these errors saying kballspeed undefined, or gameloop undefined, how can i fix that?

    thanks

  • Bob

    Hey! wasnt sure of you where answering questions via email, but i had to try…
    i finished the tutorial and when i attempt to simulate the game it immediately exits back to the menu.. this is my first game so maybe its a setting?

  • http://www.wizard-soft.com Martin

    @Bob,

    You may have made the same mistake as me:

    In the viewDidLoad function I had:

    selector:@selector(gameloop)

    instead of:
    selector:@selector(gameLoop)

    (lowercase ‘l’ instead of uppercase ‘L’.

    Changing to the correct case sorted the problem.

    Cheers,

    Martin.

  • http://www.openxcell.com iPhone Application

    It is an informative tutorial. Thanks for sharing code. It will help the beginner for creating an iPhone game. You explain every step in very simple way.

  • http://brandontreb.com/new-iphone-game-programming-tutorial-post-on-icodeblog/ brandontreb.com » New iPhone Game Programming Tutorial Post On iCodeBlog

    [...] iPhone Game Programming Tutorial – Part 1 [...]

  • http://www.cygnismedia.com/ facebook app develop

    Great Information and post! It is very informative and suggestible for the user of solar May I think it can be beneficial in coming days…

  • http://www.worldoftrade.com/ Rolex Deep Sea

    This post is different from what I read on most blog. And it have so many valuable things to learn.

  • Ollie

    Hi there..

    When connecting you need to right click when holding down on the icon which connects the item to.

  • Ollie

    Hi there

    I have read through your tutorial and it is very well done! I have one question. I have done everything the same as the tutorial suggests and when I click on the app on the simulator it loads fine and I click the button to start the game and then the ball moves but the racquets don’t please help! Thanks best regards Ollie

  • Riscar

    I have gone through this tutorial maybe 2 or 3 times now even with copy paste to make sure I did it right looked at it front and back and when it loads on the Ipod Touch its gets to the iTennis loading png and it seems to hang there is there anything that I am doing wrong that I can not seem to catch?

  • Zach

    hello, great tutorial here… but i just cant seem to get the connections inspector to work, i closely followed your steps and after i had clicked on the connections inspector under the tools menu and when i went to drag the referencing outlet into the files owner, all that comes up is “view”

  • http://hirephpwebdeveloper.com marksteve

    I searches so many pages for iPhone Programming but can’t find satisfied answer. when i come across your page my problem is solve and i found my solution from this tutorial. Thanks a lot for supply this amazing information.

  • Kenneth

    Hey,
    Im 12 and I have a bit of a problem: when I run this app on the simulator, it stays on the loading page and in the Debugger Console it says GDB: Stopped at breakpoint 13 (hit count: 1)-’line 9′

    Please help me this is my first app!
    Great tutorial by the way.
    Thanks!

  • http://vendomiapple.com/2011/01/29/100-cursos-gratuitos-y-tutoriales-para-aspirantes-a-desarrolladores-de-app-para-iphone/ 100 cursos gratuitos y tutoriales para aspirantes a desarrolladores de Apps para iphone « Programacion « VENDO MI APPLE

    [...] iPhone Game Programming Tutorial: This multipart tutorial offers a way to learn OpenGL and Quartz for iPhone development. [iCode] [...]

  • Christian

    i get 2 error with the line of code “ball.center =CGPointMake(ball.center.x + ballVelocity.X , ball.center.y + ballVelocity.Y);” it says CGPoint has no member named x or y? any help on solving this error?

  • Thales Medeiros

    It happened because probably you clicked on a line in the code marking it as a breakpoint. It`s a feature that helps executing something we call Debug the application.

    Try to find at left of your line 9 for a blue arrow. Right click it and select “Remove Breakpoint”.

  • Thales Medeiros

    It happens because it`s not supposed to happen!
    The code is not that complete. It`s just a start point.

  • John Quinn

    @Christian: maybe it’s your capital X and Y on ballVelocity?

  • http://www.my-digital-source.ca Iphonerepairnow

    Always great stuff from these guys. Thanks for another awesome tutorial, appreciate it.

    when does part 2 come out?

    iPhone/ipod touch repairs @

  • Mossa

    Since the web has changed, I cannot acces the video. I see:

    [qt:http://icodeblog.com/wp-content/uploads/2009/01/Game_1.mov 640 416]

    I’ve tried copy&paste for:

    qt:http://icodeblog.com/wp-content/uploads/2009/01/Game_1.mov 640 416
    http://icodeblog.com/wp-content/uploads/2009/01/Game_1.mov