python - 如何在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,如果您有任何建议,请告诉我。
解决方案
或者,如果需要,您可以再次填充屏幕并更新显示。
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制作按钮并检查它们是否被按下
推荐阅读
- python - 获取熊猫数据框中每个唯一元素的第一个和最后一个日期
- python - 为什么使用 LRU 缓存的图形 DFS 比字典查找更快。LeetCode 128 解法区别
- android - Detect App是通过广告的安装链接
- python - 检查熊猫数据框中的列是否有趋势
- html - 背景图像未显示在引导卡中
- android - 假设这个世界上的所有 Android 设备都使用“\n”作为行分隔符是否可以?
- javascript - 为每个创建的元素创建一个新的 onclick 函数
- yum - download.postgresql.org 的证书已过期
- node.js - 错误:听 EADDRNOTAVAIL 13.*.*.*:3004
- kubernetes - 如何在 envoyproxy 中配置公共访问 web api?