[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Questions about blitting



Gabriele Farina wrote:
if I've a surface of 100x100 pixels, and I blit, on this surface, another
surface at (110,110) position, pygame draws this surface or not??Pygame
understand when the position is out of the range??
yes, pygame clips all the blitting to the target surface. you can even blit to a negative position like (-10,-10) and you will see the bottomright area of the source.

if you wanted to test if a source blit will be entirely contained by the destination surface, i'd do it with some Rects.

def is_full_onscreen(src, dst, pos):
dstrect = dst.get_rect()
srcrect = src.get_rect()
srcrect.topleft = pos
return dstrect.contains(srcrect)

def is_partial_onscreen(src, dst, pos):
dstrect = dst.get_rect()
srcrect = src.get_rect()
srcrect.topleft = pos
return dstrect.colliderect(srcrect)