iPhone Game Programming Tutorial – Part 1
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:
Advertisement
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.
Open up XCode and create a View Based Application. Name this application iTennis.
- Posted by brandontreb on 15 Jan 2009 in iPhone Game Programming, iPhone Programming Tutorials
- Digg |
- Del.icio.us |
- Stumble |
- 184 Comments »
184 Responses
frosty Says:
January 15th, 2009 at 9:31 pm
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 Says:
January 16th, 2009 at 1:23 am
Cant wait for you to finish the tutorials. Congrats by the way.
David Says:
January 16th, 2009 at 1:44 am
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 Says:
January 16th, 2009 at 4:05 am
Thanks for writing this, I look forward to reading more game tutorials.
Andre Says:
January 16th, 2009 at 7:30 am
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 Says:
January 16th, 2009 at 7:35 am
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.’
Paul Rangel Says:
January 16th, 2009 at 8:05 am
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 Says:
January 16th, 2009 at 10:14 am
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 Says:
January 16th, 2009 at 12:25 pm
Yes! I have been searching the net for a single iPhone game tutorial! This is exactly what I need! Keep up the great work!
i-n00b Says:
January 18th, 2009 at 7:24 am
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
Aaron Says:
January 18th, 2009 at 12:48 pm
Really great tutorial- looking forward to the next in the series.
Gp Says:
January 18th, 2009 at 5:08 pm
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 Says:
January 18th, 2009 at 7:42 pm
Great tutorial, but I also have the same problem where it crashes when I go to launch. Any one know why?
kuyote Says:
January 19th, 2009 at 1:12 am
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 Says:
January 19th, 2009 at 5:17 pm
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 Says:
January 20th, 2009 at 12:32 am
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 Says:
January 20th, 2009 at 4:37 am
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 Says:
January 20th, 2009 at 8:54 am
great tutorial but same like ball from standford, pls finish next part , thanks
naren Says:
January 21st, 2009 at 7:06 am
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 Says:
January 21st, 2009 at 7:38 am
narender.mudgal, thanks a lot, that did the trick. Thanks!
Looking forward for the next part of the tutorial!
DN Says:
January 23rd, 2009 at 7:48 am
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
Brandon Says:
January 23rd, 2009 at 9:49 am
@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 Says:
January 23rd, 2009 at 1:42 pm
Hey, thanks for the tutorial. It’s a great start and put together nicely. I’m looking forward to seeing more.
ck Says:
January 23rd, 2009 at 10:37 pm
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 Says:
January 24th, 2009 at 12:03 pm
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 Says:
January 25th, 2009 at 12:32 am
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?
Brandon Says:
January 25th, 2009 at 9:50 am
@masterjcl
Thats means you don’t have the latest version of quicktime. Download that and the video will work.
Brandon Says:
January 25th, 2009 at 9:54 am
@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.
Chintan Says:
January 25th, 2009 at 10:39 pm
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 Says:
January 26th, 2009 at 3:37 pm
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 Says:
January 26th, 2009 at 4:04 pm
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 Says:
January 26th, 2009 at 4:36 pm
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 Says:
January 26th, 2009 at 10:32 pm
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 Says:
January 26th, 2009 at 11:51 pm
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]];
}
Chintan Says:
January 26th, 2009 at 11:52 pm
@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 Says:
January 27th, 2009 at 12:05 am
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 Says:
January 27th, 2009 at 12:39 am
one thing i left
in viewdidload
self.pscore = 0; initialize the playerscore with zero i will continue with green_racquet functionality
naren Says:
January 27th, 2009 at 1:50 am
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 Says:
January 27th, 2009 at 5:33 am
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.
rey Says:
January 27th, 2009 at 4:07 pm
@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.
Chintan Says:
January 28th, 2009 at 2:19 am
@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 Says:
January 28th, 2009 at 10:47 am
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 Says:
January 28th, 2009 at 4:36 pm
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 Says:
January 29th, 2009 at 12:54 pm
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 Says:
January 29th, 2009 at 1:12 pm
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 Says:
January 29th, 2009 at 5:00 pm
@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 Says:
January 30th, 2009 at 2:39 am
@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 Says:
January 31st, 2009 at 7:15 am
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 Says:
January 31st, 2009 at 11:51 am
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 Says:
January 31st, 2009 at 11:55 am
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 Says:
January 31st, 2009 at 4:50 pm
hey Naren…
can you upload the project so we can download it with your changes?
Naren Says:
February 3rd, 2009 at 12:03 am
@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.
Jhsw77 Says:
February 5th, 2009 at 6:59 pm
Is there a way to create the ball and paddles the old fashioned way with code and WITHOUT Interface Builder?
Mark Says:
February 6th, 2009 at 4:18 am
You are the MAN! If only Apple had guys like you writing their tutorials for them…
josh Says:
February 6th, 2009 at 6:07 pm
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 Says:
February 8th, 2009 at 10:29 am
@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??
Naren Says:
February 10th, 2009 at 10:09 pm
@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.
Brennon Says:
February 10th, 2009 at 10:26 pm
Brilliant! However, when I ran it just to see what would happen I got 2 warnings and 24 build errors!
Bruce Says:
February 11th, 2009 at 10:47 am
Thanx a Million, to Brandon, Naren and Joe. You guys have done a great job putting this together for us NOOBs. Much appreciated.
BdR Says:
February 11th, 2009 at 5:06 pm
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 Says:
February 11th, 2009 at 9:06 pm
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 Says:
February 11th, 2009 at 9:50 pm
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 Says:
February 11th, 2009 at 10:03 pm
@Ricky
Check to make sure you declared your two score labels as “IBOutlet UILabel” and not UIImageView like the ones before them
Ricky Says:
February 11th, 2009 at 10:09 pm
@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 Says:
February 11th, 2009 at 10:11 pm
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 Says:
February 11th, 2009 at 10:12 pm
@Ricky
Don’t forget to take care of them below for the @property portion
Kyle Says:
February 11th, 2009 at 10:13 pm
@Ricky
Glad it worked – yeah I have no idea what’s wrong on my end
Ricky Says:
February 11th, 2009 at 10:22 pm
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 Says:
February 11th, 2009 at 10:46 pm
urgh – had a width mixed with a height. It’s working now.
Looking forward to part two!
Jo Says:
February 12th, 2009 at 5:56 am
@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 Says:
February 12th, 2009 at 6:32 am
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 Says:
February 12th, 2009 at 7:06 am
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 Says:
February 12th, 2009 at 7:12 am
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 Says:
February 12th, 2009 at 7:14 am
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 Says:
February 12th, 2009 at 7:15 am
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 Says:
February 12th, 2009 at 7:16 am
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 Says:
February 12th, 2009 at 7:19 am
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 Says:
February 13th, 2009 at 1:11 am
ooops,
my posts are deleted .
ok great. I will not post more stuff now onwards.
Thanks a lot.
Ricky Says:
February 13th, 2009 at 9:36 pm
Hey,
This as been out for a month! When is Part 2 coming out? Thanks Brandon! Great Tutorial thus far
-Ricky
miah Says:
February 14th, 2009 at 8:19 am
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 Says:
February 14th, 2009 at 8:21 am
nevermind. i just figured it out. i was using a ‘retain’ in the @property
miah Says:
February 14th, 2009 at 10:34 am
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.
Sameer Gupta Says:
February 16th, 2009 at 6:41 pm
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 Says:
February 16th, 2009 at 7:29 pm
Great tutorial! REALLY looking forward to the next one. Thanks
Hau Says:
February 17th, 2009 at 1:05 pm
Thanks for the great tutorial! I can’t wait to try it out. Looking forward to the rest of your series!
Maarten Billemont Says:
February 17th, 2009 at 4:33 pm
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 (http://gorillas.lyndir.com) 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:
http://gorillas.lyndir.com/trac
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 Says:
February 18th, 2009 at 3:41 am
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!
bob Says:
February 18th, 2009 at 9:35 am
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.
Hau Says:
February 18th, 2009 at 9:10 pm
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: http://www.haungo.com/2009/02/if-first-you-dont-succeed.html
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!
Hau Says:
February 18th, 2009 at 9:14 pm
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
Owen Says:
February 20th, 2009 at 5:07 pm
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 Says:
February 22nd, 2009 at 9:05 pm
This is brilliant. Exactly what a lot of aspiring Mac developers are looking for. Thank you for providing this for us!
Frank Says:
February 24th, 2009 at 7:55 pm
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 Says:
February 24th, 2009 at 9:12 pm
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 Says:
March 2nd, 2009 at 1:10 am
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 Says:
March 4th, 2009 at 11:14 am
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
iPhone Dev - Games/Apps - Top Bookmarks « Java Developer / Fledgling iPod Touch Developer Says:
March 10th, 2009 at 11:16 pm
[...] iPhone Game Programming Tutorial – Part 1 | iCodeBlog [...]
Nick Says:
March 20th, 2009 at 12:00 am
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?
iPhone development Tutorials « The Brook Song - ঝর্ণার গান Says:
March 24th, 2009 at 12:22 pm
[...] 33. iPhone game programming [...]
Chris Anderson Says:
April 6th, 2009 at 3:43 pm
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!
Roland Combes Says:
April 7th, 2009 at 5:00 pm
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.
iPhone game development guide: On the go tutorial | iPhone Footprint Says:
April 14th, 2009 at 1:14 am
[...] tutorial has three parts, the first part deals with the creation of different folders within the main project folder. The second part [...]
iNewbie Says:
April 20th, 2009 at 11:06 am
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 Says:
April 21st, 2009 at 10:51 am
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 Says:
April 22nd, 2009 at 12:09 am
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 Says:
April 22nd, 2009 at 3:08 pm
I got it. It’s because I didn’t connect something, something the tutor didn’t talk about explicitly…
The Kellen Says:
April 22nd, 2009 at 6:07 pm
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.
alex Says:
April 29th, 2009 at 1:48 am
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 Says:
April 29th, 2009 at 9:55 am
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 Says:
May 3rd, 2009 at 8:27 pm
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 Says:
May 5th, 2009 at 6:33 pm
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 Says:
May 12th, 2009 at 8:10 pm
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 Says:
May 19th, 2009 at 3:41 pm
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 Says:
May 21st, 2009 at 5:49 am
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 Says:
May 25th, 2009 at 9:58 pm
@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 Says:
May 29th, 2009 at 6:13 am
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 Says:
May 31st, 2009 at 4:21 pm
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!
Carlos Says:
June 3rd, 2009 at 8:01 pm
Great series. I’ll add a snippet about it to our news.
http://www.idevgames.com/news/itennis-iphone-game-programming-tutorial
Henry Says:
June 15th, 2009 at 2:32 pm
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!
Al Says:
June 24th, 2009 at 2:21 pm
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 Says:
June 29th, 2009 at 8:24 pm
Fixed it! Never mind! Excellent tutorial! Can’t wait to try the others!
Al Says:
June 29th, 2009 at 8:24 pm
Fixed it, so never mind! Excellent tutorial, Brandon! Can’t wait to try the others!
Anthony Says:
July 1st, 2009 at 10:21 pm
wow, helped me allot. im looking forward to reading more of these tutorials. keep up the great work man! =)
iBots Says:
July 4th, 2009 at 10:27 am
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?
100 ресурсов для iPhone-разработчиков - Краковецкий Александр: заметки программиста - iPhone Community в Украине Says:
July 5th, 2009 at 6:25 am
[...] iPhone Game Programming Tutorial: This multipart tutorial offers a way to learn OpenGL and Quartz for iPhone development. [iCode] [...]
Developer Steals iPhone App Code, Submits As Own | KRAPPS | a different and funny iPhone app review site Says:
July 9th, 2009 at 1:43 am
[...] 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 [...]
Apple Bloog » Blog Archive » Lifted tutorial code winds up in $0.99 App Store tennis game Says:
July 9th, 2009 at 7:00 pm
[...] 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 [...]
Lifted tutorial code winds up in $0.99 App Store tennis game | iPhone Firmware Says:
July 9th, 2009 at 7:45 pm
[...] 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 [...]
Lifted tutorial code winds up in $0.99 App Store tennis game | InfoFork.com Says:
July 9th, 2009 at 7:47 pm
[...] 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 [...]
AppleUsers.org News » Lifted tutorial code winds up in $0.99 App Store tennis game Says:
July 9th, 2009 at 7:48 pm
[...] 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 [...]
iWyre Says:
July 9th, 2009 at 8:06 pm
[...] 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 [...]
Apple User’s Blog » Lifted tutorial code winds up in $0.99 App Store tennis game Says:
July 9th, 2009 at 8:15 pm
[...] 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 [...]
Lifted tutorial code winds up in $0.99 App Store tennis game » Shai Perednik.com Says:
July 10th, 2009 at 12:20 am
[...] 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 [...]
Free Tutorial code sold as 99c App on the AppStore » iPhonePulse Says:
July 10th, 2009 at 6:49 am
[...] 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 Says:
July 12th, 2009 at 4:37 pm
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 Says:
July 12th, 2009 at 4:38 pm
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 Says:
July 13th, 2009 at 11:38 pm
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 Says:
July 13th, 2009 at 11:45 pm
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.
Lifted tutorial code winds up in $0.99 App Store tennis game Says:
July 15th, 2009 at 7:04 pm
[...] 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 Says:
July 25th, 2009 at 2:30 pm
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.
DevTutorial #13 – Creiamo il nostro primo gioco, Pong! (Parte I) - Bubi Devs Says:
July 27th, 2009 at 8:50 am
[...] 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 Says:
August 6th, 2009 at 1:44 pm
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 Says:
August 7th, 2009 at 4:27 am
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 Says:
August 7th, 2009 at 4:30 am
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.
Quick Post: iPhone Game Development Tutorials | Thomas Nicholson iPhone Developer Newbie Says:
August 19th, 2009 at 1:24 pm
[...] iPhone Game Programming Tutorial – Part 1 [...]
ThinkMud Says:
August 22nd, 2009 at 7:01 pm
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 Says:
August 25th, 2009 at 9:56 pm
Great Job….
It’s been very detailed, can’t wait to have my Mac to follow to follow your instruction…
iPhone/iPod touch游戏开发 | SHUGUO Says:
September 2nd, 2009 at 2:52 am
[...] iTennis这个教程还不错,虽然没用上什么华丽复杂的功能,但是一步一步跟着做下去,对于怎么做出一个iPhone游戏还是很有帮助的。这也是我除了Hello World之外第一个自己尝试的iPhone App了。虽然Object-C的挺多语句还不很习惯,也有一些不理解的地方,但确实感受到了,开发iPhone的项目门槛并不高。这也给自己树立了信心,有机会好好学习和开发iPhone软件。如果有时间,我也自己写一个关于自己开发软件的教程。 [...]
Look Familiar? | Iphone Study Blog Says:
September 4th, 2009 at 6:03 pm
[...] 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 [...]
Granny Coder Says:
September 7th, 2009 at 8:12 am
Hello dear, thank you for useful article. It cleared me a lot of things. Love, Granny.
Amy Says:
September 13th, 2009 at 6:19 pm
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 Says:
September 13th, 2009 at 6:20 pm
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
iPhone Game Programming Tutorial Suggested Link « Uright Tech Blog Says:
October 4th, 2009 at 4:48 pm
[...] 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. [...]
unt Says:
October 5th, 2009 at 12:05 pm
Great, totally awesome tutorial! Please, please continue to make more
Annie ( Period Property ) Wagner Says:
October 7th, 2009 at 8:01 am
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
Some Great Resources! | My First iPhone Application Says:
October 20th, 2009 at 9:25 pm
[...] iPhone Game Programming Tutorial: This multipart tutorial offers a way to learn OpenGL and Quartz for iPhone development. [iCode] [...]
jonk Says:
October 23rd, 2009 at 4:18 am
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 Says:
October 25th, 2009 at 11:07 pm
Disregard my last post. I figured it out.
Nice job!
ash Says:
October 27th, 2009 at 8:46 am
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
Tommy Myers Says:
November 21st, 2009 at 3:59 am
Hi,
how can i modify the app to play against your friends through bluetooth?
Tommy
The Ultimate Toolbox for iPhone Development - Creative Solutions Says:
November 24th, 2009 at 1:58 am
[...] iPhone Game Programming Tutorial: Part 1 Here’s a complete tutorial for creating a Pong-like iPhone game. [...]
Aussie96 Says:
November 26th, 2009 at 4:29 am
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!
Enlaces para desarrollar en el iPhone | El mundo de IMD Says:
November 30th, 2009 at 1:50 am
[...] iPhone Game Programming Tutorial: Part 1 Here’s a complete tutorial for creating a Pong-like iPhone game. [...]
Simon88 Says:
December 6th, 2009 at 6:27 pm
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 Says:
January 14th, 2010 at 3:27 pm
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.
My first iphone game! « Learning techie Says:
January 21st, 2010 at 5:11 pm
[...] 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. [...]
CasdraBlog » Blog Archive » links for 2010-01-29 Says:
January 29th, 2010 at 5:03 am
[...] iPhone Game Programming Tutorial – Part 1 | iCodeBlog (tags: iphone programming) [...]
iPhone Game Programming Tutorial – Part 1 « Evolving Minds Says:
January 29th, 2010 at 9:02 am
[...] 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 Says:
January 30th, 2010 at 8:44 am
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!
The Ultimate Toolbox for iPhone Development | c'est la vie Says:
February 1st, 2010 at 7:57 pm
[...] iPhone Game Programming Tutorial: Part 1 Here’s a complete tutorial for creating a Pong-like iPhone game. [...]
Chimpy Says:
February 5th, 2010 at 3:17 pm
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











