Game Maker's Garage Forum

Game Creation => Code Exchange => Topic started by: Gan on January 21, 2010, 08:10:07 PM

Title: My iPhone Game Tutorials for Beginners
Post by: Gan on January 21, 2010, 08:10:07 PM
Hey guys, I've finally come up with the courage to make a tutorial about iPhone game development. Yes, using my voice. This is my very first screen cast + voice tutorial so it definitely won't be perfect.

The purpose of the tutorials is to teach you guys how to make your own games for the iPhone platform. I have created a template(Download is below) that will make the process painless and quite fun.

Right-click to download. Stars(*) mean downloads that go along with tutorial.

Tutorial #1(75mb,13min): Basics of Syntax/Structure and Building Your First Game (http://web.mac.com/avisaria/iPhoneTut1.mov)
*Ball Game (http://web.mac.com/avisaria/BallGame.zip)

Tutorial #2(80mb,10min): Drawing Images and Detecting Touch (http://web.mac.com/avisaria/iPhoneTut2.mov)
*Ball Game 2 (http://web.mac.com/avisaria/BallGame2.zip)

Tutorial #3(115mb,20min): Using NSMutableArray, Making a Main Menu, and Infinite Balls (http://web.mac.com/avisaria/iPhoneTut3.mov)
*InfiniBalls (http://web.mac.com/avisaria/InfiniBalls.zip)

*iPhone Game Template Download (http://web.mac.com/avisaria/iPhoneGameTemplate.zip)


-Gandolf
P.S. If you encounter an error when trying to download a tutorial, that's because the tutorial is still uploading.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gnome on January 21, 2010, 09:18:16 PM
THANK YOU :D
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on January 22, 2010, 07:47:30 AM
You're welcome. I'm hoping to give you guys everything you need in the easiest and most painless way possible.

If you guys see something you don't like such as:
"The video's too long."
"You used too many complicated terms!"
"Your voice isn't great enough. Change it to Darth Vader."
"You go too fast, slow down!"

Post away. I want to make this better and custom tailor these tutorials to fit exactly how you guys want them. Likewise, if you have suggestions for the next tutorial, post that too!


-Gandolf
P.S. If you have any coding questions, post them here.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Silverwind on January 22, 2010, 11:14:21 AM
I downloaded the files but couldn't figure out what anything was, nor where the video itself was. What's the name of the file?
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on January 22, 2010, 03:05:21 PM
The video is named iPhoneTut1.mov, future tutorials will just have a higher number. Ball game resource is BallGame.zip. IPhone game template is called iPhoneGameTemplate.zip. If you're using safari, just hit the magnifying glass next to the download in the downloads windows to reveal it in finder.


-Gandolf
P.S. Do you guys need directions to get and install Xcode and the iPhone SDK?
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on February 01, 2010, 07:46:14 PM
Tutorial #2 is up!


-Gandolf
Title: Re: My iPhone Game Tutorials for Beginners
Post by: DWapps on February 12, 2010, 03:09:01 PM
Hi, i'm getting a 'position' undeclared and a 'True' undeclared. Can't find the problem
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Silverwind on February 12, 2010, 03:37:02 PM
Gadzooks... a new member just waltzed in from nowhere? Quick! Everyone smile!

Welcome to the GMG! :) ;D :D
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on February 12, 2010, 03:58:28 PM
:)
Quote
Hi, i'm getting a 'position' undeclared and a 'True' undeclared. Can't find the problem
That means that either you haven't made the global variables 'position' and 'true' or you have a syntax error. I could give you the correct answer immediately if you could post your source. An easy way to do that is uploading on MediaFire (http://mediafire.com) and posting the link.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: DWapps on February 12, 2010, 04:47:30 PM
Here,http://  http://www.mediafire/DWapps
BTW, love the guide and how the codes setup. Helped a tonnn
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on February 12, 2010, 05:21:50 PM
Thanks, I'd love to make it better if you had any suggestions.

Now in your code you had a few mistypes.
In MyCustomView.h:
Code: [Select]
//Put your global game variables here, but don't set a value to them!!

//This works: int test;

//This doesn't: int test = 0;

CGPoint postion;

int xVel;

int yVel;
'position' is spelled as 'postion'. That leads the compiler to believe you hadn't made this variable when you try to use it.
In MyCustomView.m:
Code: [Select]
- (void) awakeFromNib
{

screenDimensions = CGPointMake([[UIScreen mainScreen] bounds].size.height, [[UIScreen mainScreen] bounds].size.width);


//Set any global variables you have made here.

//For example, test = 10;

xVel = 0;

yVel = 0;

positon = CGPointMake(50, 50);
You spelled 'position' as 'positon'.

Code: [Select]
- (void) handleGameTimer: (NSTimer *) gameTimer {

//All game logic goes here, this is updated 60 times a second

positon.x += xVel;

positon.y += yVel;

//This updates the screen

[self setNeedsDisplay];
}
Same error here. Just change 'positon' to 'position'.

And finally you had an error in drawRect:
Code: [Select]
- (void) drawRect:(CGRect)rect
{

CGContextRef context;

//To set a color for a shape:

float color[] = {1.0,0.0,0.0,1.0};


//ALL DRAWING CODE GOES HERE

[self drawOval:context translate:CGPointMake(0,0) color:color point:position dimensions:CGPointMake(10,10) rotation:0 filled:True linesize:0,0];


}
The error is that you have 'filled:True'. In Obj-C you want a boolean to be fully capital: 'filled:TRUE'. Finally your 'linesize:0,0' has an error. That comma should be a period.
No big errors, all good. :) Perhaps I'll make a debugging tutorial...


-Gan
P.S. If you don't want to have to upload rtf files, you could just zip the source and send that.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: DWapps on February 13, 2010, 08:25:55 AM
Ohhh, didn't see my typos, thanks. It worked afterwards. Time to continue on with the tutorial. I'll post back if i have any problems or ?'s.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on February 13, 2010, 10:46:47 AM
Ok. :)


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: bloodline on February 16, 2010, 01:12:56 PM
Hey Gandolf!

I was having a terrible time trying to figure out where the callbacks were (the timer handler is a great help!) and where the CGContext was coming from! After reading through your source code, it all make sense now, so many thanks!

I realise now that it only makes sense for an object to be drawing in it's own context :)

Now I have to figure out a way to link my game model object to the view controller :))

I expect I'll have more questions later!
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Xiphos on February 16, 2010, 03:05:39 PM
I can't wait to start making a game! However it would take 2 hours to download Xcode and the Iphone SDK so I think I'll wait until I have more time.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on February 16, 2010, 06:26:23 PM
Quote
Now I have to figure out a way to link my game model object to the view controller :)
What kind of a game object model? If it's just an NSObject or class you can #include "Class.h" to hook it up.

Quote
I expect I'll have more questions later!
I'll be ready. :)

Quote
I can't wait to start making a game! However it would take 2 hours to download Xcode and the Iphone SDK so I think I'll wait until I have more time.
Ah, I used iGetter (http://igetter.net/). Cut the downloading time in half.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on February 17, 2010, 04:38:35 PM
I have time to make a 3rd tutorials. I have received a suggestion for it but what do you guys think I should focus on?


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on February 17, 2010, 09:58:30 PM
Sorry guys, I had gotten everything prepared and was just ready when I realized I was out of time. I'll try and see if I can record tut #3 tomorrow.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: DWapps on February 18, 2010, 05:21:03 PM
[url] http://DWapps.yolasite.com /url]

Zip of my source is there. I was trying to make program with the black ball/blue background with the ball moving around. For some reason it's not running correctly. Wondering if anyone could tell me what i did wrong.

just stays as a gray screen.



 ???
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on February 18, 2010, 05:35:38 PM
On my way home, will see if I can get you an answer within the hour.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on February 18, 2010, 06:06:07 PM
Bad news, you only uploaded the xcode .xcodeproj file. You gotta upload the file containing it, if you don't than none of your source code will be uploaded.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: DWapps on February 18, 2010, 06:14:18 PM
alright check now

 http:// http://DWapps.yolasite.com/
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on February 18, 2010, 06:21:25 PM
Your source was perfect except for:
Code: [Select]
background = [self loadImage:@"background" type:@"png"];  

ball = [self loadImage:@"ball" type:@"png"];
Your images have capitalized first letters, so it should be:
Code: [Select]
background = [self loadImage:@"Background" type:@"png"];  

ball = [self loadImage:@"Ball" type:@"png"];


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gnome on February 18, 2010, 06:26:08 PM
Wow, this stuff is easier then I though! I might start helping you with simple RPG gan!
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on February 18, 2010, 06:33:53 PM
Awesome. :)


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: DWapps on February 18, 2010, 06:58:14 PM
Wow. I can't thank you enough for these tutorials. They're great. Keep it up. ;D
 (get tut 3 out!)
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on February 18, 2010, 08:33:27 PM
Tutorial #3 is up! Or at least it's trying. Uploading at the moment. Make sure to download the newest template, has new stuff on it.
Ah, sorry guys, I broke the 10min tradition. This tutorial covers new amazing things so I got lost in the excitement and it went to 20min.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gnome on February 18, 2010, 08:35:12 PM
Main menu? Its getting closer!
Title: Re: My iPhone Game Tutorials for Beginners
Post by: bloodline on February 19, 2010, 05:11:44 AM
Hi Gandolf,

I'm totally new to Obj-C and not really sure of the scope of instances... I want my game engine object to be able to send messages to my view obect and vice versa, but as I understand it I need to have a Controler object which has instances of both my view class and my game engine class... Then the controller need to mediate between the two... This is a new way of working for me and will require reworking my game code a great deal...

Second question, I have built custom UIObjects (buttons which are animated), but they need to be animated with respect to the touch input. (i.e. Touch movement cause the icon to change more White if the touch moves up, more black if moves down etc...).. How can I do this, giving realtime feedback, without blocking the main thread of execution (and other animations)?
Title: Re: My iPhone Game Tutorials for Beginners
Post by: bloodline on February 19, 2010, 05:16:13 AM
Third question... Does the AppDelegate run in a separate thread? What can I use this class for?
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on February 19, 2010, 07:01:08 AM
Quote
Hi Gandolf,  
 
I'm totally new to Obj-C and not really sure of the scope of instances... I want my game engine object to be able to send messages to my view obect and vice versa, but as I understand it I need to have a Controler object which has instances of both my view class and my game engine class... Then the controller need to mediate between the two... This is a new way of working for me and will require reworking my game code a great deal...  
I believe you wouldn't need to do such things. My obj-c lingo isn't very refined but I believe a good answer for this problem is to integrate the game engine class into the view class. If you want to post your source I can give you a better answer or if you don't feel comfortable you could post a dummy source which doesn't reveal any of your actual code.
 
Quote
Second question, I have built custom UIObjects (buttons which are animated), but they need to be animated with respect to the touch input. (i.e. Touch movement cause the icon to change more White if the touch moves up, more black if moves down etc...).. How can I do this, giving realtime feedback, without blocking the main thread of execution (and other animations)?
You can put UIObjects right in the UIView class and it'll run perfectly with your game or you could make your own kind of a non-UIObject basic button(Shown in tut #3). As for changing colors of the animation, would be possible using the NSTimer but I haven't experimented with that sort of thing.

Code: [Select]
Third question... Does the AppDelegate run in a separate thread? What can I use this class for?
As far as my knowledge, the AppDelegate probably doesn't run in a separate thread but I'm a bit unsure of that. This class can be used for a ton of great stuff, gets deep in your app and can access your view controlls and the view itself. Of course by using commands you can access it from the view or controller itself giving you access to everything in your app anywhere you need it. Works amazing if you want code that runs before your app quits or if you want to be able to set a responder for a UIObject.

Sorry if I didn't give the answer you wanted though if you could point me in a better direction than I might be able to be more on track.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on February 19, 2010, 04:11:36 PM
Hey guys, I have found code to play music/sound. You can guess what's going to be packaged in the next template update...


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: DWapps on February 20, 2010, 07:19:49 PM
idk if it's just me but the 3rd tutorial isn't working for me. I've waited and waited. But it just stops after a few minutes and will not keep going no matter how long i wait.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on February 20, 2010, 07:31:24 PM
Try to right click and download. Then watch in QuickTime.
If that doesn't work try this link:
Might still be loading if you click right away. (http://web.mac.com/avisaria/iPhoneTut3-2.mov)


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on February 20, 2010, 08:26:03 PM
Having a bit of uploading issues so it might take quite a bit longer until the new link works.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: DWapps on February 21, 2010, 09:45:33 AM
Thanks, new link worked fine.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: bloodline on February 22, 2010, 02:52:32 AM
I just want to add a quick update, it turns out the iPhone's entire event system is multithreaded!

I created a subclass of UIView, and overrode the touches moved method to increase or decrease an internal variable depending upon the direction of touch movement, the. I could then redraw the required image (dependant upon the variable) in the drawRect method, this allows the custom UIView to animate with touches and does not block the other classes which have their own animation code.

Any questions, feel free to ask.


@Gandolf, in Tut3... I'm thinking it would be "More Correct", though not easier, to subview the main menu and the game screen in the superview... this way, one could use IB to build the Menu... and might allow for some other cool stuff, not sure though, as this is all very new to me (I haven't really touched game development since the Amiga days).

I plan to hit OpenGL next, any tips on that would be welcome :)
Title: Re: My iPhone Game Tutorials for Beginners
Post by: DWapps on February 22, 2010, 05:43:51 PM
My button isn't working, helpp

http:// http://DWapps.yolasite.com  ???
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on February 22, 2010, 06:49:15 PM
Within your button's if statement you had:
Code: [Select]
currentView == 2;
Should only have 1 equal sign. That's it.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: DWapps on March 01, 2010, 09:12:09 PM
Could i take the code you provided and use it as my own for selling apps after i add all i need or , can i not do that. All i will be doing is taking your template and adding my code to make an app.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on March 01, 2010, 09:13:59 PM
Yeah go ahead. Absolutely free, it's there to help you guys. (Of course, a little credit wouldn't hurt ;))


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: DWapps on March 01, 2010, 09:32:56 PM
Quote
Yeah go ahead. Absolutely free, it's there to help you guys. (Of course, a little credit wouldn't hurt ;))


-Gan

ha k
Title: Re: My iPhone Game Tutorials for Beginners
Post by: DWapps on March 07, 2010, 11:49:31 AM
Do you know of a graphic design program better than pixen? Pixen is to blocky for what i want to be creating.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: gbaldwin9 on March 21, 2010, 06:26:07 PM


Great tutorials! Just a couple of questions:

How might I go about adding friction so as to slow the ball to a stop?

I'm new to game programming, and would like to essentially make a ball acted like a putted golf ball, or a billiard ball - started by a user swipe and slowing by friction until it reaches a stop.

Can anyone point me in the right direction?
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on March 21, 2010, 07:22:07 PM
3 main variables:
- Ball's position as a CGPoint.
- Ball's velocity as a CGPoint.
- Friction as a float.

If you add velocity to the ball's position every time it'll move the ball. If you make friction as .9 or another decimal below 1 and multiply it to the velocity, it'll eventually slow the ball to a stop.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: gbaldwin9 on March 21, 2010, 09:24:21 PM
Thanks Gandolf!

I tried it like this:

Code: [Select]
- (void) handleGameTimer: (NSTimer *) gameTimer {
//All game logic goes here, this is updated 60 times a second

float slower = .99;

velocity.x = slower * velocity.x;
velocity.y = slower * velocity.y;


position.x += velocity.x;
position.y += velocity.y;


if(position.x <0) {velocity.x = velocity.x;}
if(position.y <0){velocity.y = velocity.y;}
if(position.x >screenDimensions.x-30) {velocity.x = -velocity.x;}
if(position.y >screenDimensions.y-30) {velocity.y = -velocity.y;}



//This updates the screen
[self setNeedsDisplay];
}

But the ball now disappears off the top of the screen. See anything that explains it?

I'm not usually this thick-headed about this stuff, but I've been banging my head against this for a while now...
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on March 21, 2010, 09:38:28 PM
.99 is quite a large number for slowing. Try .5 and go from there.

Besides that your screen bound logic for keeping the ball in view is buggy.
If the ball goes off the screen make the appropriate velocity * -1 to change direction and stick the ball back in the screen by setting the x or y position right inside the view.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: gbaldwin9 on March 21, 2010, 09:49:47 PM
Thanks again.

It's odd, because the ball bounces off the bottom and right walls, but then flies through the top wall. I'm having trouble figuring out why that would happen.

I'll keep at it.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on March 21, 2010, 11:20:17 PM
I'll go toss some working code at you tomorrow when I get on my mac. :)



-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: gbaldwin9 on March 21, 2010, 11:46:36 PM
Thanks Gandolf. I think I solved it.

The problem was related to applying the "friction" before I placed the ball. When i moved the float etc below the rest of the code it worked out.

I still have no idea what was causing the "wall" to disappear though. Although I did discover that if I add something like
Code: [Select]
if(ballVelocity.x < .01) {

ballVelocity.x =0;

}

the right-hand wall disappears, even in a fresh project which works fine otherwise. Strange.

Now to figure out how to start the ball with a swipe and have it move in the direction of the swipe...   ???
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on March 22, 2010, 06:15:30 AM
For an effective wall I'd use:
Code: [Select]
if(position.x < 0) { 
ballVelocity.x *= -1;
position.x =0;
}
That'd fix it. Then you'd just need to apply this code to the different walls too.

For your velocity, that's a good idea.
For gettings the direction and length of the swipe just make a variable of where the finger starts and a variable for when the finger ends. Use touchBegan and touchEnded to make it work. That'll give you a line pointing you in the right direction in which all you need to do is some trig to set the correct velocity. Then using pythagorean's theorem you can get the length of that line.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: gbaldwin9 on March 22, 2010, 09:27:33 AM
Thanks so much! That worked perfectly. And the advice about getting swipe detection and speed was perfect too.

You're the man.

I hope you find the time to do more tutorials. They are the best I have seen.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Silverwind on March 22, 2010, 11:44:42 AM
Does that wall reverse direction or bring it to a stop? How about:

Code: [Select]
ballVelocity.x = -ballVelocity.x;
ballVelocity.x = ballVelocity.x / 2;

To sow it down? Or would that not work?
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on March 22, 2010, 06:37:56 PM
Just reverses and replaces the ball back within the bounds.
Your code for slowing would work but it'd only slow it when it hit a wall. I'm thinking he wanted for it to slowly stop.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Silverwind on March 22, 2010, 06:46:10 PM
Cool. I was thinking of the slowdown caused by the ball's disperse of energy when it hits the wall. I'm not sure 50% is accurate though, it's probably nearer 25%.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: gbaldwin9 on March 22, 2010, 06:49:21 PM
Right i wanted it to slow gradually, all along its path. I used this:

Code: [Select]
float friction = .99;
velocity.x =velocity.x * friction;
velocity.y = velocity.y * friction;

And it worked like a charm. I tried .5, but at 60 fps it was completely stopped nearly instantly.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: vsching on April 07, 2010, 08:28:54 PM
i am new to iphone game developing . Thanks for sharing your tutorials. The descriptions seems like mentioning a problem i wish to solve. Will report once i watch it.

Thanks again and keep it coming :)
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on April 07, 2010, 08:39:08 PM
Can't wait to hear what you think of it. :)


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: breshi on April 08, 2010, 03:48:59 AM
Today I downloaded the tutorials and code. I loved it!! :) :) :) :)
I am one of those people who have trouble reading a book and understanding what it says - I need to get stuck right in and see how other people solve problems. Your code is great and I look forward to pulling it apart, working out what you have done, changing it here and there to see what happens etc etc etc.
Using it I can already make some interesting graphics - all within one day.
Once again thank you!
Title: Re: My iPhone Game Tutorials for Beginners
Post by: DWapps on April 11, 2010, 09:21:32 AM
Hi, could you create a tutorial with buttons and connecting them to sounds? Or one about sounds? It would be very helpful.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on April 11, 2010, 09:24:44 AM
Yeah sure, though it may be later in the week before I'm able to post it.
Next Tutorial:
Real Buttons(Interface Builder), Fake Buttons and Sound.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: DWapps on April 12, 2010, 08:28:28 PM
alright, thank you.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: mcquoidellum on April 14, 2010, 01:13:20 PM
tutorial topic #4, using the accelerometer? Drawing more complex shapes? using Open GLES for 3D graphics? haha that would be cool, not really basic. but..
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on April 14, 2010, 04:35:41 PM
Ooh, accelometer ... That sounds like great tutorial material(especially now that I have a dev license).
As for complex shapes, what kinds?
Now for OpenGl, that'd be much later... No need for it at the moment.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on April 14, 2010, 04:57:30 PM
Anything's possible to draw, you could manipulate individual pixels if wanted.


-Gan
P.S. I think I know a tutorial that goes pretty nicely into complex shapes if you want it...
Title: Re: My iPhone Game Tutorials for Beginners
Post by: breshi on April 17, 2010, 01:30:36 AM
Can you please give an example of your drawString command.
I am trying to display a score and thought I could use this to do so but I'm not sure about the format of options such as "format".
Is this the best way to display a game score?
Thanks
Title: Re: My iPhone Game Tutorials for Beginners
Post by: breshi on April 17, 2010, 03:53:18 AM
Sorry that should have read 'format of options such as "font"'
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on April 17, 2010, 08:00:03 AM
For font put in @"Helvetica".


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on April 17, 2010, 08:22:46 AM
Just to tell you guys, I'm not going to release tutorials for a bit of time... I'm working on something new.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on April 19, 2010, 08:26:04 AM
Just to let you guys know, I've figured out how to use OpenGL ES for 2D games. It's crazy fast and perfect for fast paced games involving lots of moving sprites.
Eventuallly I may make a tutorial for it or just release the template for people to use.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Mike on April 22, 2010, 02:53:06 AM
Gan's dock (at least in the first video) has two SilverCreators :D

I wonder if the SilverCreator runtime could be rewritten in Cocoa to gain speed - except we lose Windows support. I would have to maintain two runtimes. Scratch that I guess.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: breshi on April 29, 2010, 11:44:27 PM
Using your template I have been working on a game and would like to add a High Score screen. To do this I used Interface Builder to create a screen that allows the entry of a textfield - name. How can I switch to this screen from the template? It is easy to create new game screens and switch between them but how do you do it with an IB screen.
The new files I created are HighScoreView.h HighScoreView.m and HighScoreView.xib
I will also need to pass the name back.
Thanks!
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on April 30, 2010, 06:23:18 AM
I haven't ever done something like that before..
I think there's a tutorial about it on icodeblog.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: breshi on May 10, 2010, 11:55:06 PM
i am working through the high score text entry screen using a UIAlertView method, I am having a little bit of a problem with memory release issues but as soon as I work it out will post the code.

In the mean time can you suggest a way within your template to change orientation whilst the game is running?
You hard code it at the start but it would be great, especially considering future use of the iPad, to be able to recognise the moving of the view and to change the layout accordingly ie landscape to portrait and back again.

I know all the screen locations, including edges, will have to become variables but that is not too hard once you know what the layout is.
Thanks
Title: Re: My iPhone Game Tutorials for Beginners
Post by: I-NEED-HELP on June 14, 2010, 07:26:10 PM
I am trying to write a platform game for the iPhone. I wrote a collision testing function that looks like this:

-(BOOL) collision: (CGRect)Rect1 Rect2:(CGRect)Rect2 {
if(Rect1.x > (Rect2.x+Rect2.width) || (Rect1.x+Rect1.width) < Rect2.x){
return FALSE;
}
if(Rect1.x > (Rect2.y+Rect2.height) || (Rect1.y+Rect1.height) < Rect2.y){
return FALSE;
}
return TRUE;
}

It almost works. When I try to build, I get these errors:

'CGRect' has no member named 'x'

'CGRect' has no member named 'y'

What are the coordinate values called? Please help.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gnome on June 14, 2010, 08:50:26 PM
Quote
I am trying to write a platform game for the iPhone. I wrote a collision testing function that looks like this:

-(BOOL) collision: (CGRect)Rect1 Rect2:(CGRect)Rect2 {
if(Rect1.x > (Rect2.x+Rect2.width) || (Rect1.x+Rect1.width) < Rect2.x){
return FALSE;
}
if(Rect1.x > (Rect2.y+Rect2.height) || (Rect1.y+Rect1.height) < Rect2.y){
return FALSE;
}
return TRUE;
}

It almost works. When I try to build, I get these errors:

'CGRect' has no member named 'x'

'CGRect' has no member named 'y'

What are the coordinate values called? Please help.


Sorry mate, Gandolf is out for a 2 weeks.

Wish I could help.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: I-NEED-HELP on June 15, 2010, 05:38:02 PM
Instead of using CGRect, I made it work by passing x, y, width and height as parameters.
I've got collision testing working, I am trying something where the platform on the screen is 'solid', so it stops the player when the player tries to move through it. Here is my code:

if(y+height >= platy) {yVel = -1;}
if(y <= platy+platheight) {yVel = 1;}
if(x+width >= platx) {xVel = -1;}
if(x <= platx+platwidth) {xVel = 1;}

But it doesn't work! On two sides, the rectangle is 'solid'. On the other two, the player moves right through to the other side. Please help!
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on June 18, 2010, 04:20:58 PM
Hmmmm. Could you post a video or source? I'd like to see what happens.

Also for a CGRect you have to use rect.size.x.


-Gan
P.S. I'm back from my incredibly long vacation without technology.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: I-NEED-HELP on June 18, 2010, 07:33:37 PM
I got collision testing working with one rectangle, I want to be able to loop through an array of say, 50 rectangles. I need an array of CGRects, so I need to know what are the CGRect variables (if public) or methods to access the x position, y position, width and height.

I fixed my code, here is the handleGameTimer function:

- (void) handleGameTimer: (NSTimer *) gameTimer {
//All game logic goes here, this is updated 60 times a second

if (touchlocation.x > screenDimensions.x/2) {
inputxVel = 1;
}
if (touchlocation.x < screenDimensions.x/2) {
inputxVel = -1;
}
if (touchlocation.y > screenDimensions.y/2) {
inputyVel = 1;
}
if (touchlocation.y < screenDimensions.y/2) {
inputyVel = -1;
}

xVel = inputxVel;
yVel = inputyVel;

if([self collision:x y1:y w1:width h1:height x2:platx y2:platy w2:platwidth h2: platheight]){

if(y+height >= platy && y < platy+platheight && yVel == 1) {
yVel *= -1;
}
if(y <= platy+platheight && y > platy&& yVel == -1) {
yVel *= -1;
}
if(x+width >= platx && x < platx+platwidth && xVel == 1) {
xVel *= -1;
}
if(x <= platx+platwidth && x > platx && xVel == -1) {
xVel *= -1;
}
}

x += xVel;
y += yVel;
inputxVel = 0; xVel = 0;
inputyVel = 0; yVel = 0;

//This updates the screen
[self setNeedsDisplay];
}

Please help! Thanks in advance.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on June 18, 2010, 08:10:38 PM
You can either (a) Create an array of them by CGRect rectangles[50]; or (b) Create an NSMutableArray to hold the values though the CGRect is not an NS variable and cannot be held in an NSMutableArray.

Once you've made the array just make a for loop that goes through each.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: I-NEED-HELP on June 24, 2010, 11:08:08 AM
Thanks! I got it working.

For your next tutorial, could you show how to make the iPhone interface type buttons (with Interface Builder) and how to load and play sounds?

Thanks for all the help!
Title: Re: My iPhone Game Tutorials for Beginners
Post by: I-NEED-HELP on June 24, 2010, 11:10:12 AM
Oh, and also I looked up the CGRect variable names: there is a CGPoint called origin and a CGPoint called size. You can access them directly like this:

CGRect.origin.x;
CGRect.origin.y;
CGRect.size.width;
CGRect.size.height;
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on June 24, 2010, 11:22:00 AM
Sound and adding buttons are easy. I'll see if I can make a tutorial later though I'm incredibly busy these days.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: I-NEED-HELP on June 24, 2010, 03:05:41 PM
OK. I was wondering - since I am not a paid developer, if you have some sound-playing code and you ran it in the simulator, would your computer's speakers play the sound?

Maybe you should also make a tutorial on how to download the app to an iPhone/iPod Touch for paid developers.

Thanks for all the help!
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on June 24, 2010, 03:11:26 PM
Quote
OK. I was wondering - since I am not a paid developer, if you have some sound-playing code and you ran it in the simulator, would your computer's speakers play the sound?
Yeah.

Quote
Maybe you should also make a tutorial on how to download the app to an iPhone/iPod Touch for paid developers.
With Xcode 4 that's suppose to come out soon it'll be incredibly easy. Literally just plug it in and insert your account details.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: I-NEED-HELP on June 28, 2010, 12:08:22 PM
I was trying to have my app display the value of a variable in the upper-left hand corner of the screen, using your [self drawString] function.

I put this code in the drawRect function:

[self drawString:context translate:CGPointMake(0, 0) text:(NSString*)loopCounter point:CGPointMake(0, 0) rotation:0 font:@"Helvetica" color:color size:12];

However, now the app crashes as soon as it starts and never displays the variable. loopCounter is a global variable, I made it in MyCustomView.h. Can someone please help me with drawString?

EDIT:

loopCounter is an int.

Thanks in advance!
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on June 28, 2010, 12:18:53 PM
Hmm. Try this:
Code: [Select]
NSString* loopCounterTxt = [NSString stringWithFormat:@"%d", loopCounter];
[self drawString:context translate:CGPointMake(0, 0) text:loopCounterTxt point:CGPointMake(0, 0) rotation:0.0 font:@"Helvetica" color:color size:12];
That should do the trick. Another way to turn an int to a string may be: [loopCounter stringValue]; .


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: I-NEED-HELP on June 28, 2010, 01:56:24 PM
Worked perfectly. Thank you so much!
Title: Re: My iPhone Game Tutorials for Beginners
Post by: I-NEED-HELP on June 28, 2010, 02:16:51 PM
Could you show how to read and write files in the iPhone filesystem? I think that is what some of your functions are for. I want to save a highscore file, but I have no idea how. I will have just one number in the file, which is the highscore. In my program, if the score is greater than the highscore in the file, then the score will replace the highscore. How do I do this? Could you make a tutorial on saving highscores?

Thanks in advance.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on June 28, 2010, 02:45:54 PM
Make an NSMutableArray.
Code: [Select]
NSMutableArray* highscore = [NSMutableArray new];
Add your score to the NSMutableArray.
Code: [Select]
[highscore addObject:[NSNumber numberWithInt: 253]];
Then run the save command:
Code: [Select]
[self saveFileInDocs:"Highscore.txt" object:highscore];

That'll save the score 253 in the file "Highscore.txt";

Now to open:
Code: [Select]
NSMutableArray* highscore = [self openFileInDocs:"Highscore.txt"];
int scoreNumber = [[highscore objectAtIndex:0] intValue];

That's how you retrieve and save data.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Silverwind on June 28, 2010, 03:56:27 PM
Oh yeah, I don't think I mentioned it but I finally got around to watching the first of your iPhone tutorials a few weeks back. It's really good Gan. :) I actually understood it without popping a lobe, hehe...
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on June 28, 2010, 06:09:42 PM
Awesome. :) Hopefully soon you'll be making your own great apps.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: breshi on June 28, 2010, 06:29:16 PM
I have an interesting problem.
I have used your fantastic Game making structure as my base and have written what I think is a pretty good game. Everything was perfect until I upgraded to OS4 - now the game runs extremely slow.
I can easily fix this within the code but then when the game runs on earlier OS versions it will run extremely fast.
Has any one else run across this problem?

I would have thought that since all my other games (on my iPhone) run well on all OS versions the problem lies with your base Game Structure. I can do an overall fix and check to see what version of the OS is being used and slow down/speed up the game accordingly but why don't other games not written for OS4 have this problem?
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on June 28, 2010, 06:47:58 PM
It's probably my game structure. I made the structure before os 4 and while I was a beginner.
Currently I use a new structure that's similar to this one. Though it's quite a bit more advanced and uses OpenGL and a reliable thread loop for logic.
If you want I can make my latest one a bit more beginner friendly and post it up. Because it uses OpenGl you can have a ton more objects on screen.
If you don't want to use the new template I have code to get the os number. That way you don't need to change anything.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: breshi on June 28, 2010, 06:54:08 PM
That would be fantastic!
Would it be a hard thing to modify the old structure, i'd hate to have to rewrite my entire game?
Keep up the great work!!!
Title: Re: My iPhone Game Tutorials for Beginners
Post by: I-NEED-HELP on June 28, 2010, 08:10:28 PM
Thanks for your help with opening/saving files!

But what if the app is running for the first time... would you create a new file? But then how would you tell whether the app was running for the first time or not? Or if you could test whether or not the file already exists? How to tell whether or not a file exists?

Thanks in advance.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on June 28, 2010, 09:29:50 PM
Here's the code to detect the current OS:
Code: [Select]
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 4.0) {
//Less then 4.0
} else {
//4.0 or greater
}

To check if your file exists just load it as normal and do this:
Code: [Select]
if (testFile == nil) {
//File doesn't exist
}

I will see about converting it but still pretty busy.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: I-NEED-HELP on June 29, 2010, 11:16:57 AM
I tried with the file stuff for highscores, but when my program gets to the part where it's supposed to check highscores and update the file, it crashes. Any help?

Code: [Select]
            int score = loopCounter;
            if (!gottenScore) {
                  NSMutableArray* highscore = [NSMutableArray new];
                  highscore = [self openFileInDocs:@"Highscore.txt"];
                  if (highscore != nil) {
                        if (score > [[highscore objectAtIndex:0] intValue]) {
                              [highscore replaceObjectAtIndex:0 withObject:[NSNumber numberWithInt:score]];
                              gotHighscore = TRUE;
                        }
                        [self saveFileInDocs:@"Highscore.txt" object:highscore];
                  }
                  else {
                        [highscore addObject:[NSNumber numberWithInt:score]];
                        [self saveFileInDocs:@"Highscore.txt" object:highscore];
                  }
                  gottenScore = TRUE;
                  
                  [self drawString:context translate:CGPointMake(0, 0) text:[NSString stringWithFormat:[highscore objectAtIndex:0]] point:CGPointMake(0, screenDimensions.y-130) rotation:0 font:@"Arial" color:color size:20];
                  if (gotHighscore) {
                        [self drawString:context translate:CGPointMake(0, 0) text:@"HIGHSCORE!" point:CGPointMake(70, screenDimensions.y-80) rotation:0 font:@"Arial" color:color size:20];
                  }
            }
Title: Re: My iPhone Game Tutorials for Beginners
Post by: I-NEED-HELP on July 04, 2010, 08:11:36 PM
I was wondering how to resize a sprite. Your drawing methods seem to leave the sprite dimensions as they were, but I would like to be able to change them, e.g. make a sprite from a file that is 20x20 pixels but show it on the screen as 40x40 pixels. How do you do this?

Thanks in advance.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: I-NEED-HELP on July 09, 2010, 04:32:32 PM
Quote
Do you know of a graphic design program better than pixen? Pixen is to blocky for what i want to be creating.
Sorry this is really late, your question might have already been answered, but I use GIMP. Gnu Image Manipulation Program. It's free, easy to use, and I use it for all my sprites in games. It has tons of awesome tools too, very nice software. You can save as tons of different image formats, even as ASCII art! Try it.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: I-NEED-HELP on July 11, 2010, 09:53:25 PM
How to you use OpenGL to draw 2d sprites? Can you post a tutorial? Or update the iPhone Game Template code so that is uses OpenGL ES instead of CoreGraphics? I'm making a sprite intensive game that requires very fast update speeds.

Thanks in advance.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: breshi on July 11, 2010, 10:46:43 PM
Yes, that would be a great help to find out how to use openGL for sprites. With the update to OS4 I have to rewrite my game to speed it up - not sure how.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on July 14, 2010, 06:40:33 PM
Here's one of my old opengl templates. It has most of what you need to get the job done but it's a mess.
If I had more than 5 minutes I could clean it up.

http://web.mac.com/avisaria/OpenGL%20Template.zip


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: I-NEED-HELP on July 17, 2010, 12:43:50 PM
THANK YOU!  :D :D :D :D :D :D
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on July 21, 2010, 05:28:31 PM
I'm remaking the template. This latest will completely blow all previous templates out of the water.
I'm making it so that you can build all menus in interface builder while having the game view a little separate for maximum speed in an easy to use OpenGl ES view.
This also allows use of professional looking transitions.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: breshi on July 21, 2010, 05:35:57 PM
Gandolf you are a legend!!!!
I can hardly wait.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on July 23, 2010, 01:10:44 AM
Quote
Gandolf you are a legend!!!!
No, not yet at least.

Here's a teaser of the Ultimate iPhone Template running in Xcode 4:
Teaser (http://web.mac.com/avisaria/Ultimate%20iPhone%20Template%20Teaser.m4v)

Highlights:
*All code only needs to be in the App Delegate.
*The menu is made in Interface Builder. Has animations.
*OpenGl drawing.
*iOS 4 multitasking friendly.
*Made of awesome.


-Gan
P.S. Hurray for midnight screencast recording.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Silverwind on July 23, 2010, 06:02:31 AM
Wow, that looks really self explanatory! :o I'll have to get cracking on the rest of your tutorials when I free up some time.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: I-NEED-HELP on July 29, 2010, 09:17:11 PM
YES!!!! I can't wait!

But for now I am using the OpenGL template that Gandolf posted. I was wondering how to make the game so it doesn't automatically rotate when it starts? I want to make a game where you hold the device upright, but I don't know what code to change to make it rotate to an upright position.

Thanks in advance!
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on July 29, 2010, 10:52:44 PM
To make it stay in portrait mode go to the left bar, go to the Resources folder, click the Info.plist file then change the UIInterfaceOrientation to UIInterfaceOrientationPortrait.

Then to make OpenGL draw for portrait mode you...
Replace the drawImage method with this:
Code: [Select]
- (void)drawImage:(Image*)image AtPoint:(CGPoint)point {
[image renderAtPoint:CGPointMake(point.x, 480-point.y - image.imageHeight) centerOfImage:NO];
}

Replace the 3 touches methods with this:
Code: [Select]
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
NSArray* allTouches = [touches allObjects];
NSArray* eventTouches = [[event allTouches] allObjects];

for (int i = 0; i < [eventTouches count]; i +=1) {
if ([eventTouches objectAtIndex:i] == [allTouches objectAtIndex:0]) {
//touchedScreenBegan1 = [[eventTouches objectAtIndex:i] locationInView:self];
//Rotated touch to landscape
CGPoint touch = CGPointMake([[eventTouches objectAtIndex:i] locationInView:self].x,[[eventTouches objectAtIndex:i] locationInView:self].y);
touchedScreenBegan1 = touch;
[self setNeedsDisplay];
}
if ([allTouches count] > 1) {
if ([eventTouches objectAtIndex:i] == [allTouches objectAtIndex:1]) {
//Rotated touch to landscape
CGPoint touch = CGPointMake([[eventTouches objectAtIndex:i] locationInView:self].x,[[eventTouches objectAtIndex:i] locationInView:self].y);
touchedScreenBegan2 = touch;
}
}
}
//CGPoint location = [touch locationInView:self];
// tell the view to redraw
}
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event{
NSArray* allTouches = [touches allObjects];
NSArray* eventTouches = [[event allTouches] allObjects];

for (int i = 0; i < [eventTouches count]; i +=1) {
if ([eventTouches objectAtIndex:i] == [allTouches objectAtIndex:0]) {
//Rotated touch to landscape
CGPoint touch = CGPointMake([[eventTouches objectAtIndex:i] locationInView:self].x,[[eventTouches objectAtIndex:i] locationInView:self].y);
touchedScreenMoved1 = touch;
}
if ([allTouches count] > 1) {
if ([eventTouches objectAtIndex:i] == [allTouches objectAtIndex:1]) {
//Rotated touch to landscape
CGPoint touch = CGPointMake([[eventTouches objectAtIndex:i] locationInView:self].x,[[eventTouches objectAtIndex:i] locationInView:self].y);
touchedScreenMoved2 = touch;
}
}
}
//CGPoint location = [touch locationInView:self];
// tell the view to redraw
}
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
NSArray* allTouches = [touches allObjects];
NSArray* eventTouches = [[event allTouches] allObjects];

for (int i = 0; i < [eventTouches count]; i +=1) {
if ([eventTouches objectAtIndex:i] == [allTouches objectAtIndex:0]) {
//Rotated touch to landscape
CGPoint touch = CGPointMake([[eventTouches objectAtIndex:i] locationInView:self].x,[[eventTouches objectAtIndex:i] locationInView:self].y);
touchedScreenEnded1 = touch;
}
if ([allTouches count] > 1) {
if ([eventTouches objectAtIndex:i] == [allTouches objectAtIndex:1]) {
//Rotated touch to landscape
CGPoint touch = CGPointMake([[eventTouches objectAtIndex:i] locationInView:self].x,[[eventTouches objectAtIndex:i] locationInView:self].y);
touchedScreenEnded2 = touch;
}
}
}
//CGPoint location = [touch locationInView:self];
// tell the view to redraw
}

And finally replace the initWithCoder method with this:
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on July 29, 2010, 10:53:01 PM
Code: [Select]
//The GL view is stored in the nib file. When it's unarchived it's sent -initWithCoder:
- (id)initWithCoder:(NSCoder*)coder {
    
    if ((self = [super initWithCoder:coder])) {
        // Get the layer
        CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
        
        eaglLayer.opaque = YES;
        eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
                                        [NSNumber numberWithBool:NO], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];
        
        context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
        
        if (!context || ![EAGLContext setCurrentContext:context]) {
            [self release];
            return nil;
        }

CGRect rect = [[UIScreen mainScreen] bounds];


// Set up OpenGL projection matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthof( 0, rect.size.width, 0, rect.size.height, -1, 1 );
glMatrixMode(GL_MODELVIEW);
glViewport(0, 0, rect.size.width, rect.size.height);


// Initialize OpenGL states
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_DEPTH_TEST);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND_SRC);
glEnableClientState(GL_VERTEX_ARRAY);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

testSprite = [[Image alloc] initWithImage:[UIImage imageNamed:@"Npc 1.png"]];
movingThings = [NSMutableArray new];
for (int i = 0; i < 300; i ++) {
Sprite* toAdd = [[Sprite new] initWithImage:testSprite position:CGPointMake(rand()%320, rand()%480)];
[movingThings addObject:toAdd];
}


touchedScreen1 = CGPointMake(-1, -1);
touchedScreen2 = CGPointMake(-1, -1);
updateScreen = TRUE;

middleScreen = CGPointMake((177 - 46/2)*2,(160 - 46/2)*2);

gameTimer = [NSTimer scheduledTimerWithTimeInterval:(float)1/60 target:self selector:@selector(mainGameLoop) userInfo:nil repeats:YES];
screenDimensions = CGPointMake([self bounds].size.height, [self bounds].size.width);
}
    return self;
}

Sorry about that, didn't stop to think of differently oriented games.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: I-NEED-HELP on July 29, 2010, 11:10:33 PM
Thank you! Problem solved. Just one thing - in the initWithCoder method, screenDimensions was initialized slightly wrong:

screenDimensions = CGPointMake([self bounds].size.height, [self bounds].size.width);

height and width are mixed up. When I changed it to this, it worked:

screenDimensions = CGPointMake([self bounds].size.width, [self bounds].size.height);

Thanks for all the help! Hope you can release the Ultimate iPhone Game Template soon!
Title: Re: My iPhone Game Tutorials for Beginners
Post by: I-NEED-HELP on August 09, 2010, 06:16:19 PM
Gandolf I was wondering, how does the Ultimate iPhone Template work with iPhone 4 if the iPhone 4 screen is 940x640(I think)? Does it scale everything, or leave black spots on the screen?

Please release it soon! Or at least a beta version!!
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on August 09, 2010, 07:49:06 PM
Works like normal though if you display uiimages it just shows them in a higher definition.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on August 10, 2010, 01:06:29 PM
Here's a beta:
Ultimate iPhone Template Beta (http://web.mac.com/avisaria/Ultimate%20iPhone%20Template%20Beta.zip)

Should work perfectly. You design the menu in Interface Builder, all main code goes in the app delegate, supports multitasking, and it's compatible with iOS 3.1+. It's also fast, very fast.


-Gandolf
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gnome on August 10, 2010, 01:53:39 PM
I have posted for the first time in a month to say:

[glb][size=18]YAY!!!??!!!111!!!one!!1[/size][/glb]
Title: Re: My iPhone Game Tutorials for Beginners
Post by: I-NEED-HELP on August 10, 2010, 05:13:10 PM
Thank you! It is AWESOME!!!!!!
Title: Re: My iPhone Game Tutorials for Beginners
Post by: I-NEED-HELP on August 10, 2010, 05:52:03 PM
Thank you. I was wondering how, for the Ultimate iPhone Template, to make it rotate so that it is upright? Also, I noticed that when you ran the game, if you clicked the "play" button it would run fine, but then I made a button to go back to the main menu, and if you pressed this and then clicked "play" again the screen would be rotated strangely. I changed the code in the beginning of GameView.m to this and it seemed to fix the problem:

#import <QuartzCore/QuartzCore.h>
#import <OpenGLES/EAGLDrawable.h>

#import "GameView.h"
#import "AppDelegate.h"

#define USE_DEPTH_BUFFER 0


@implementation GameView

@synthesize context;


//The GL view is stored in the nib file. When it's unarchived it's sent -initWithCoder:
- (id)initWithCoder:(NSCoder*)coder {
    
    if ((self = [super initWithCoder:coder])) {
        // Get the layer
        CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
        
        eaglLayer.opaque = YES;
        eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
                                        [NSNumber numberWithBool:NO], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];
        
        context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
        
        if (!context || ![EAGLContext setCurrentContext:context]) {
            [self release];
            return nil;
        }
            
            //CGRect rect = [[UIScreen mainScreen] bounds];
            
                  
            // Set up OpenGL projection matrix
            glMatrixMode(GL_PROJECTION);
            glLoadIdentity();
            glOrthof(0, 480, 0, 320, -1, 1);
            glViewport(0, 0, 480, 320);
            //glTranslatef(-100, -320/2, 0.0f );
            glMatrixMode(GL_MODELVIEW);
            //glTranslatef(-0, -240.0f, 0.0f );
            //glRotatef(180.0f, 0.0f, 0.0f, 1.0f);
            //glScalef(-1.0, 1.0, 1.0);
            
            
            // Initialize OpenGL states
            //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
            glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
            glDisable(GL_DEPTH_TEST);
            glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND_SRC);
            glEnableClientState(GL_VERTEX_ARRAY);
            glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
            
            
            screenDimensions = CGPointMake([self bounds].size.width, [self bounds].size.height);
            //[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
            rotationNeg = CGPointMake(1, -1);
            rotationOffset = CGPointMake(0, 320);
            glRotatef(-90.0, 0.0f, 0.0f, 1.0f);
            glTranslatef(-480.0, 0.0, 0.0f );
            //[self setTransform:CGAffineTransformMakeRotation(M_PI/2)];
            [self setFrame:CGRectMake(0, 0, 320, 480)];
            //[gameView setCenter:CGPointMake(320/4, 320/2)];
            // Set up OpenGL projection matrix
            glMatrixMode(GL_PROJECTION);
            glLoadIdentity();
            glOrthof(0, 320, 0, 480, -1, 1);
            glViewport(0, 0, 320, 480);
            //glTranslatef(-100, -320/2, 0.0f );
            glMatrixMode(GL_MODELVIEW);
            //glTranslatef(-0, -240.0f, 0.0f );
            //glRotatef(180.0f, 0.0f, 0.0f, 1.0f);
            //glScalef(-1.0, 1.0, 1.0);
            
            
            // Initialize OpenGL states
            //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
            glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
            glDisable(GL_DEPTH_TEST);
            glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND_SRC);
            glEnableClientState(GL_VERTEX_ARRAY);
            glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
            //[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
      
      }
    return self;
      
}


- (void)renderScene {
// Make sure we are renderin to the frame buffer
[EAGLContext setCurrentContext:context];
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);

// Clear the color buffer with the glClearColor which has been set
glClear(GL_COLOR_BUFFER_BIT);

AppDelegate* delegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];

// Save the current matrix to the stack
glPushMatrix();

// Set client states so that the Texture Coordinate Array will be used during rendering
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

// Enable Texture_2D
glEnable(GL_TEXTURE_2D);

// Enable blending as we want the transparent parts of the image to be transparent
glEnable(GL_BLEND);

[delegate drawGame];

// Now we are done drawing disable blending
glDisable(GL_BLEND);

// Disable as necessary
glDisable(GL_TEXTURE_2D);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);

// Restore the saved matrix from the stack
glPopMatrix();

// Switch the render buffer and framebuffer so our scene is displayed on the screen
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];

}
Title: Re: My iPhone Game Tutorials for Beginners
Post by: I-NEED-HELP on August 10, 2010, 05:52:15 PM
- (void)setOrientation:(UIInterfaceOrientation)interfaceOrientation {
/* if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
rotationNeg = CGPointMake(-1, 1);
rotationOffset = CGPointMake(480, 0);
glRotatef(90.0, 0.0f, 0.0f, 1.0f);
glTranslatef(0, -320.0, 0.0f );
//[self setTransform:CGAffineTransformMakeRotation(-M_PI/2)];
[self setFrame:CGRectMake(0, 0, 320, 480)];
//[gameView setCenter:CGPointMake(320/4, 320/2)];
// Set up OpenGL projection matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthof(0, 320, 0, 480, -1, 1);
glViewport(0, 0, 320, 480);
//glTranslatef(-100, -320/2, 0.0f );
glMatrixMode(GL_MODELVIEW);
//glTranslatef(-0, -240.0f, 0.0f );
//glRotatef(180.0f, 0.0f, 0.0f, 1.0f);
//glScalef(-1.0, 1.0, 1.0);


// Initialize OpenGL states
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_DEPTH_TEST);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND_SRC);
glEnableClientState(GL_VERTEX_ARRAY);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
//[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO];
}
if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
rotationNeg = CGPointMake(1, -1);
rotationOffset = CGPointMake(0, 320);
glRotatef(-90.0, 0.0f, 0.0f, 1.0f);
glTranslatef(-480.0, 0.0, 0.0f );
//[self setTransform:CGAffineTransformMakeRotation(M_PI/2)];
[self setFrame:CGRectMake(0, 0, 320, 480)];
//[gameView setCenter:CGPointMake(320/4, 320/2)];
// Set up OpenGL projection matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthof(0, 320, 0, 480, -1, 1);
glViewport(0, 0, 320, 480);
//glTranslatef(-100, -320/2, 0.0f );
glMatrixMode(GL_MODELVIEW);
//glTranslatef(-0, -240.0f, 0.0f );
//glRotatef(180.0f, 0.0f, 0.0f, 1.0f);
//glScalef(-1.0, 1.0, 1.0);


// Initialize OpenGL states
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_DEPTH_TEST);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND_SRC);
glEnableClientState(GL_VERTEX_ARRAY);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
//[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
} */
}
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on August 10, 2010, 06:27:32 PM
Sorry, I tend to forget people use portrait mode for games...
Ultimate iPhone Template Beta - Portrait (http://web.mac.com/avisaria/Ultimate%20iPhone%20Template%20Beta%20Portrait.zip)


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: I-NEED-HELP on August 11, 2010, 04:36:18 PM
Thank you!!!!! In the credits of my game who should I put you as?
Gandolf from the GMG forums?
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on August 11, 2010, 05:07:34 PM
Gandolf or Matthew French. Either would be fine.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: I-NEED-HELP on August 11, 2010, 10:50:49 PM
Also, I was trying to figure out how to play music in games. Before, I just added the AVFoundation.framework file, #imported the header into the project, and then used this bit of code in awakeFromNib to load, play, and keep looping the music:

NSString* pathToMusicFile = [[NSBundle mainBundle] pathForResource:@"MusicFile" ofType:@"mp3"];
AVAudioPlayer* music = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:pathToMusicFile] error:NULL];
music.numberOfLoops = -1;
music.volume = 1;
[music play];

But every time I try this in the Ultimate iPhone Template, I get an error whether I compile for the simulator or for a device. Any help is much appreciated! Thanks.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: I-NEED-HELP on August 12, 2010, 10:51:37 PM
Ah, I managed to get that working by dragging/dropping the AVFoundation framework from a different project into the frameworks folder of the Ultimate iPhone Template. But now I need help with figuring out how to draw text in the UIT... I tried copying over the files from the OpenGL template for Texture2D.h/.m, but it still wouldn't let me draw text - it wouldn't give an error, it just wouldn't draw the text. Any help is much appreciated.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on August 12, 2010, 11:20:24 PM
Yeah text drawing is incomplete in the template. Later I'll update it and stick it up.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: I-NEED-HELP on August 12, 2010, 11:29:56 PM
How long do you think that will take? Thank you for all the awesome work you've done on the template though. Me and a friend are making a game now, and without the template we would be stuck with buttons and switches and labels and static UIImages. Thanks man!
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on August 12, 2010, 11:57:26 PM
Glad you like it. I'll stick up the update sometime tomorrow.
Drawing text is a bit different in OpenGl than what you're use to. You'll find out later.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on August 13, 2010, 04:50:12 PM
http://web.mac.com/avisaria/Ultimate%20iPhone%20Template%20Portrait.zip

If you need to customize text color, size, or font just ask.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: I-NEED-HELP on August 13, 2010, 05:27:02 PM
Thank you!

Is it possible to have game logic and have the AppDelegate doing stuff when the game is in its menu? I want to have menu music and then different music for in-game. How do you think I should do this? BTW the music is longer than 30 seconds.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on August 13, 2010, 06:11:05 PM
For having game logic running during the menu just move around the initializeTimer and pauseTimer commands until it suits your needs.
The code you have for music will work fine for main menu music. Just tell it to play when entering the main menu.

Sorry for the vague answers. Power's out and on iPhone.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: I-NEED-HELP on August 13, 2010, 06:16:49 PM
Ah. I see. That makes sense, thank you! (haha I'm on my iPod Touch)
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Silverwind on August 13, 2010, 06:43:27 PM
Hehehe... good old Gan.

Teaching the world how to program, one forum member at a time! ;D
Title: Re: My iPhone Game Tutorials for Beginners
Post by: I-NEED-HELP on August 14, 2010, 10:10:23 AM
Is it possible to use custom fonts, or must you use the default fonts pre-installed on the iPhone?
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on August 14, 2010, 10:28:05 AM
There's only a limited number of fonts on the iPhone. To change the font go to the GameView class, search Georgia and replace it with your font name. The default size is 15, you can change that as well.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: breshi on August 18, 2010, 01:23:56 AM
"Teaching the world how to program, one forum member at a time!"
- My turn!

I am trying  to understand the logic of your new template and work out why there is code in AppDelegate and GameView for ball collisions. What type of coding goes in each, in your last template all I really had to do was modify the AppDelegate.

Also in the xib the color is set to white but the background is black. I could eventually figure out where you set this but thought I would be lazy and ask the question.
Thanks!!
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on August 18, 2010, 06:53:52 AM
You pretty much only have to worry about the AppDelegate. In the app delegate is the logic and drawing code for the game. In the gameview I put the circle collision code to declutter the app delegate a little.
As for the black background on the OpenGL view, that's the clear color. To change it just look around for glclear and some sort of function for setting the clear color in the gameview. Sorry for being vague. Not at my computer now.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: I-NEED-HELP on August 20, 2010, 05:26:47 PM
I want to have my game so that you can control movement of the player by tilting the device, however when I used your accelerometer code nothing happens. Is there something I am missing? At the top of AppDelegate.m I have
#define kAccelerometerFrequency        10 //Hz
In the middle of the file, right before gameLogic, I have
- (void) configureAccelerometer {
UIAccelerometer* theAccelerometer = [UIAccelerometer sharedAccelerometer];

if (theAccelerometer) {
theAccelerometer.updateInterval = 1 / kAccelerometerFrequency;
theAccelerometer.delegate = self;
}
else {
NSLog(@"Oops we're not running on the device!");
}
}

- (void) accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
UIAccelerationValue x, y, z;
x = acceleration.x;
y = acceleration.y;
z = acceleration.z;

NSLog(@"X:%f Y:%f Z:%f", x, y, z);

// Do something with the values.
//xField.text = [NSString stringWithFormat:@"%.5f", x];
//yField.text = [NSString stringWithFormat:@"%.5f", y];
//zField.text = [NSString stringWithFormat:@"%.5f", z];
}

I tried my code on a device with the console window open, and it didn't do anything. My device is a second gen iPod Touch. Any help is much appreciated!
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on August 20, 2010, 06:17:01 PM
In your application load method you gotta configure the accelerometer:
Code: [Select]
[self configureAccelerometer];


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: I-NEED-HELP on August 20, 2010, 06:35:14 PM
Oh! Thanks, I overlooked that. Now my game works! Awesome! Thanks!
Title: Re: My iPhone Game Tutorials for Beginners
Post by: I-NEED-HELP on September 15, 2010, 07:56:54 PM
For about... I think 2 years now, I've been trying to get a working platform physics engine working. I've been persistently Googling "platform game tutorial" and I have almost memorized the results by heart.

FINALLY, I just made a successful platform game engine! Yes!! Just wanted to say that.

Basically, I made it work by doing something like this:

player.origin.x += xVel; //temporarily move player
for (int i = 0; i < NUM_OF_PLATS; i++) {
if ([self collision:player rect2:rects]) { //if there is a //platform collision
player.origin.x -= xVel; //backtrack movement
if (xVel > 0) {
NSLog(@"Something on my right OMG!");
}
if (xVel < 0) {
NSLog(@"Something on my left OMG!");
}
}
}
player.origin.y += yVel; //temporarily move player
for (int i = 0; i < NUM_OF_PLATS; i++) {
if ([self collision:player rect2:rects]) { //check for collision
player.origin.y -= yVel; //move player back
if (yVel < 0) {
yVel *= -1; // if we were moving up and we hit a //platform, reverse vertical direction and stop jumping, start falling.
jumping = FALSE;
}
if (yVel > 0) { //if we were moving down and we hit a //platform, then now we can jump.
can_jump = TRUE;
}
}
}
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on September 15, 2010, 08:24:56 PM
Good job. :) You should've asked here, we probably could've given you loads of working code.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: I-NEED-HELP on November 12, 2010, 08:00:53 PM
Wow, old post.

Me and a friend are almost finished with a game for iPhone, using your Ultimate iPhone Template. Well, when I say almost I mean it might take a few more months... :)

So, I wanted to have a player sprite rotate, and I know I can do this with Core Graphics, but how do you do it using your OpenGL code? I tried adding a method in Image.m that accepts an int argument and sets the variable "rotation" to that argument, but this didn't alter the image at all when drawn.

Could you add a rotation method in Image.h and add that to the template?

Thanks!
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on November 12, 2010, 08:08:16 PM
Wow this is old.

I've learned tons since I made the tutorials. Here's my advice:

Skip OpenGl too complicated, scrap my tutorials. They're crap.

If you want speeding graphics that are low LoC count and simple then look into CALayers. CALayers are heavenly. Apple made them, and they are amazing. CALayers are like Sc's sprites.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Xiphos on November 21, 2010, 07:07:01 AM
Is there an equivalent of SC's random? Or a way to replicate it.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on November 21, 2010, 09:01:16 AM
srand(time(NULL));
Put that when you first start the app. It seeds the random generator.

int num = rand%5;
This gets a number from 0 to 4.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: I-NEED-HELP on November 21, 2010, 12:28:15 PM
What about arc4random()? With arc4random() I don't think you have to seed anything. It's just arc4random()%5 to get a number between 0-5.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on November 21, 2010, 01:34:02 PM
That should work as well. Though remember to seed the random generator. That is, if you want truly random results.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Xiphos on November 21, 2010, 05:33:30 PM
srand(time(NULL));
okay so i put that to seed the random generator when the app starts.

arc4random()%(x)
giving me a random number between 0 and (x)
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on November 21, 2010, 06:41:00 PM
Yeah, that should be right.


-Gan
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on March 08, 2011, 04:19:11 PM
Quote
-Gandolf
P.S. Do you guys need directions to get and install Xcode and the iPhone SDK?

I need directions on how to find Xcode (sorry if this was already said I read through all of the pages pretty fast)
And as my name tag says 'Sorry for being such a noob'
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on March 08, 2011, 06:25:24 PM
developer.apple.com

Make a free account, go to the iOS section and download the latest SDK with Xcode.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on March 29, 2011, 05:02:31 PM
When I started to make an account the agreement said that checking the box would be saying that i'm 18 or above. should I just get my dad to make one? Also you said it was free, but it looks like most of the programs are $100 a year. I'm confused is it free or not? ???

EDIT: Also what is a Safari plug-in. It says that developer tools for these are free. What are they?
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on March 29, 2011, 05:38:48 PM
When you make an account, if you're worried get someone over 18 to check the little check box. Though don't buy any packages, making the account is free. From there you can download Xcode 3.2 for free. Xcode 4 costs $5 I think. The safari dev tools are for making safari stuff. No need to have them.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on March 29, 2011, 05:41:01 PM
when making the account it asked me which software package I wanted (or something along those lines) It had iOS OS and safari plug-ins (again, something like that I don't remember)
which one do I select, and does it make me buy that?
EDIT: never mind. I thought I'd just blaze ahead, and not worry about the 18 or older thing. I answered my own question
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on March 29, 2011, 07:22:16 PM
Is buying Xcode 4 worth the money, or should I just stick with the free Xcode 3 (Xcode 3 makes applications for iPhone too right?) Also why would you want to sign up for the $100 a year thing, when you could just buy Xcode 4 for $5?
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on March 29, 2011, 11:02:11 PM
The $100 a year plan allows you to install apps you make on your iPhone as well as giving you access to a programming forum and top secret new confidential builds of iOS.

Xcode 3 is good enough. Xcode 4 has a lot of new stuff but it's a little unstable at the moment. Crashes like twice day for me.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on April 26, 2011, 05:05:50 PM
Hey Gan I can't seem to see tutorial 1. It says it can't find the URL.
Oh and P.S.  Thanks for all the help you gave me for finding Xcode.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on April 26, 2011, 06:28:09 PM
It seems the video has been erased and is gone forever...
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on April 26, 2011, 07:01:57 PM
thanks for checking, also do you know of a guide for object-C that lists all (or most) of the commands?
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on April 26, 2011, 07:17:00 PM
http://developer.apple.com/library/ios/navigation/index.html

It's a maze, but if you figure it out you can make amazing things.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: I-NEED-HELP on April 26, 2011, 09:58:51 PM
Yay! I've made two games with your template, and now both are on the app store for $0.99!

http://itunes.apple.com/us/app/schnauzer/id430678453?mt=8&ls=1

http://itunes.apple.com/us/app/black-white/id417477779?mt=8&ls=1
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on April 26, 2011, 10:06:48 PM
Wow!  :D Color me impressed.

Those look like some top notch games. This is really exciting, I had no idea my tutorials would help that much. ;D
You know what? I'm motivated again to work on my super secret chocolate covered project.

Keep up the game making! I know a 17 year old guy making more money off iPhone apps than a teacher.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: I-NEED-HELP on April 26, 2011, 11:21:02 PM
 :D Thanks!
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on April 27, 2011, 02:57:22 PM
I can't seem to download the iPhone game template. The computer keeps saying that it can't find the URL >:(
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on April 27, 2011, 03:14:14 PM
a lot of the cases (at least that's what I think they are) start with NS or CG what do they stand for. And what is the importance of the semi-colon. You seem to write them a lot. And what does the star (*) actually do. And what is the difference between strong typing, and weak typing? ???
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on April 27, 2011, 04:59:08 PM
Quote
I can't seem to download the iPhone game template. The computer keeps saying that it can't find the URL
Yeah, some of the links are dead but hey:
I still got the ultimate iPhone OpenGL game template! (http://cl.ly/28203S3g262K3i0x2j3b)

Quote
a lot of the cases (at least that's what I think they are) start with NS or CG what do they stand for
NS stands for NextStep. It's just what the API was built from.
CG stands for CoreGraphics. It's a powerful framework for drawing.

Quote
And what is the importance of the semi-colon.
Semi-colons separate commands.
int x = 1; int y = 1;
Meaning you can put multiple things on the same line if you wanted. You must have a semi-colon after every command or you will get an error.

Quote
And what does the star (*) actually do.
The star means that variable is a pointer to a piece of memory. You use it on objects.
NSString* myString = @"This is a string";
You don't need to use it on:
int test = 5;

Pointers(*) come in handy when you want to pass objects through functions and use them elsewhere.
This is really hard to understand until you actually use it.

Quote
And what is the difference between strong typing, and weak typing?
This article can explain better than I can:
http://en.wikipedia.org/wiki/Strong_typing


It appears that a few of the iPhone tutorial links still work.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on April 27, 2011, 05:25:39 PM
also how do the brackets [] and the other brackets {} differ.
And what is the name of the language that Xcode uses?
EDIT: Also what are all of the cases, and what they do?
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on April 27, 2011, 05:32:21 PM
Quote
And what is the name of the language that Xcode uses?
Xcode actually can use many languages. Java, C, C++, ect. But what you'll be using is called Objective C.

Quote
also how do the brackets [] and the other brackets {} differ.
[] are used for arrays and commands.
Example array:
int test[5];
test[0] = 33;

Example command:
NSString* myString = @"BWAHAAHAHA";
myString = [myString lowercaseString];

{} are used to put code in. For example:
if (test == 5) {
     test += 1;
     [self doSomeRandomCommand];
}
It's just organizing the code so the compiler knows what goes where.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: x on April 27, 2011, 06:57:31 PM
Quote
Xcode actually can use many languages. Java, C, C++, ect. But what you'll be using is called Objective C.

[] are used for arrays and commands.
Example array:
int test[5];
test[0] = 33;

Example command:
NSString* myString = @"BWAHAAHAHA";
myString = [myString lowercaseString];

{} are used to put code in. For example:
if (test == 5) {
     test += 1;
     [self doSomeRandomCommand];
}
It's just organizing the code so the compiler knows what goes where.

Actually {} in Objective-C can also represent scope. Same as in Java and C++ (and C).
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on April 27, 2011, 08:54:32 PM
what do commands like += do, and is <> still a valid command, or can I use the regular inequal symbol?
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on April 27, 2011, 08:58:32 PM
test += 1
is the same as
test = test + 1

<> isn't a valid command. Instead use !=
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on April 27, 2011, 09:02:06 PM
and how do I find out about cases? Like what are all the different types, and what do they do?
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on April 27, 2011, 09:04:35 PM
when, and why would you use strong typing over weak typing, and vice versa
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on April 27, 2011, 09:05:46 PM
Quote

Actually {} in Objective-C can also represent scope. Same as in Java and C++ (and C).
what do you mean by scope?
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on April 27, 2011, 09:06:56 PM
Quote
Xcode actually can use many languages. Java, C, C++, ect. But what you'll be using is called Objective C.

[] are used for arrays and commands.
Example array:
int test[5];
test[0] = 33;

Example command:
NSString* myString = @"BWAHAAHAHA";
myString = [myString lowercaseString];

{} are used to put code in. For example:
if (test == 5) {
     test += 1;
     [self doSomeRandomCommand];
}
It's just organizing the code so the compiler knows what goes where.

what does the @ sign do?
And why would you put == instead of =
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on April 27, 2011, 09:09:39 PM
The @ tells the compiler that you're making an NSString. So @"this is a test" is an NSString you made. So you can do:
NSString* test = @"This is a test";

== means = but when comparing two objects you must use ==. So
if (1 == 1) {
     NSLog(@"Yay");
}

NSLog just prints out a message to the debugger.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on April 27, 2011, 09:14:07 PM
it seems that
test[0] = 33;
is comparing two objects. Why doesn't it have the two equal signs, and does NSString just make a string variable?
Also where do you find all the cases, and what they do. It seems like you just pull them out of thin air :-/
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on April 27, 2011, 09:31:45 PM
test[0] = 33;
That's setting a number to the index of 0 in an array.
If you want to compare two things you must use ==.

NSString is a type of string variable.

What do you mean by cases?
Title: Re: My iPhone Game Tutorials for Beginners
Post by: x on April 27, 2011, 10:25:24 PM
Scope is your programming locality.

for example take this piece of pseudocode:
int x = 10;
{
    int x = 20;
    output x;
}
output x;

Will print out:
20
10.

You can use {} to create a new scope.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on April 27, 2011, 10:48:03 PM
Ah yeah, X is right. Obj-C isn't like Sc where all variables are global. You gotta make sure the variable you want is made within scope.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on April 28, 2011, 06:01:35 PM
oh I get it thats a lot easier to understand than what's in the manuals on the site. :D
And I made the Hello world application, and that was super helpful.
Thanks for humoring all my questions about Object-C ;D
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on April 28, 2011, 06:31:43 PM
what is the difference between the files that end in .m and .h
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on April 28, 2011, 06:34:22 PM
Also when you create an iPhone project it gives a lot of different types of templates. What is the most basic one to start with, and what can you do with it?
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on April 28, 2011, 07:22:21 PM
where can I find frameworks. (namely UIKit) I'm actually not quite sure what it is in the first place, I only know that you need it or another framework to make a game. So I don't know where to start looking :-[
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on April 28, 2011, 11:34:13 PM
Quote
what is the difference between the files that end in .m and .h
.h is where you declare variables and functions you want to use in your code. Ex:
int myTestNumber;

Then in .m you'd put code like:
-(void)init {
    myTestNumber = 1;
}

Quote
Also when you create an iPhone project it gives a lot of different types of templates. What is the most basic one to start with, and what can you do with it?
That's a toughie, depends on the app. If you want to make a game, either a plain UIView, OpenGl or navigation controller template. For a utility app you might want to use the tabbar template.

Quote
where can I find frameworks. (namely UIKit) I'm actually not quite sure what it is in the first place, I only know that you need it or another framework to make a game. So I don't know where to start looking
The UIKit framework should already be attached. To see all frameworks, open the Framework folder in the left bar.

Hmm. I should scrap all my tutorials and make new ones. Cause I've learned a ton and can make them much simpler.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: I-NEED-HELP on April 28, 2011, 11:41:24 PM
Maybe I could add to your template. I added rotation to the OpenGL files and a function to draw rotated images. Also added a Player.h and Player.mm class (Yes, I use Objective-C++). This class has some basic stuff, like score, position, bounding box, image... maybe I will polish/post my version of the template sometime.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on April 29, 2011, 06:13:01 PM
UIKit isn't in the frameworks folder under Mac OS X and it isn't under Library under iOS either. I found the cases for UIKit. Would it be a good framework for an iPhone game, and does it have motion control detectors, or do I have to find another framework?
Again thanks for the patience starting on things like this always give me the most trouble. :)
EDIT: oh now I'm super duper confused. I found it in the iPhone simulator ??? and I don't understand what I'm supposed to do to be able to use it for your own applications
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/System/Library/Frameworks
oh my head :(
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on April 29, 2011, 07:04:14 PM
You're trying much too hard.

You don't need to physically find the UIKit framework. When you make a new project it should already be connected. If you want to connect frameworks to your project, just go to your target settings, link with libraries, hit the plus button, add the framework.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on April 30, 2011, 09:52:41 AM
ooooohhhhhhhh ::) I see now. Thanks! Just two more questions about frameworks
what do they do? are they where the cases are located,
and what do you do with files whose names appear in red?
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on April 30, 2011, 12:42:08 PM
Frameworks provide useful functions to do stuff.

For example the UIKit framework gives you all the neat UI classes. Like UIImage. Where you can load an image as easy as: UIImage* myImage = [UIImage imageNamed:@"My Image.png"];

I have no idea what you mean by cases.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on April 30, 2011, 02:52:20 PM
I thought cases were the functions like you just gave as an example
Quote
UIImage* myImage = [UIImage imageNamed:@"My Image.png"];
The second time I said cases I meant to say files (just edited the post) I can explain it better with a screen shot:
http://www.mediafire.com/?pwrmqpm91xxw8qv
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on April 30, 2011, 03:21:01 PM
It means your missing those frameworks. Hm. Your SDK appears connected, what're the bugs when you hit Build & Run?
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on May 01, 2011, 04:34:28 PM
weird... it work perfectly. I checked all the processes it can do, and everything works. Here's the folder
http://www.mediafire.com/download.php?j2a853ff3ccjhbc
it's something for a tutorial on recognizing touches, and the like.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on May 01, 2011, 07:12:12 PM
Well if it works there's no problem! ;)
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on May 01, 2011, 08:32:44 PM
is it easy to make an app like Discover? it's an app that turns your iPod into a flash drive, and lets you read PDF's. The only problem is that the PDF reader is horrible, and I thought I might try my hand at remaking, and improving it.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on May 01, 2011, 08:54:09 PM
in the 'other languages and tools' section of the forums I found the post 'Cocca (objective-C)' I looked through it and found the link you put there for 'Become An Xcoder' and it was extremely helpful.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on May 01, 2011, 09:07:23 PM
Yeah it is. :) That's the one that really pushed me into serious Obj-C programming.

Literally read the whole thing.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on May 01, 2011, 09:16:15 PM
Code: [Select]
int x = 5, y = 12, ratio; ratio =y / x;
it said that ratio would be 2 instead of 2.4 does the compiler estimate, or does it just plain drop the factions? Also can a block of code like this exist? Also I thought variables had to be predefined in .h files and executed in .m files?
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on May 02, 2011, 09:07:55 AM
Integers are whole numbers. If you set an integer to a fraction of a number, it rounds to the nearest whole number.
Yes you can have clumped stuff like that.

Variables that you want to use anywhere in the .m file must be declared in the .h. Though you can declare local variables in the .m file. They just won't be global.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on May 02, 2011, 02:48:26 PM
OOHHH that makes total sense. Thanks. What do you do to get a random number picker. I'm trying to make a dice roller to get acquainted with code Object-C from 'scratch'
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on May 02, 2011, 02:56:54 PM
Loading
Code: [Select]
/* initialize random seed: */
  srand ( time(NULL) );
Anywhere Else
Code: [Select]
//Get a random number, can be 0,1,2,3 or 4
int randomNumber = rand()%5;
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on May 02, 2011, 03:03:56 PM
what does the line
Code: [Select]
 srand ( time(NULL) ) ;
what does that do? The individual parts. The way I've learn things is taking them apart from the inside. Is time(NULL) a main() function. Also what happens to the variables inside the parenthesis, ie. NULL
And how do you program an IF THEN statement.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on May 02, 2011, 03:13:17 PM
Also what coding languages can you use in Object-C and howdy you incorporate them into your game. And how do you see the internal structures of main() function        thingys
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on May 02, 2011, 03:27:49 PM
also what the heck does void mean?
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on May 02, 2011, 03:58:13 PM
Quote
what does that do? The individual parts. The way I've learn things is taking them apart from the inside. Is time(NULL) a main() function. Also what happens to the variables inside the parenthesis, ie. NULL  
time() is a C function. time(null) gets the number of seconds since Jan 1 1970.
NULL means nothing. So you give the function nothing.

Quote
And how do you program an IF THEN statement.
Code: [Select]
int test = (rand()%2)+1;
if (test == 1) {
    //Do Stuff
} else if (test == 2) {
    //Do Stuff
}

Quote
Also what coding languages can you use in Object-C and howdy you incorporate them into your game. And how do you see the internal structures of main() function   thingys
You can use C and C++ with Objective-C. To find functions, either Google or search the Xcode documentation.

Quote
also what the heck does void mean?
Void means that the function returns nothing.
Code: [Select]
- (void)stuff {
   //stuff
}
- (void)awakeFromNib {
    [self stuff];
}
If you want the function to return something you can do:
Code: [Select]
- (int)stuff {
   //stuff
   return 5;
}
- (void)awakeFromNib {
    int testNum = [self stuff];
}
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on May 02, 2011, 04:33:18 PM
I get it, cool. While reading how to become an Xcoder (I'm on chapter 8 ) It sounds like you have to keep gaining different functions to create programs. Where would be the best place to find a list of all the really useful & most commonly used functions for Beginner, intermediate, and Experience Xcoders.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on May 02, 2011, 04:39:21 PM
Also what the heck is a argument. The document keeps referring to it, and I'm not quite sure what it is.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on May 02, 2011, 05:07:20 PM
Quote
I get it, cool. While reading how to become an Xcoder (I'm on chapter 8 ) It sounds like you have to keep gaining different functions to create programs. Where would be the best place to find a list of all the really useful & most commonly used functions for Beginner, intermediate, and Experience Xcoders.
never mind I just read the part on documentation, and found most of what I was looking for.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on May 02, 2011, 05:23:52 PM
Quote
Also what the heck is a argument. The document keeps referring to it, and I'm not quite sure what it is.
The argument is the variable you're putting in the function.

Code: [Select]
int myVar = 5;
[self doStuff: myVar];
myVar is the argument cause you're putting it in a function so the function can use it.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: breshi on May 02, 2011, 08:47:10 PM
 ???
I also have written what I think is a great game using your template. I was all set to release it but then the new operating system came out and slowed it right down so it is now unplayable.
I've reduce the loop time but still it is way too slow.
Any suggestions?
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Connors on May 02, 2011, 10:59:17 PM
@breshi: Hey, it's cool to see new faces here!

@Gan: I think you're becoming famous. I don't believe everyone that has used that used that template has posted here yet... ;)
Title: Re: My iPhone Game Tutorials for Beginners
Post by: breshi on May 02, 2011, 11:09:23 PM
Thanks!
I loved the template, it enabled me to jump right in and produce a game I've been thinking of for a while.
All I need to do is fix this speed issue and you will see it submitted to iTunes.
I'm positive the problem relates to the way the graphics are rendered and am hoping we can just change that section of my code as the program is now very big - I would hate to have to rewrite the whole thing.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on May 03, 2011, 07:03:57 AM
Quote
???
I also have written what I think is a great game using your template. I was all set to release it but then the new operating system came out and slowed it right down so it is now unplayable.
I've reduce the loop time but still it is way too slow.
Any suggestions?
Can you pm me the code? I'll do some tests.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on May 03, 2011, 09:44:20 PM
how good is the built in manuel: 'Developer Documentation' that is built into Xcode. I tried the manuel for Terminal, but apparently that manuel expects you already know the command, and are native to the language, so I was wondering how Beginner friendly the built in "manuel" is.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on May 03, 2011, 10:38:23 PM
The Xcode documentation is pretty good. If you have a question about UIImageViews, just type in UIImageView and hit enter. It'll pop up a description of it, all it's functions, and how all the functions work. Fairly nice.

There are also some video tuts and stuff on how to do certain things.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on May 04, 2011, 04:49:10 PM
I see, and just wondering. Could you do a tutorial on useful cases (functions, or whatever the heck their called), and their Gamemaker counterparts, or maybe how to make a "fake array" like in the articles and tutorials section.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on May 04, 2011, 05:22:37 PM
Hmm. I think you're right. I need to scrap these tutorials, make new ones, especially on how to use certain functions, make a real array and do stuff.

Holy crap. I just realized my previous tutorials cover all that. Maybe I'll just update them.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on May 04, 2011, 05:45:33 PM
Quote
Holy crap. I just realized my previous tutorials cover all that. Maybe I'll just update them.
what previous tutorials? Well cool, I'd like to use my knowledge of GM to get me a foot up on Object-C
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on May 04, 2011, 05:53:33 PM
The previous tutorials are in the first post in this thread. Though it looks like some of them are missing. So I gotta make new ones.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on May 05, 2011, 02:45:29 PM
okay so I thought I'd start off making a dice roller for Xcode (don't tell me they're all ready dice rollers, mine is especially for AD&D) and I think i have the random number class down, but I don't know which template I should choose, the differences aren't really defined. So...

What is the best template for a dice roller?
What is the best template for an RPG?
WHat is the best template for a comand line based app?
and can I import your template into the template chooser?

sorry to bombard you with all these questions.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on May 05, 2011, 04:45:33 PM
Okay so I tried the split-view, and hues it's fine, but this error popped up when I tried to build it right off the start, to see what I had to work with and this popped up
http://www.mediafire.com/download.php?40pp47agcjjr6nt
I have no idea what it means ??? at all
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on May 05, 2011, 05:08:26 PM
It means you can't run it on your iPhone. Cause you don't have the app signed.
You should change it from iphone to iPhone Simulator.

For a dice roller really anything would work. Though probably the simplest would just be a simple UIView template.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on May 05, 2011, 05:42:14 PM
Quote
It means you can't run it on your iPhone. Cause you don't have the app signed.
You should change it from iphone to iPhone Simulator.
I don't understand? isn't this the format where there's a bunch of tabs and you click them and go to different windows. Also which template would make the app almost card based in a way where I can go from one window to the next with a button press instead of tabs?
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on May 05, 2011, 05:47:31 PM
A navigation controller template is what you're looking for.

To get rid of the bug go to the top, hit the button, click simulator.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on May 05, 2011, 08:49:33 PM
I got it thanks, maybe while your re making those tutorials you should try making one on the templates. Also can I add your template in, instead of copying the folder everytime?
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on May 05, 2011, 09:20:58 PM
alright so I was trying to do the dice roller I was talking about earlier, and I was fine declaring variables in the .h files, the I went to the .m files and it went all bad
first of all what are those things with @ signs before their purple names, and what are their significance, and secondly wear do I put my code, and thirdly in .h files are you only able to declare variables, or are there other processes you can do?
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on May 05, 2011, 10:23:04 PM
.h is only for declaring variables and functions.

.m is for code. There should be a whole lot of functions already in the .m that you can use.
@"test" is a string variable.
@synthesize prepares global variables to be accessible by outside classes.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on May 06, 2011, 02:51:28 PM
okay I guess I can get that, but where do I put my code in? like do I have to separate them based on different functions (if so which where) or can I just put all of them in one function block?
P.S. i'm on chapter 11 now
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on May 06, 2011, 03:26:38 PM
where do you put custom functions in? do you put them in the .h or .m files?
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on May 06, 2011, 03:40:21 PM
Your custom function code goes in the .m while you declare it in the .h.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Somhairle1314 on May 10, 2011, 08:16:47 PM
I can not get the first tutorial to open/download.  When I try to open the file in a new window or when I save the file and open it I get the same message (Not Found url not found on this server).  The second and third tutorials work fine though.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Connors on May 10, 2011, 08:50:00 PM
Yo, gan! I don't remember ever seeing a thread with 10,000+ views before! Nice work!
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on May 10, 2011, 10:29:38 PM
Quote
I can not get the first tutorial to open/download.  When I try to open the file in a new window or when I save the file and open it I get the same message (Not Found url not found on this server).  The second and third tutorials work fine though.
I apologize, but the first tutorial has died.
So dead that I can't resuscitate it. Sorry. I might remake it sometime in the future.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on May 11, 2011, 03:50:52 PM
so I've been looking through the classes and they always seem to have a .h file to make them work, and it says to import them, but all the information they give is the name (ie. UISwipeGestureRecognizer.h) so I create it, and then don't know what to put in there.
What am I supposed to do, to get, or make these .h files
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on May 11, 2011, 04:39:07 PM
You don't need to create or get the .h files. You have the frameworks, to use their functions just put #import "name of framework" at the top of the class you want to use them in.

I'd suggest following a specific tutorial to learn the basics rather than attempting to study the structure and lingo.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: breshi on May 19, 2011, 01:39:08 AM
I've been slowly working on swapping a game I wrote in the old Game Makers Template to the new one and I have to say the new template is FANTASTIC!!!!!!
Rather than wrap my mind around adding alert views for high score name entry I just use Interface Builder to bring hidden labels and textFields up - so much better.
It is much, much, much faster.
Adding new pages is easier so now I have Options, Credits, Info and High Score screens.
Just wanted to especially thank Gan the Flamer for all his help and making the template available.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: breshi on May 19, 2011, 07:17:22 PM
Have got a question - how do a pass a variable (bool soundOption;) set up in my optionsScreen to my gameScreen.m?
I know how to assign a global variable throughout one .m file but how do you pass it to another?
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on May 20, 2011, 12:15:26 AM
That's where I use the delegate.
At the top of your .m file if you add:
#import "DelegateName.h"
DelegateName *delegate;

Then in load you do:
delegate = [[UIApplication sharedApplication] delegate];

And voila. Put your global variables in delegate and you have easy access from everywhere. Or you could put your global variables in a singleton class and just pass that down through the delegate.

P.S. I don't know if this is the most professional way but I have found it to be efficient, quick, and easy.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: breshi on May 20, 2011, 12:45:39 AM
Do you have to declare the variables in all the .h files ie AppDelegate.h MainMenu.h HighScoreScreen.h and gameScreen.H?
Which .m file do you initially set the variables?

I have put the following code at the start of each of my .m files:
#import "AppDelegate.h"
AppDelegate *delegate;

I then put in the ViewDidLoad:
    delegate = [[UIApplication sharedApplication] delegate];

Is this what you meant? I only ask because it doesn't seam to be working.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on May 20, 2011, 08:10:55 AM
Quote
Do you have to declare the variables in all the .h files ie AppDelegate.h MainMenu.h HighScoreScreen.h and gameScreen.H?
Which .m file do you initially set the variables?

I have put the following code at the start of each of my .m files:
#import "AppDelegate.h"
AppDelegate *delegate;

I then put in the ViewDidLoad:
    delegate = [[UIApplication sharedApplication] delegate];

Is this what you meant? I only ask because it doesn't seam to be working.
Sorry, I did a poor job of explaining. Global variables go in the delegate's .h and must be propertied and synthesized in which you'll be able to access them from other classes through delegate.myVariable.
Later today when I wake up I'll post actual working code.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on May 20, 2011, 08:40:49 AM
Here's an example of a delegate .h:
Code: [Select]
#import <UIKit/UIKit.h>

@interface AppDelegate : NSObject <UIApplicationDelegate> {
    NSString* name;
    BOOL soundOption;
}

@property (nonatomic, retain) NSString* name;
@property (nonatomic) BOOL soundOption;

@end

Top of delegate .m file:
Code: [Select]
#import "AppDelegate.h"

@implementation QAppDelegate
@synthesize name,soundOption;

That makes 2 global variables, name and soundOption.
To use them in other classes you put this in the top of the .m:
Code: [Select]
#import "AppDelegate.h" 
AppDelegate *delegate;
And this in the loading of that class:
Code: [Select]
delegate = [[UIApplication sharedApplication] delegate]; 

Then in that class you can access those variable by delegate.soundOption or delegate.name.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: breshi on May 23, 2011, 08:15:46 PM
Sorry for the delay in replying but I have only just had a chance this morning to get back to the code.

I have put in the code you suggested but in the AppDelegate.m file I have put in the line:
@synthesize soundOption;
and get this error:
Type of property 'soundOption ('signed char') does not match type of var of ivar 'soundOption' ('_Bool')
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on May 23, 2011, 08:34:42 PM
Can you paste the code you used?
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on May 23, 2011, 08:42:45 PM
what commands would you use to create and control a SPRITE, and make grid nave. I'm trying to make an iPhone RPG!
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on May 23, 2011, 08:59:11 PM
One of the easiest ways would be to make UIImageViews as the sprites. Then just move 'em around.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: breshi on May 23, 2011, 09:59:19 PM
In the AppDelegate.h I have:

#import <UIKit/UIKit.h>
#import "MainMenu.h"

@interface AppDelegate : NSObject <UIApplicationDelegate> {
    IBOutlet UINavigationController* nav;
    IBOutlet MainMenu* mainMenu;
        
bool accelerometerOption;
bool vibOption;
bool soundOption;
    bool musicOption;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic) BOOL accelerometerOption;
@property (nonatomic) BOOL vibOption;
@property (nonatomic) BOOL soundOption;
@property (nonatomic) BOOL musicOption;

@end

and in the appDelegate.m I have:



#import "AppDelegate.h"

@implementation AppDelegate
@synthesize window;
@synthesize accelerometerOption;
@synthesize vibOption;
@synthesize soundOption;
@synthesize musicOption;


All 4 synthesize commands show a similar error message.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on May 23, 2011, 10:36:19 PM
Maybe it's because you're having them as "bool" in your first declaration then as "BOOL" in your property declarations.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: breshi on May 23, 2011, 10:49:53 PM
That was it!!
I can't believe that it didn't like that.
Thanks.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on May 23, 2011, 11:03:21 PM
Yeah, Obj-C is very case sensitive. One ill-placed capital can ruin the whole program.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: breshi on May 23, 2011, 11:12:26 PM
OK did all that and put the relevant code in the AppDelegate.h and .m files.
Thus creating 4 global bool variables.

In the MainMenu.m, the OptionsScreen.m and the GameScreen.m I put this at the top:
#import "AppDelegate.h"  
AppDelegate *delegate;
and this in the ViewDidLoad class:
delegate = [[UIApplication sharedApplication] delegate];

I had to redeclare these four variables in each of the .h files as I was getting error messages with out them there- "Use of undeclared identifier 'soundOption'"

I set them all as TRUE in the MainMenu.m file but they do not flow through.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on May 23, 2011, 11:19:30 PM
Don't re-declare your global vars in your other classes. Just in the AppDelegate.

To access the global vars you gotta do:
delegate.soundOption
Title: Re: My iPhone Game Tutorials for Beginners
Post by: breshi on May 23, 2011, 11:50:27 PM
I've said it before, and I will say it again - You are a legend!!
Thank you.

Now it has brought to light one other question.
In my optionsScreen I have four toggle switches which enables me to change my options but they do not display properly.
How can you set them in the program? and
Where do you set them in the program as if you do it in the ViewDidLoad isn't that too late?
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on May 23, 2011, 11:56:35 PM
You can set them in viewDidLoad or viewDidAppear. Neither are too late.
To figure out what code to use I'd suggest going to the Developer Documentation in Xcode and searching the toggle switch control. When at the docs for the switch you can scroll down to see all the functions for it and definitions of what they do. Very handy.

But the functions is probably somewhere along the lines of setState:
Title: Re: My iPhone Game Tutorials for Beginners
Post by: breshi on May 24, 2011, 12:24:12 AM
Where would you put something you only want run the very first time you run your template.
I want to set my options once and then let the user change them with out getting them reset.
As the template goes back and fourth between different screens including MainMenu where would I find a class that only ever gets run once when you start the app?
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on May 24, 2011, 12:26:48 AM
That would be the delegate. On application load in the app delegate. Ran once. When the app opens.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: breshi on May 24, 2011, 12:37:18 AM
That's perfect.
Would I be right in saying because I am putting them there I do not need to put the 'delgate.' in front of the variable name?
ie:
soundOption = TRUE;
rather than
delegate.soundOption = TRUE;
Title: Re: My iPhone Game Tutorials for Beginners
Post by: breshi on May 24, 2011, 01:31:59 AM
All good:

To change the switch I used:
        [soundSwitch setOn:YES animated:YES];
or
        [soundSwitch setOn:NO animated:YES];

and then had to remember to link the switch in IB as a Referencing Outlet



Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on May 24, 2011, 10:00:18 AM
Yeah, awesome.
Sounds like your figuring stuff out on your own. Soon when you run into a road block you'll be able to overcome it without asking.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on May 26, 2011, 05:59:22 PM
which cases would I have to learn about to make an RPG, and also in a custom case can you have numbers in the name?
P.S. I'm making a THAC0 class!
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on May 26, 2011, 06:10:49 PM
(1) Don't use the word case in place of function. A case has it's own specific use in Obj-C.
(2) You'd have to learn how to display graphics, move them, make a timer to make game logic, and make custom classes to make it easier to handle such things as bad guys and stuff.
(3) In a custom function you can have numbers in the name..
(4) What is THAC0?
Title: Re: My iPhone Game Tutorials for Beginners
Post by: breshi on May 28, 2011, 01:26:11 AM
With the new template to access any screen you have to go via the MainMenu.
I have modified one screen so it goes directly to a different screen and back again. It works fine but when it returns how can I tell that it has returned? ViewDidLoad is not flagged in this case.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on May 28, 2011, 07:52:32 AM
If you look in the docs for UIViewController there should be a viewDidAppear function. That gets called when your view in the controller is show.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: breshi on May 28, 2011, 10:12:49 PM
Thanks - that worked.
I search and try to figure it out but a simple hint like that is perfect!!!
Title: Re: My iPhone Game Tutorials for Beginners
Post by: breshi on May 28, 2011, 11:54:13 PM
Everything now is working well - 99% of the time.
Occasionally if I am swapping between screens I get a Bad Exec error and from past experience it means I have a memory leak somewhere.
I made sure every time I alloc or retain I have a matching release - I did miss a few so I put them in.
Still happens so I found an "analyse" option and ran it, the only potential issues it came up with are in the MainMenu.m

- (IBAction)options {
    OptionsScreen *controller = [[OptionsScreen alloc] initWithNibName:@"OptionsScreen" bundle:nil];
    [[self navigationController] pushViewController:controller animated:YES];
}

Here it says "Potential leak of an object allocated on line 59 and stored into 'controller'"

I get the same message for each screen that is called.

Is it because we are alloc OptionsScreen and not releasing it anywhere - I have not really changed much in this part of the Template so am hesitant to make any changes.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on May 29, 2011, 12:14:02 AM
No problem.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on June 05, 2011, 03:11:36 PM
Quote
(1) Don't use the word case in place of function. A case has it's own specific use in Obj-C.
(2) You'd have to learn how to display graphics, move them, make a timer to make game logic, and make custom classes to make it easier to handle such things as bad guys and stuff.
(3) In a custom function you can have numbers in the name..
(4) What is THAC0?
sry I just haven't been on the computer in general.
1.) oh okay I though they were the same.
2.) right that's probably what I'll try to find out next. It might be a good tut theme
3.) do you mean can't or can?
4.) THAC0 To Hit At Armor Class Zero. It's a AD&D rule on how to hit enemies If you don't have your combat tables.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on June 05, 2011, 03:26:34 PM
(3) Can
(4) Never played D&D.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on June 05, 2011, 04:23:33 PM
you should. In my opinion it could most definitely be the Best game of all time in adventure & RPG, sci-fi, and western game history.
I'm talking about the paper and pens version, not Online D&D.
And yes I do consider Boot Hill, Alpha Omega, and Gamma World all D&D.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on June 06, 2011, 07:09:31 PM
I found this tut by you somewhere. I don't remember where

http://www.youtube.com/watch?v=GUUF5ojX1ps&NR=1

but it wasn't posted here so I took the liberty.
And by the way This one was probably one of your most helpful for me! Thanks :)
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on June 06, 2011, 07:39:39 PM
If you make an app on Xcode. How do you put it on your iPod without a $100 developer account.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on June 06, 2011, 10:33:19 PM
It's actually my latest tutorial I've made. Haven't put it in the Gmg though.

I don't believe there's an easy way. Make your app fully and get the dev license when the app is ready.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: breshi on June 08, 2011, 10:22:43 PM
Hi guys, using the new template I would like to draw some lines on the screen.
The old template did this extremely well so I cut and past some of the code (ie the drawline, drawoval, the drawstring etc) and placed it in gamescreen.
I then put this code in theviewdid launch to see if I could draw an oval:

position = CGPointMake(50, 50);
    CGContextRef context;
//To set a color for a shape:
float color[] = {1.0,1.0,1.0,1.0};
    
//ALL DRAWING CODE GOES HERE
[self drawOval:context translate:CGPointMake(0, 0) color:color point:position dimensions:CGPointMake(10, 10) rotation:0 filled:TRUE linesize:0.0];

The code likes it, I get no issues but I also get not oval.
I went through the help, and I downloaded a code example of drawing (QuatzDemo) but I am having trouble working out how to get some drawing on my screen. I really have tried to solve this on my own but am stuck.
Any help would be appreciated.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on June 08, 2011, 10:57:26 PM
To draw on a view you need to put drawing code in the DrawRect method. Then you need to update the view.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: breshi on June 09, 2011, 12:37:35 AM
Sorry, I'm really trying elsewhere to understand this. Spent the last couple of hours reading streams of documentation other forums and very unhelpful apple documentation.
The new template is using UIViewController whilst the old is just using UIView and from what I understand that is where most of my problems lie.
I put the code in the DrawRect as suggested and also put in a NSLog to see if it ever gets called - it doesn't.
I know this is a problem with my lack of understanding so I am sorry for the frustration it must cause to try and answer it.
It is interesting that on the iPhone Dev SDK forum someone has the exact problem and the answer they were given was "Read the OS Programming Guide."
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on June 09, 2011, 07:57:01 AM
Alright, so you got multiple ways of doing this. Some vary in quality and complexity.
(1) Make a new UIView class and set your view that the view controller controls as that new view class. Then you just put your code in that view. Of course using DrawRect can be slow and this method doesn't integrate well with other UIImageView graphics on the screen.
(2) Create a new UIView class with the drawing code. Make it update only when needed. Add it to your main view just like you do with UIImageViews. Now you can manipulate that drawable view just like you do UIImageViews.
(3) Find code to draw directly into a UIImage. Make a new one with your draw code, add it a UIImageView which you can then manipulate on screen.

Those are my suggestions, choose wisely cause each depends mostly on how you want the program set up.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: breshi on June 09, 2011, 05:33:32 PM
Thanks Gan,
I think Im going to choose whats behind curtain no 3.
I need some images flying around the screen but need to do some drawing as well!
Title: Re: My iPhone Game Tutorials for Beginners
Post by: breshi on June 09, 2011, 06:20:23 PM
Curtain no 3 was a winner!!
If anyone else has a similar sort of problem I did this:
1. Create a large empty UIImageView in xib
2. Created a referencing outlet called backgroundImage
3. put the following code in:


UIGraphicsBeginImageContext(CGSizeMake(300, 450));
CGContextRef context = UIGraphicsGetCurrentContext();
    
// drawing with a white stroke color
CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0);
// drawing with a white fill color
CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0);
// Add Filled Rectangle,
CGContextFillRect(context, CGRectMake(0.0, 0.0, 20, 40));
    
backgroundImage.image = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

This then drew a small white rectangle at the top left of my image - perfect!!

Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on June 09, 2011, 08:48:06 PM
Congratz.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on June 11, 2011, 09:11:01 PM
HI gan I had a question about a book I thought about getting.
It called "Coding in Object-C 2.0"

I looked for it on amazon, and found it, but it said that a new version of it was coming out "for Xcode 4 and iOS"
I have Xcode 3.5, but may get Xcode4 once I pay Apple the $100 if it isn't too different, and I'm probably only going to develop for the iOS. The books are the same price.

Which should I get?
And does "Coding in Object-C 2.0" have anything about development for the iOS?
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on June 12, 2011, 09:46:57 AM
Never read that book but Objective-C 2.0 is much different than 1.0.
XCode 4 is just a bit different that Xcode 3.

It may be useful to get them but it's up to you. I started out by going through free online resources, so that's what I suggest. Free resources and experimentation.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: breshi on June 16, 2011, 01:34:02 AM
Got my first game on iTunes!!

http://itunes.apple.com/au/app/christmas-high-jinks/id443115778?mt=8

Thanks to everyone on the forum for their help!!!!!
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on August 16, 2011, 12:15:34 PM
Gan I finally started reading an Objective-C book. and your right it is a neat language. way better than C++.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on August 25, 2011, 03:23:48 PM
If you know anything about me you know three things stay the same

1.) I'll always make a fool of myself on forums
2.) I never take a real vacation
3.) and I always self-impose due-dates

during my recent leave I learned Obj-C, and part of the foundation framework, and a little bit of making iPhone user interfaces, and I hope to make a iPhone game ofter my C/C++ tutorials.

P.S. and Gan you were right it is an awesome language! In the future it might be my main language.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on September 24, 2011, 06:54:58 PM
hey sorry too bug you again, but can you resize a sprite? The game I'm making has the screen resize to show the entire room your in.

And also, how do you make image drawing work with a sprite sheet instead of separate images for 'left' 'right' 'walking' or 'idle'.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on September 24, 2011, 08:06:22 PM
Quote
hey sorry too bug you again, but can you resize a sprite? The game I'm making has the screen resize to show the entire room your in.
Sounds like a fancy scaling thing. There are some ways of doing this, completely different in OpenGl vs CoreGraphics. Which are you using?

Quote
And also, how do you make image drawing work with a sprite sheet instead of separate images for 'left' 'right' 'walking' or 'idle'.
There is a way to do that. I can't remember off the top of my head... but there is a way. I guess I can just say to Google it.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on September 24, 2011, 08:40:50 PM
I'm pretty sure I'll use Core Graphics.

alright I'll google it. ;)

EDIT: didn't find it in google, but in one of my books. looks a bit complicated, but I should hope to get it. It'd just require experimentation, and'd be something to build up to (the sprite sheet)
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on December 02, 2011, 05:28:41 PM
How do you draw a Sprite?
I've been experimenting with UIImage, but can't get anything to actually apear on the screen. I've googled it, but can't get anything that specifically shows that.

Even just a small code sample would be fine, I"m desperate at this point  [smiley=dankk2.gif]
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on December 03, 2011, 02:57:07 AM
Code: [Select]
UIImage* cow = [UIImage imageNamed:@"cow.png"];
[cow retain];
UIImageView* sprite = [[UIImageView alloc] init];
sprite.image = cow:
[myView addSubview:sprite];
sprite.center = CGPointMake(50,50);

Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on December 03, 2011, 05:06:27 PM
Code: [Select]
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
   
    // Override point for customization after application launch.

      // Set the view controller as the window's root view controller and display.
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
      
      UIImage* player = [UIImage imageNamed:@"Sprite.gif"];
      UIImageView* Sprite = [[UIImageView alloc] initWithImage:player];
      [viewController addSubveiw:Sprite]; /*****problematic code*****/
      Sprite.center = CGPointMake(50, 50);
      
      
      
    return YES;
}

Without the line marked problematic code it open and showed a blank grey screen. When I put that in, it says the build was successful, and then opens, and immediately crashes.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on December 03, 2011, 05:59:41 PM
[viewController.view addSubview: sprite];
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on December 06, 2011, 04:08:39 PM
oh I see. I was using -addSubveiw with a UIVeiwController, when I was supposed to used it with a UIVeiw.

While I was sick I re-read the sections in the books about these, so just so I'm clear:

UIImage is an object container for an image
UIVeiwController manipulates, and checks the UIVeiws
UIWindow is like a card in GM, and encapsulates everything

are thoes right, or am I still off?  :-?
also what the heck is the difference between a UIImage and a UIImageVeiw. sorry for asking all these n00b questions, but I can't seem to find anything specifically on my query.  [smiley=embarassed.gif]
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on December 06, 2011, 05:35:51 PM
A UIImage is the image. A UIImageView is a view that displays the UIImage.
Besides that everything's correct.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on December 08, 2011, 05:43:21 PM
Obj-C is hell  [smiley=angry.gif]

I finally found a sample application simple enough I could understand it, but it doesn't use any UIImageVeiws, it uses something called a UIVeiw. from the UIVeiw reference (in the documentation) it sounds like UIImageVeiw is a subclass, but why use it if you can fully function with a UIVeiw? What added benefit does it have?

http://developer.apple.com/library/ios/#samplecode/MoveMe/Introduction/Intro.html
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on December 08, 2011, 08:15:19 PM
You can display images on a UIView by drawing with CoreGraphics. Or you can choose to use a UIImageView, just set the Image property and it draws it for you.

UIImageViews are a bit easier and don't take as much CPU as CoreGraphics.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on December 10, 2011, 07:32:21 PM
Thanks so much Gan, I've finally got the hang of Objective-C, and yes you were right there was a beautiful princess at the end, now I just have to conquer the Dragon.  ;D

p.s. this metaphor is perfect.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Connors on December 10, 2011, 07:42:51 PM
Hey Gan I know it seems like I waited a long time to look at this again but now I'm really interested...
How similar is Obj-C to C?  Will I be able to look at your early tutorials and learn what I need?
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on December 10, 2011, 08:18:22 PM
They are way different, Obj-C is way easier.

Yeah my older tutorials are still good to learn the basics.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on December 15, 2011, 06:43:14 PM
I beg to differ, C is way easier for me, and I enjoy it more, except for larger programs, u need Object-Oriented programming for that.

OBj-C paradox! Do I have to allocate the AppDelegate object to use it's public properties and what not in other objects? Or is it automatically allocated somewhere?

EDIT:
nvm that was a retarded question, what I meant to ask was:
when is the main() function called in an Obj-C program.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on December 15, 2011, 07:13:53 PM
It is in the main.m file. But it's best to follow the structure of Obj-C and have code work from the AppDelegate and other classes you've created.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on December 16, 2011, 09:26:16 PM
I'm trying to make a timer to handle game logic, but it won't even run GameTimer is an NSTimer, and mainloop is a NSRunLoop.

I finnaly found out what #pragma is  [smiley=WaveyWave2.gif]


[code c++]//
//  AdventureViewController.m
//  Adventure
//
//  Created by Kurt Manion on 12/10/11.
//  Copyright 2011 __Compleatly_Coded__. All rights reserved.
//

#import "Adventure_Prefix.pch"
#import "AdventureViewController.h"

@implementation AdventureViewController

@synthesize GameTimer;
@synthesize mainloop;


#pragma mark -
#pragma mark Touches

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
      
      NSSet*            allTouches      = [event allTouches];
      UITouch*      touch            = [[allTouches allObjects] objectAtIndex:0];
  //UIView*            Frame            = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
      CGPoint       Location      = [touch locationInView:nil];
  //int                  *quadrants;
      
      NSLog(@"touch at location:%@",NSStringFromCGPoint(Location));
      

      
}

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

      //[GameTimer invalidate];
      NSLog(@"Touches ended");
      
}


#pragma mark -
#pragma mark CustomInitalizer

// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
            [self makeTimer];
            [self startTimer];
            
            UIImage* Sprite = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Sprite" ofType:@"gif"]];
            UIImageView* Hero = [[UIImageView alloc] initWithImage:Sprite];
            [self.view insertSubview:Hero atIndex:1];
            Hero.center = CGPointMake(CENTER);
            
            [Sprite retain];
            [Hero retain];
    }
    return self;
}

- (void)dealloc {
    [super dealloc];
      [GameTimer release];
      [mainloop release];
}

#pragma mark -
#pragma mark SetUpTimer

- (void) makeTimer {

      NSLog(@"making timer");
      NSTimer* Timer = [NSTimer scheduledTimerWithTimeInterval:0.2
                                                                         target:nil
                                                                     selector:@selector(movehero)
                                                                     userInfo:nil
                                                                        repeats:YES];
      self.GameTimer = Timer;
}

- (void) startTimer {

      NSLog(@"starting timer");
      [mainloop addTimer:GameTimer forMode:NSDefaultRunLoopMode];
      [mainloop run];
      
}

- (void) movehero {

      NSLog(@"Move Hero");
      
}




/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/

#pragma mark -
#pragma mark CustomRules

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

/*
- (void)didReceiveMemoryWarning {
      // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
      
      // Release any cached data, images, etc that aren't in use.
}
*/

/*
- (void)viewDidUnload {
      // Release any retained subviews of the main view.
      // e.g. self.myOutlet = nil;
}
*/





@end
[/code]
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on December 16, 2011, 11:28:49 PM
Delete any code involved with the NSRunLoop. That's unnecessary. Set the target of the NSTimer's scheduledTimer.... to "self" without the quotations.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on December 18, 2011, 06:08:59 PM
It worked! thanks  :) It's weird that the apple documentation would go into the whole mess of NSRunLoop when you could make it as simple as your method.  [smiley=dankk2.gif]
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on December 21, 2011, 09:01:12 PM
My device orientation is LandscapeRight. My UITouch event still thinks the iPod is in portrait. Is there an actual way to tell the UITouch that the device has changed orientation, or do I just have to do some subtraction? It seems like there should be some method to switch it's orientation, but I can't find it's documentation anywhere.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on December 21, 2011, 09:10:19 PM
UIViews contain the UITouch responders. A UIView's rotation depends on the rotation of the ViewController. If the ViewController is in portrait, the UIView will be in portrait, which means the touches will be in portrait.

Make sure you set your device orientations in the UIViewController:
[code Objective C]-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}[/code]

Also, you can set the landscape of a UIViewController within Xcode's visual editor. I think you can also set the window's orientation...

Oh and yeah, in your application's PLIST, there should be an option to specify the starting orientation of your application.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on January 02, 2012, 02:08:16 PM
So I've been trying to get the sprite to move, and it sort of works, it moves up if you touch the top, and the other sides, don't really work coorectly, or at all. Thats not the real problem though. A lot of times I touch the screen, and the movement method is called, but isn't allowed to continue, like it's being cut off by the gametimer calling it again. At least I think thats whats wrong, but I have no idea, and haven't been able to find any solutions online

http://www.mediafire.com/?ufo745pt3tb715x
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on January 02, 2012, 03:07:57 PM
Sorry Kurt, turns out I haven't installed Xcode yet on my new computer.

I'm on the road and it'll be tonight before I can try it out. In the meantime I'll use TextEdit to browse your code...

Edit:
Your code looks good, I can clean up a bunch of it. I don't immediately see anything that could cause problems. I'm gonna have to test later when I install Xcode.

Edit 2:
On second thought, your code looks kinda strange. I'm gonna edit and post the new version.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on January 02, 2012, 03:26:35 PM
AdventureViewController.h
Code: [Select]
//
//  AdventureViewController.h
//  Adventure
//
//  Created by Kurt Manion on 12/10/11.
//  Copyright 2011 __Compleatly_Coded__. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface AdventureViewController : UIViewController {
//I like to leave the first letter lowercase.
//I have uppercase for class names
NSTimer* gameTimer;
CGPoint  location;
BOOL touching;
UIImageView* hero;
UIImageView* stage;
}

- (void) makeTimer;
- (void) movehero;

/*
Unnecessary. Only use if another class needs to acess these variables
@property (nonatomic, retain) NSTimer* GameTimer;
@property (nonatomic, readwrite) CGPoint Location;
*/

@end


AdventureViewController.m
Code: [Select]
//
//  AdventureViewController.m
//  Adventure
//
//  Created by Kurt Manion on 12/10/11.
//  Copyright 2011 __Compleatly_Coded__. All rights reserved.
//

#import "Adventure_Prefix.pch"
#import "AdventureViewController.h"

@implementation AdventureViewController

/*
@synthesize GameTimer;
@synthesize Location;
*/

#pragma mark -
#pragma mark Touches

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

NSSet* allTouches = [event allTouches];
UITouch* touch = [[allTouches allObjects] objectAtIndex:0];
CGPoint touchpoint = [touch locationInView:self.view];

touching = YES;
touchpoint.x = [touch locationInView:self.view].y;
touchpoint.y = 320 - [touch locationInView:self.view].x;

location = touchpoint;


NSLog(@"touch at location:%@",NSStringFromCGPoint(location));

}

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

//[GameTimer invalidate];
touching = NO;
//NSLog(@"Touches ended");

}


#pragma mark -
#pragma mark CustomInitalizer

// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
touching = NO;
[self makeTimer];

stage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"stage1.png"]];
hero = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Sprite.png"]];
[self.view addSubview:stage];
[self.view addSubview:hero];
//[self.view insertSubview:Stage atIndex:0];
//[self.view insertSubview:Hero atIndex:1];
Stage.center = CGPointMake(480/2,320/2);
Hero.center = CGPointMake(480/2,320/2);

/*
Allocating automatically retains.
[Sprite retain];
[Hero retain];
[Stage1 retain];
[Stage retain];
*/

    }
    return self;
}

- (void)dealloc {
    [super dealloc];
[GameTimer release];
}

#pragma mark -
#pragma mark SetUpTimer

- (void) makeTimer {

NSLog(@"making timer");
gameTimer = [NSTimer scheduledTimerWithTimeInterval:0.2
target:self
   selector:@selector(movehero)
   userInfo:nil
repeats:YES];
}

- (void) movehero {

if (touching == YES)
{
NSLog(@"entering move hero");


NSLog(@"%@",NSStringFromCGPoint(hero.center));

//CGPoint newCenter = Hero.center;

//What is MVM? I assume movement speed
//I'd suggest declaring it as a var or using a number
int MVM = 5;

if (location.x >= 240) {NSLog(@"touch at top"); hero.center = CGPointMake(hero.center.x - MVM, hero.center.y);}
if (location.x <= 80) {NSLog(@"touch at bottom");hero.center = CGPointMake(hero.center.x + MVM, hero.center.y);}
if (location.y >= 360) {NSLog(@"touch at right");hero.center = CGPointMake(hero.center.x, hero.center.y + MVM);}
if (location.y <= 120) {NSLog(@"touch at left");hero.center = CGPointMake(hero.center.x, hero.center.y - MVM);}

//hero.center=newCenter;
/*
Already in the view, don't need to re-insert
[self.view insertSubview:Hero atIndex:1];
*/
//NSLog(@"moving to:%@", NSStringFromCGPoint(newCenter));

}
}


/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/

#pragma mark -
#pragma mark CustomRules

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

/*
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
}
*/

/*
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
*/


@end

Cleaned up your code, might have fixed up some bugs. Can't test yet.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on January 02, 2012, 07:15:18 PM
Hey Kurt, installed Xcode and took a look at your code.

There was a lot messed up.

http://cl.ly/0j000n2B3o1z1Z0Z3I0k

Also, I believe I fixed the UIView rotation thingymagig touch coordinates. Also added the TouchesMoved method. Ah and fixed the movement. Hmmm....
Have fun. Feel free to post questions and code whenever you run into a problem. I like checking out other people's code and fixing stuff up.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on January 03, 2012, 04:40:55 PM
Thanks Gan  ;D, yeah the code was really messed up, but I see what I did wrong.

The touch glitch is still there though. If I touch the screen, and lift before the timer executes the character doesn't move. I've got 2 ideas I'm going to try out after homework.

Of yeah 'MVM' was a macro, it's located in the Adventure_Prefix.pch, along with 'CENTER'
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on January 03, 2012, 09:12:48 PM
Oh haha, that's an easy fix.

Put this at the end of the TouchesBegan function:
Code: [Select]
[gameTimer fire];

When you touch, the timer fires immediately and the character moves. Before, you had it wait up to 0.2 seconds before anything happened.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on January 04, 2012, 04:38:52 PM
oh thats much nicer than what I did, I had it calling movehero outside of the timer. Cool thanks Gan, I'm back on track  ;D
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Connors on January 06, 2012, 10:07:25 PM
The links in your first post (ball tutorial) go to a "file not found" error.
Did you update them? Did I just not read enough pages? ???
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on January 06, 2012, 10:30:54 PM
Hmmm. I think those files disappeared somewhere. I can post a beginner template if you want to give it a try.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on January 13, 2012, 02:05:12 PM
Whenever I open up Xcode after having quit it, It sets the active executable to iPad, is there any way to make the default iPhone?
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on January 13, 2012, 02:36:12 PM
That's a good question. I have no idea.

My suggestion, go play around in your project setting.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on January 13, 2012, 05:03:08 PM
so yeah yadayda... code defication...

Code: [Select]
#import "Unbeatable_Prefix.pch"


@interface Sprite : NSObject {

UIImage* Image;
UIImageView* Sprite;
CGPoint Location;

}
@property (retain, nonatomic) UIImage* Image;
@property (retain, nonatomic) UIImageView* Sprite;
@property (readwrite, nonatomic) CGPoint Location;

+(void) move:(CGPoint) newPoint; //to be used by the walking and jumping function

-(void) initialize:(stype)spriteType;

@end

Code: [Select]
#import "Sprite.h"


@implementation Sprite
@synthesize Image;
@synthesize Sprite;
@synthesize Location;

+(void) move:(CGPoint) newPoint
{

self.Location = newPoint; /***** error *****/

}

-(void) initialize:(stype)spriteType
{

switch (spriteType) {
case PLAYER:

break;
case MONSTER:

break;
case ENTITY:

break;
case STAGE:

break;

default:
break;
}

}

@end

Accessing unknown setLocation method.
Object cannot be set - either readonly prop. or no setter found
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on January 13, 2012, 05:06:41 PM
Code: [Select]
#import "Unbeatable_Prefix.pch"


@interface Sprite : NSObject {

UIImage* Image;
UIImageView* Sprite;
CGPoint Location;

}
@property (retain, nonatomic) UIImage* Image;
@property (retain, nonatomic) UIImageView* Sprite;
@property (assign) CGPoint Location;

-(void) move:(CGPoint) newPoint; //to be used by the walking and jumping function

-(void) initialize:(stype)spriteType;

@end

Code: [Select]
#import "Sprite.h"


@implementation Sprite
@synthesize Image,Sprite,Location;

-(void) move:(CGPoint) newPoint
{

self.Location = newPoint; /***** error *****/

}

-(void) initialize:(stype)spriteType
{

switch (spriteType) {
case PLAYER:

break;
case MONSTER:

break;
case ENTITY:

break;
case STAGE:

break;

default:
break;
}

}

@end

Try that.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on January 13, 2012, 10:16:35 PM
I've got two problems. One my method marked problematic code would execute, and there's an uncaught exception: NSInternalInconsistencyException from       UnbeatableViewController.xib. The problem triggers, when the program tries to 'makekeyandvisible'

I've isolated the problems to those areas, but I can't for the life of me even comprehend what I did wrong.

Code: [Select]
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
//initialize the viewController and spriteController
NSLog(@"delegate");
self.viewController = [[UnbeatableViewController alloc] initWithNibName:@"UnbeatableViewController.xib" bundle:[NSBundle mainBundle]];
[[self.viewController sController] init:FIELD]; /***** problematic *****/
NSLog(@"end delegate");

// Set the view controller as the window's root view controller and display.
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];

    return YES;
}
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on January 13, 2012, 11:48:49 PM
Hmm. I see a few lines of code and I'm thinking, "What are you doing there?".

If you could PM me your source I could better debug it.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on January 15, 2012, 12:08:03 PM
oh sorry that must've slipped my mind

http://www.mediafire.com/download.php?6fx1ux6567bgx77

The line labeled, problematic code won't even run. And then theres the whole NSInternalInconsistencyException
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on January 15, 2012, 12:43:22 PM
I'll try to check this out but I don't think I'm gonna have wifi at all today.

Edit:
I'm doing the 22 hour drive home today.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on January 16, 2012, 02:01:15 PM
alright thanks for taking time to look at it. In the future where would I go when I get strange errors like this?

EDIT:
I found out a bit more about 'NSInternalInconsistencyException' in the documentation

NSInternalInconsistencyException
Name of an exception that occurs when an internal assertion fails and implies an unexpected condition within the called code.
Available in Mac OS X v10.0 and later.
Declared in NSException.h.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on January 16, 2012, 03:45:40 PM
http://cl.ly/2M280Y3X0I3p0s3T0W0y

Enjoy.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on January 16, 2012, 03:52:54 PM
thank you so much Gan. It works perfectly.  ;D
Title: Re: My iPhone Game Tutorials for Beginners
Post by: GMG Kurt on April 11, 2012, 12:18:02 PM
gan why is it that when I add a UIView with my UIImageView as a subview to the main view it's all blurry, but when I add a UIImageView as the subview to the main view it's nice and sharp?

NOTE: by main view I mean my ViewController's 'view' property.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on April 11, 2012, 12:46:14 PM
The UIImageView is probably being placed in between pixels. Caused by the positions of the UIImageView itself and the UIView it's being placed in.
When place in between pixels, it use Anti-aliasing to make the image be seen as in-between pixels.
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Connors on April 12, 2012, 09:42:08 AM
Yeah you should try to position images with a whole number is that it?
Title: Re: My iPhone Game Tutorials for Beginners
Post by: Gan on April 12, 2012, 10:46:56 AM
Yeah, if you don't want the slight blurriness.