XNA Rectangle.Intersects()

Started by
3 comments, last by Andy474 14 years, 10 months ago
Just a Quick Question : I am Writing a Pong game and have defined a rectangle

topXRect = new Rectangle(0, 0, ScreenWidth, -(ScreenHeight / 10));
now when i use

if(player[0].posRect.Intersects(topXRect))
{
}
does the Rectangle.Intersects(Rectangle) Function dectect the moment the Rectangles intersect, or when there is a large portion of the Rectangles Intersect? (i am trying to create a boundary so my pongRacket cannot leave the Game Screen)
Advertisement
I believe Rectangle.Intersects() simple returns a boolean, true if the rectangles intersect at all, false otherwise.

Alternativly there is also Rectangle.Contains(), which returns true if the rectangle completely contains the other rectangle, and false otherwise.
Ok thanks, that's exactly what I thought XD
Rather than checking every frame if the paddle is on the screen (which it seems is what you're doing) why not just do a check when the paddle moves to make sure it's still on the screen? You really only need to check the X property of the paddle, not do a whole Rectangle check, right?

Former Microsoft XNA and Xbox MVP | Check out my blog for random ramblings on game development

yes, which is what I was doing originally checking if the yPos of my Racket was still on the screen, this worked! (& works)
The Reason I wanted to detect a collision Via Rectangles was to see if it was a viable method of detecting a collision between my racket and my Ball, However after testing this wont work as the Rectangles are colliding multiple time Per Second resulting in a "stuck" ball

This topic is closed to new replies.

Advertisement