Topic:   My iPhone Game Tutorials for Beginners   (Read 391457 times)


0 Members and 2 Guests are viewing this topic.

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: My iPhone Game Tutorials for Beginners
« Reply #135 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
« Last Edit: August 18, 2010, 06:54:15 AM by Gandolf »

I-NEED-HELP


  • GMG Newbie

  • *


  • Posts: 40

  • I love YaBB 1G - SP1!
Re: My iPhone Game Tutorials for Beginners
« Reply #136 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!
« Last Edit: August 20, 2010, 05:27:05 PM by I-NEED-HELP »

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: My iPhone Game Tutorials for Beginners
« Reply #137 on: August 20, 2010, 06:17:01 PM »
In your application load method you gotta configure the accelerometer:
Code: [Select]
[self configureAccelerometer];


-Gan

I-NEED-HELP


  • GMG Newbie

  • *


  • Posts: 40

  • I love YaBB 1G - SP1!
Re: My iPhone Game Tutorials for Beginners
« Reply #138 on: August 20, 2010, 06:35:14 PM »
Oh! Thanks, I overlooked that. Now my game works! Awesome! Thanks!

I-NEED-HELP


  • GMG Newbie

  • *


  • Posts: 40

  • I love YaBB 1G - SP1!
Re: My iPhone Game Tutorials for Beginners
« Reply #139 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;
}
}
}

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: My iPhone Game Tutorials for Beginners
« Reply #140 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

I-NEED-HELP


  • GMG Newbie

  • *


  • Posts: 40

  • I love YaBB 1G - SP1!
Re: My iPhone Game Tutorials for Beginners
« Reply #141 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!

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: My iPhone Game Tutorials for Beginners
« Reply #142 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

Xiphos


  • GMG-er

  • **


  • Posts: 676
Re: My iPhone Game Tutorials for Beginners
« Reply #143 on: November 21, 2010, 07:07:01 AM »
Is there an equivalent of SC's random? Or a way to replicate it.

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: My iPhone Game Tutorials for Beginners
« Reply #144 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

I-NEED-HELP


  • GMG Newbie

  • *


  • Posts: 40

  • I love YaBB 1G - SP1!
Re: My iPhone Game Tutorials for Beginners
« Reply #145 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.

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: My iPhone Game Tutorials for Beginners
« Reply #146 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

Xiphos


  • GMG-er

  • **


  • Posts: 676
Re: My iPhone Game Tutorials for Beginners
« Reply #147 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)

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: My iPhone Game Tutorials for Beginners
« Reply #148 on: November 21, 2010, 06:41:00 PM »
Yeah, that should be right.


-Gan

GMG Kurt


  • GMG-er

  • **


  • Posts: 682

  • Sorry for being such a noob
Re: My iPhone Game Tutorials for Beginners
« Reply #149 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'
Just your average Weekend Warrior.
Yes I know I have bad spelling, it's what makes me such a good programmer!

"Old art, weather magnificent or wretched, is always the raw material of new art. The artist's job, though, is to