我目前是pygame的新手,正在为几件事情苦苦挣扎。我创建了按钮并实现了按钮交互(更改hover_color和鼠标单击)。我现在想要做的只是通过屏幕填充功能在屏幕上绘制一个全新的页面。一旦用户单击该按钮,此操作将仅持续几秒钟,并且该按钮也仍会出现。我对主事件循环的整个概念真的很不好,目前正在一个循环下执行所有任务,据我所知这是不正确的方法,但是到目前为止,它是可行的。如果我可以在屏幕填充功能方面获得帮助,并将当前循环拆分为单独的循环,将对我有很多帮助。谢谢
def game_intro():
while not running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
return
elif event.type == pygame.MOUSEMOTION:
for button in buttons:
if button[1].collidepoint(event.pos):
button[2] = HOVER_COLOR
else:
button[2] = BLACK
screen.blit(bg, (0, 0))
for text, rect, color in buttons:
pygame.draw.rect(screen, color, rect)
screen.blit(text, rect)
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
if rect1.collidepoint(event.pos):
screen.fill((0, 0, 0))
elif rect2.collidepoint(event.pos):
print ('options')
elif rect3.collidepoint(event.pos):
print ('about')
if event.type == KEYDOWN:
if (event.key == K_UP):
print ("UP was pressed")
elif (event.key == K_DOWN):
print ("DOWN was pressed")
elif (event.key == K_w):
print ("W was pressed")
elif (event.key == K_s):
print ("S was pressed")
else:
print ("error")