Jump to content
• Advertisement

# XNA Rectangle.Intersects()

This topic is 3453 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

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

##### Share on other sites
Ok thanks, that's exactly what I thought XD

#### Share this 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

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

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5
• Advertisement

• 13
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633317
• Total Posts
3011336
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!