如果你想画边框,那么可以直接使用pygame.draw.rect() https://www.pygame.org/docs/ref/draw.html#pygame.draw.rect通过设置width
争论。
def draw_borders(s, x, y, w, h, bw, c):
pygame.draw.rect(s, c, (x, y, w, h), bw)
或者绘制一个封闭的多边形
def draw_borders(s, x, y, w, h, bw, c):
pygame.draw.lines(s, c, True, [(x, y), (x+w, y), (x+w, y+h), (x, y+h)], bw)
如果你想消除角落的缺失,那么你必须将边框缝合4个矩形:
def draw_borders(s, x, y, w, h, bw, c):
pygame.draw.rect(s, c, (x, y, w, bw))
pygame.draw.rect(s, c, (x, y+h-bw, w, bw))
pygame.draw.rect(s, c, (x, y, bw, h))
pygame.draw.rect(s, c, (x+w-bw, y, bw, h))
或由 4 条单独的行组成:
def draw_borders(s, x, y, w, h, bw, c):
pygame.draw.line(s, c, (x-bw//2+1, y), (x+w+bw//2, y), bw)
pygame.draw.line(s, c, (x-bw//2+1, y+h), (x+w+bw//2, y+h), bw)
pygame.draw.line(s, c, (x, y-bw//2+1), (x, y+h+bw//2), bw)
pygame.draw.line(s, c, (x+w, y-bw//2+1), (x+w, y+h+bw//2), bw)