Skip to main content
gamedev.net
🔒 Locked

XNA Rectangle.Intersects()

Started by Andy474 Jun 2, 2009 at 4:15 AM 3 replies 3.3k views
Original Post
Andy474
Andy474
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)
adt7
adt7
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.
Andy474
Andy474
Ok thanks, that's exactly what I thought XD
Machaira
Machaira
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
Andy474
Andy474
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.