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


0 Members and 1 Guest are viewing this topic.

gbaldwin9


  • GMG Newbie

  • *


  • Posts: 6

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

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


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

gbaldwin9


  • GMG Newbie

  • *


  • Posts: 6

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

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


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

gbaldwin9


  • GMG Newbie

  • *


  • Posts: 6

  • I love YaBB 1G - SP1!
Re: My iPhone Game Tutorials for Beginners
« Reply #49 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...   ???
« Last Edit: March 22, 2010, 12:16:35 AM by gbaldwin9 »

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


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

gbaldwin9


  • GMG Newbie

  • *


  • Posts: 6

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

Silverwind


  • ^ This guy is amazing.

  • ****


  • Posts: 2805

  • For the glory of my maker
Re: My iPhone Game Tutorials for Beginners
« Reply #52 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?
I survived the spammage of 2007

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


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

Silverwind


  • ^ This guy is amazing.

  • ****


  • Posts: 2805

  • For the glory of my maker
Re: My iPhone Game Tutorials for Beginners
« Reply #54 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%.
« Last Edit: March 22, 2010, 06:47:10 PM by Silverwind »
I survived the spammage of 2007

gbaldwin9


  • GMG Newbie

  • *


  • Posts: 6

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

vsching


  • GMG Newbie

  • *


  • Posts: 1

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

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: My iPhone Game Tutorials for Beginners
« Reply #57 on: April 07, 2010, 08:39:08 PM »
Can't wait to hear what you think of it. :)


-Gan

breshi


  • GMG Newbie

  • *


  • Posts: 31

  • Carpe Diem
Re: My iPhone Game Tutorials for Beginners
« Reply #58 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!

DWapps


  • GMG Newbie

  • *


  • Posts: 14

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