如何解决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,y_array[Rand_Pos]))
continue
pygame.display.flip()
解决方法
这与class
无关。这只是 Indentation 的问题。您必须在应用程序循环而不是事件循环中绘制 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()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。