1

How would I determine if a rectangle bigger than the screen is in the screen. I have looked at: Determine if two rectangles overlap each other?, but it only applies to rectangles where one can fit within the other. My rectangles are like this (Blue is screen, red is object):

Rectangle image

How can I detect if the red at any point is within the blue. I am doing this with python and pygame, so if there is a built in way to do this that would be great.

Thanks, Arkin

Arkin Solomon
  • 592
  • 1
  • 5
  • 23
  • The linked question does not only apply to the case you mentioned. It should also work for your case. You might need to switch top and bottom, depending on your coordinate system. – Nico Schertler Dec 22 '19 at 02:29
  • @NicoSchertler Actually, it doesn't. Not only did I implement it in the game, but in the example (In the comment of the answer), when I changed the style of the rectangle to be different, the tests show that it doesn't work. – Arkin Solomon Dec 22 '19 at 22:03

1 Answers1

2

Pygame has set of methods to deal with rectangles. Your code might do something like.

Rect1.colliderect(Rect2)

Check out this link on handling Rectangles in Pygame... particularly the method pygame.Rect.colliderect.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Euler
  • 312
  • 1
  • 11