views:

15

answers:

2

i am trying out a pong game to start out developing games on the the iphone and i've got everything moving but i need to implement the scoring and make the ball return to the center of the screen this is the code i have currently in the touchesBegan method:

    if(ball.center.y >=444) {
      computerScore=computerScore+1;
      computerScoreLabel=[NSString stringWithFormat:@"%d", computer];
      ball.center.x=151;
      ball.center.y=222;
}

    if(ball.center.y <=4) {
      playerScore=playerScore+1;
      playerScoreLabel=[NSString stringWithFormat:@"%d", player];
      ball.center.x=151;
      ball.center.y=222;
     }

it builds correctly and runs, but when i try the game on the simulator it just makes the ball move around and when it passes the specific points it just bounces off and the score doesn't change

A: 

Take a look at this turoial......Pong on the iPhone

ennuikiller
A: 

I suggest you add an NSLog() statement so you can actually monitor the value of ball.center.y and see if it's, for instance, triggering a collision-bounce before the value actually matches your conditional.

Seamus Campbell