问题描述
我试图将矩形的颜色设置为与背景颜色相同的颜色,但是我想知道是否有更简单的方法可以做到。这就是我所做的:
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