Sign in to follow this  
Andy474

XNA Rectangle.Intersects()

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this