Question

In this blit call

screen = pygame.Surface(640, 480)
bgsurf = pygame.Surface(640, 480)
new_rect = pygame.Rect(0, 0, 80, 80)

screen.blit(bgsurf, new_rect, new_rect)

how pygame decides which portion of bgsurf it will copy to the screen in the new_rect area?

Was it helpful?

Solution

From the pygame docs:

blit(source, dest, area=None, special_flags = 0) -> Rect

Draws a source Surface onto this Surface. The draw can be positioned with the dest argument. Dest can either be pair of coordinates representing the upper left corner of the source. A Rect can also be passed as the destination and the topleft corner of the rectangle will be used as the position for the blit. The size of the destination rectangle does not effect the blit.

An optional area rectangle can be passed as well. This represents a smaller portion of the source Surface to draw.

So as you can see, pygame would blit the whole surface at (0,0). If you want to blit a part of surface, you need to pass in the area Rect.

EDIT:

In your case, it will blit the subsurface given by new_rect onto screen where the top-left corner will be placed at (0,0).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top