python - 为什么我的解析器无法在不崩溃的情况下将精灵绘制到屏幕上?
问题描述
我正在使用光线投射开发一款名为 HypoPixel 的游戏,但我发现了另一个错误。我无法打开游戏,它只是崩溃,当我在 IDE 中使用它时,它不会出错。
我只是用了简单的
elif event.type == pygame.MOUSEBUTTONDOWN:
程序,但自从我添加这个程序以来它一直在崩溃
pygame.init()
Screen = "None"
Sobj = "None"
Width = 800
Height = 600
Time = 0
MouseX, MouseY = pygame.mouse.get_pos()
Frame = pygame.display.set_mode((Width,Height))
pygame.display.set_caption("HypoPixel")
FPS = pygame.time.Clock()
def button(DisplayText,ButtonPosition,Function):
pass
def mapX(MapXPos):
pass
def mapY(MapYPos):
pass
def mapZ(MapZPos):
pass
def ReDisplayItem():
if Sobj == "None":
Raycast('Assets/Textures/Extra/ItemBox.png',0,0,160,160)
elif Sobj == "Loom":
Raycast('Assets/Textures/Extra/IBO.png',0,0,160,160)
Raycast('Assets/Textures/Blocks/loom_side.png',10,10,140,140)
def Raycast(TTR, RayXPos, RayYPos, RaySizeX, RaySizeY):
RaycastThis = pygame.image.load(TTR)
RaycastThis = pygame.transform.scale(RaycastThis,(RaySizeX,RaySizeY))
Frame.blit(RaycastThis, (RayXPos, RayYPos))
Loop = True
Raycast('Assets/Textures/Screens/Skybox/Earth.png',0,0,800,600)
Raycast('Assets/Textures/Extra/ItemBox.png',0,0,160,160)
while Loop == True:
Time = Time + 1
while Sobj == "None":
RCT = 'Assets/Textures/Blocks/air.png'
while Sobj == "Loom":
RCT = 'Assets/Textures/Blocks/loom_side.png'
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()
elif event.type == pygame.MOUSEBUTTONDOWN:
Raycast(RCT,MouseX,MouseY,160,160)
elif event.type == pygame.KEYDOWN:
if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
exit()
elif event.type == pygame.KEYDOWN and event.key == pygame.K_0:
Raycast('Assets/Textures/Extra/ItemBox.png',0,0,160,160)
Sobj = "None"
elif event.type == pygame.KEYDOWN and event.key == pygame.K_1:
Raycast('Assets/Textures/Blocks/loom_side.png',10,10,140,140)
Sobj = "Loom"
if Time >= 2400 and Time < 4800:
Raycast('Assets/Textures/Screens/Skybox/EarthNight.png',0,0,800,600)
ReDisplayItem()
elif Time >= 4800:
Time = 0
Raycast('Assets/Textures/Screens/Skybox/Earth.png',0,0,800,600)
ReDisplayItem()
pygame.display.update()
FPS.tick(60)
我希望应用程序能够正常打开,并且新增了为我的游戏进行 Alpha 测试的绘制块的新功能,但它崩溃了,没有任何错误迹象。
解决方案
没关系,我意识到我必须使用
if
和
elif
而不是 while 循环,对于混乱的 Stack OverFlow 社区感到抱歉。:(
推荐阅读
- shell - 如何检索由 docker-compose.yml 启动的确切容器名称
- c# - ML.Net 无法从 MVC 项目的存储中加载模型
- javascript - 根据数组的元素从数组中提取元素
- python - Python MySQL 连接器:错误 #2003
- c++ - 何时使用 vkCmd* 函数的参数?
- firebase - React-Native Firebase 身份验证错误消息卡住直到第二次尝试
- android - 如何从 void 方法中使用 findViewById 获取 Recyclerview id
- c++ - 为什么函数返回不移动向量?
- python - 用于屏蔽 API 的多个页面的迭代器
- javascript - Fontawesome 图标文本出现而不是图标