• Advertisement
Sign in to follow this  

XNA Rectangle.Intersects()

This topic is 3186 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement