collision - Is there a way in pygame to detect if a rect is fully inside a mask? -


is there way in pygame detect if rect inside mask?

i know there rect in rect collision , collidepoint (point in rect collision) there way detect if rect inside mask?

thanks

i don't believe there function supplied pygame that. challenging, because of "shapeless" possibilities of mask. 1 possibility might work first list of bounding rects of mask (a list of rects "contain" of points of mask) , check if rect inside of these rects:

bounding_rects = mask.get_bounding_rects() b_rect in bounding_rects:     if b_rect.contains(test_rect):         print "rect inside mask" 

of course solution, if rect inside mask, not inside 1 particular bounding rect, test fail. here's idea of how might handle that, tradeoff of little bit of lost precision:

bounding_rects = mask.get_bounding_rects() mask_rect = bounding_rects[0].unionall(bounding_rects) if mask_rect.contains(test_rect):     print "rect inside mask" 

this solution unions of bounding rects of mask 1 rect, has possibility of covering area none of bounding rects covered (if 2 rects have gap of 10 pixels between each other , unioned together, new rect contain gap)


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -