【发布时间】:2023-03-28 12:20:01
【问题描述】:
我正在尝试在我的游戏 SpaceInvaders 中添加一个暂停菜单,游戏的最后一帧在后台,但是当我加载暂停场景时,我的游戏没有在后台显示游戏
the background game looks like this
the first time I load pause it shows this
and then whenever i load pause it behaves normally like this
我的游戏有 3 个文件:
1)游戏文件
2)暂停文件
3)init文件(连接以上两个)
游戏文件
import pygame
from __init__ import __INIT__
pygame.display.set_caption("Endless")
pygame.init()
screen=pygame.display.set_mode((1920/2,1080/2),pygame.RESIZABLE)
def menu():
running=True
while running:
screen.blit(pygame.image.load("docs/bg.png"),(0,0))
for event in pygame.event.get():
if event.type==pygame.QUIT:
running=False
pygame.quit()
quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
__INIT__("pause")
pygame.display.update()
menu()
暂停文件
import pygame
from __init__ import __INIT__
pygame.display.set_caption("Pause")
pygame.init()
screen=pygame.display.set_mode((1920/2,1080/2),pygame.RESIZABLE)
def PAUSE():
running=True
while running:
for event in pygame.event.get():
if event.type==pygame.QUIT:
running=False
pygame.quit()
quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
__INIT__("menu")
if event.key == pygame.K_h:
from __init__ import hello
hello()
screen.blit(pygame.image.load("docs/D_effect.png"),(0,0))
pygame.display.update()
PAUSE()
初始化文件
def __INIT__(a):
if a=="pause":
from pause import PAUSE
PAUSE()
if a=="menu":
from endless import menu
menu()
我不知道是什么导致了这个问题,因为它只会在我是初学者的时候出现一次。如果发生这种情况,我很抱歉
无论如何,如果你觉得我的问题难以理解,请运行 Space_invaders/Space_invaders/endless.py 中的无尽文件 此处提供 https://drive.google.com/file/d/1FUhGNdXp4CgYcr9PAfey-6ElZhVYMKem/view?usp=sharing
【问题讨论】:
标签: python python-3.x pygame