gpt4 book ai didi

python - Pygame 叠加

转载 作者:行者123 更新时间:2023-12-01 06:05:12 25 4
gpt4 key购买 nike

好的,所以我想做一个覆盖屏幕。

因此,每当按键为 p 时,屏幕就会暂停并弹出一个屏幕,显示:“按‘q’退出或按‘c’继续,”类似的事情。

谁能告诉我怎么做?

最佳答案

最简单的方法是使用子模块,然后为 blit() 创建一个新循环 - 到屏幕并处理此暂停菜单的事件。

(这只是方法论;这就是我工作项目的方式。)

更新:2011 年 12 月 13 日

以下代码摘录自“父”模块。这只是代码的循环部分。您正在寻找的是 button.doAction(screen) 行,它基本上告诉 PyGame 执行适用的子模块(并不重要;您只需要像平常一样调用“child”函数) )。

while mainRunning:

# --- Event Catching & Handling ---
for event in pygame.event.get():
# Quit PyGame safely upon exit
if event.type == pygame.QUIT:
mainRunning = False

# Make the buttons do actions
if event.type == pygame.MOUSEBUTTONUP:
mousePos = pygame.mouse.get_pos()
for button in menuList:
X = button.getXPos()
Y = button.getYPos()
if X[0] < mousePos[0] < X[1] and Y[0] < mousePos[1] < Y [1]:
button.doAction(screen)

pygame.display.flip()

pygame.quit()

因此,如果我们说我们想要的函数是 playGame.levelChoose() - 请记住,这是 [submodule].[function] - 那么“child”中的循环将是:

def levelChoose(screen, playerData, playerName):
levelChooseRunning = True

while levelChooseRunning:
# --- Event Catching & Handling ---
for event in pygame.event.get():
# Quit PyGame safely upon exit
if event.type == pygame.QUIT:
levelMenuRunning = False

pygame.display.flip()

(当然,这些示例中省略了很多代码;如果您想拆开完整的文件,它们是 over here on GitHub )

如果还有其他问题,请告诉我,因为这可能会让您更加困惑......

关于python - Pygame 叠加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8378922/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com