如何在pygame中删除矩形?

问题描述

我试图将矩形的颜色设置为与背景颜色相同的颜色,但是我想知道是否有更简单的方法可以做到。这就是我所做的:

screen = display.set_mode(500,500)

BLACK = (255,255,255)
color2 = (127,127,127) #Grey

screen.fill(BLACK)
start_button = draw.rect(screen,color2,(190,180,120,60))
display.update()
for i in event.get():
    if i.type() == MOUSEBUTTONDOWN and mouse.get_pos[0] >= 190 and mouse.get_pos[0] <= 310 and mouse.get_pos[1] >= 180 and mouse.get_pos[1] <= 240:
        color2 = (255,255)
        display.update()

无论如何,这是我第一次尝试pygame,如果您有任何建议,请告诉我。

解决方法

或者,您可以再次填充屏幕并根据需要更新显示。

screen = display.set_mode(500,500)

BLACK = (255,255,255)
color2 = (127,127,127) #Grey

screen.fill(BLACK)
start_button = draw.rect(screen,color2,(190,180,120,60))
display.update()
for i in event.get():
    if i.type() == MOUSEBUTTONDOWN and mouse.get_pos[0] >= 190 and mouse.get_pos[0] <= 310 and mouse.get_pos[1] >= 180 and mouse.get_pos[1] <= 240:
        screen.fill(BLACK)
        display.update()

我还建议您使用按钮,并检查是否使用此按钮 http://programarcadegames.com/index.php?lang=en&chapter=array_backed_grids

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...