首页 > 解决方案 > 如何在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, 255)
        display.update()

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

标签: pythonpython-3.xpygamedrawgame-development

解决方案


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

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制作按钮并检查它们是否被按下


推荐阅读