作者:allmon白_980 | 来源:互联网 | 2023-12-14 17:07
本文介绍了在Pygame中使用矩形对表面进行涂色的方法。通过查阅Pygame文档中的blit函数,可以了解到如何将一个表面的特定部分复制到另一个表面的指定位置上。具体的解决方法和参数说明在文中都有详细说明。
在这个盲打中
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)
pygame如何决定它将bgsurf的哪一部分复制到new_rect区域的屏幕上?
解决方法:
从pygame文档:
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.
如您所见,pygame将在(0,0)处涂满整个表面.
如果要对曲面的一部分进行拉伸,则需要传入Rect区域.
编辑:
在您的情况下,它将在屏幕上将new_rect给定的次表面着色到屏幕上,该屏幕的左上角将位于(0,0).