pygame.draw.rect()
draw a rectangle shape
rect(Surface, color, Rect, width=0) -> Rect
Draws a rectangular shape on the Surface. The given Rect is the area of the
rectangle. The width argument is the thickness to draw the outer edge. If
width is zero then the rectangle will be filled.
如果您正在寻找一个颜色变化的矩形(或任何其他形状),那么pygame有一些非常有用的
draw
命令拿这个,
pygame.draw.rect
拿自the pygame docs在本例中,
color
将是红、绿和蓝颜色值的3元素元组。这些都将在0和255之间。例如,(255,255,255)将是纯白色。你知道吗如果跟踪一个
health
和一个max_health
变量,那么可以找出矩形中有多少应该是红色的,有多少应该是绿色的。你知道吗例如
假设您的生命值是最大值100中的20,那么绿色值将是255的20%,红色值将是255的80%,并且
pygame.draw.rect
函数将接受color
参数(red_value, green_value, 0)
只要您记得更新
green_value
和red_value
变量,就可以了。你知道吗相关问题 更多 >
编程相关推荐