I have been playing with a pong game made of sprites and I reached a certain point which does not make any sense.
The problem is this.
I have two if statements that check to see if the ball collided with P1 and P2 paddles.
function CheckPaddleCollisions()
if sprite hit(BallSprite, P1PaddleSprite) = 1
BallSpeedY = BallSpeedY * -1
endif
if sprite hit(BallSprite, P2PaddleSprite) = 1
BallSpeedY = BallSpeedY * -1
endif
endfunction
The problem is in the second if statement. If the second if statement is omitted, everything works fine. The code runs through the first if statement once check and if it is a hit it changes the BallSpeedY to the negative. No problems
If however the second if statement that checks the P2 collision, the the code runs through the first statement, changes the ballspeed, however, during the second, third, fourth ... it still detects a collision.
With both sprite hit checks it looks like this
http://www.youtube.com/watch?v=0Xy0pJjf4Fc
With only the first sprite check it looks like this
http://www.youtube.com/watch?v=0Xy0pJjf4Fc
It is obvious that if both sprite checks are there the first sprite check is run through continuously. But why? It does not make any sense at all!