def selection():
global selectionLoop
selectionLoop = True
clock.tick(1)
while selectionLoop:
print("disspam")
window.blit(backgroundgame, (0,0))
text.title('CHOOSE A SUBJECT!')
button(550, 500, 250, 100, rollover_menucolours, menucolours, 'MUSIC', 'music', black, smallText)
button(900, 500, 250, 100, rollover_menucolours, menucolours, 'ART', 'art', black, smallText)
button(1250, 500, 250, 100, rollover_menucolours, menucolours, 'DRAMA', 'drama', black, smallText)
pygame.display.update()
这个菜单工作正常,当我按下指令时,它也工作正常,但当我按下选择时,它会弹出循环,不会听鼠标
def menu():
pygame.mixer.music.load("menu_music.mp3")
pygame.mixer.music.play()
mainLoop = True
clock.tick(1)
while mainLoop:
window.blit(background, (0,0))
text.title('lettermatcher.edu')
button(550, 500, 250, 100, rollover_menucolours, menucolours, 'SELECTION', 'selction', black, smallText)
button(900, 500, 250, 100, rollover_menucolours, menucolours, 'INSTRUCTIONS', 'rule', black, smallText)
button(1250, 500, 250, 100, rollover_menucolours, menucolours, 'QUIT', 'end', black, smallText)
pygame.display.update()
https://www.mediafire.com/file/5n0hkva5alqawiz/pygame.zip/file所以这是我的游戏,请随意下载,当直接进入游戏进入选择菜单时会出现问题。当在选择功能中时,它会像所有其他屏幕一样发送循环,但不会显示。有人能帮我解决这个问题吗。
典型的PyGame应用程序循环必须:
- 使用
pygame.time.Clock.tick
限制每秒帧数以限制CPU使用率 - 通过调用CCD_ 2或CCD_
- 根据输入事件和时间(分别为帧(更新游戏状态和对象的位置
- 清除整个显示或绘制背景
- 绘制整个场景(
blit
所有对象( - 通过调用
pygame.display.update()
或pygame.display.flip()
来更新显示
最小和工作示例:
import pygame
pygame.init()
window = pygame.display.set_mode((500, 500))
clock = pygame.time.Clock()
# main application loop
run = True
while run:
# limit frames per second
clock.tick(100)
# event loop
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
# clear the display
window.fill(0)
# draw the scene
pygame.draw.circle(window, (255, 0, 0), (250, 250), 100)
# update the display
pygame.display.flip()
pygame.quit()
exit()