Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualShadowValence

Posted 30 August 2012 - 01:26 PM

It looks to me like WarAmp was correct in his response. Your logic is only checking a single point of the 20 pixel ball (X, Y). To correct for this you'll have to extend your logic to include the size.

Try something like this:
[source lang="csharp"]if (ballvec.X + ballrec.Width > maxX || ballvec.X < 0)ballspeed.X *= -1;if (ballvec.Y + ballrec.Height > maxY || ballvec.Y < 0)ballspeed.Y *= -1;[/source]

This makes sure that the furthest part of the ball (not just its current position) is taken into consideration (by adding the width and height).

#1ShadowValence

Posted 30 August 2012 - 01:25 PM

It looks to me like WarAmp was correct in his response. Your logic is only checking a single point of the 20 pixel ball (X, Y). To correct for this you'll have to extend your logic to include the size.

Try something like this:
[source lang="csharp"]if (ballvec.X + ballrec.Width > maxX || ballvec.X < 0)ballspeed.X *= -1;if (ballvec.Y + ballrec.Height > maxY || ballvec.Y < 0)ballspeed.Y *= -1;[/source]

PARTNERS