python - Pygame 输出:黑色背景
问题描述
我想查看我的blit()
但是一旦我添加了self.screen_dim.fill([255, 255, 255])
pygame.display.update()
它重叠的线
def __init__(self):
self.width = 500
self.height = 500
self.screen_dim = pygame.display.set_mode((self.width, self.height))
self.mole = pygame.image.load("mole.png")
self.mole_hit = pygame.image.load("mole-hit.png")
我对如何让我的pygame屏幕感到困惑,该功能中的图像正在工作,但是如果我添加了新的背景颜色,它会重叠
def start(self):
stat = True
num_display = 1
x_array = []
y_array = []
for i in self.mole_pos:
x_array.append(i[0])
y_array.append(i[1])
while stat:
Rand_Pos = random.randint(0, 8)
if num_display == 1:
self.screen_dim.blit(self.mole, (x_array[Rand_Pos], y_array[Rand_Pos]))
for Event in pygame.event.get():
if Event.type == pygame.QUIT:
stat = False
if self.mouse_clicked(mouse.get_pos(), self.mole_pos[Rand_Pos]):
num_display = 0
self.screen_dim.blit(self.mole_hit, (x_array[Rand_Pos], y_array[Rand_Pos]))
continue
pygame.display.flip()
解决方案
这没什么关系class
。这只是一个缩进的问题。您必须绘制self.mole_hit
应用程序循环而不是事件循环:
def start(self):
# [...]
while stat:
# [...]
for Event in pygame.event.get():
if Event.type == pygame.QUIT:
stat = False
#<--| INDENTATION
if self.mouse_clicked(mouse.get_pos(), self.mole_pos[Rand_Pos]):
num_display = 0
self.screen_dim.blit(self.mole_hit, (x_array[Rand_Pos], y_array[Rand_Pos]))
pygame.display.flip()
推荐阅读
- swift - 如何将 Web 界面功能添加到我的 Swift WebView
- php - 如何找到 PHP 内置函数的代码?
- node.js - 根据 api post 调用上传文件不同的目的地
- r - 文本聚类需要太多时间
- sql - 解决错误这个错误(必须声明标量变量“@totalproduct”。)
- c# - 我为订单和客户选择了 2 个表格,但我添加了日历来监控特定日期的销售情况
- javascript - 无法在回调中访问函数的局部变量
- fortran - 如何使用数据在 fortran 模块中初始化 var
- querydsl - Querydsl 不支持 not() 吗?
- scala - 如果只有第一个接收器成功,则将元素发送到第二个接收器