Python 我的比赛赢了';当我使用控件时无法工作,如何修复它?
我无法让控件工作,我尝试按escape打开我制作的菜单,但它不会打开,我不知道我是否正确地检查事件,有什么方法可以这样做吗 我尝试使用这些函数检查不同的键,并转到显示所有事件名称的电子表格,以便您可以在pygame.org上映射它们,但当我使用escape或也称为:Python 我的比赛赢了';当我使用控件时无法工作,如何修复它?,python,python-3.x,pygame,Python,Python 3.x,Pygame,我无法让控件工作,我尝试按escape打开我制作的菜单,但它不会打开,我不知道我是否正确地检查事件,有什么方法可以这样做吗 我尝试使用这些函数检查不同的键,并转到显示所有事件名称的电子表格,以便您可以在pygame.org上映射它们,但当我使用escape或也称为: elif event.type == pygame.K_ESCAPE: Frame.blit('Textures/GUI/loom.png', (0,0)) 以下是完整的代码: import pygame #Textur
elif event.type == pygame.K_ESCAPE:
Frame.blit('Textures/GUI/loom.png', (0,0))
以下是完整的代码:
import pygame
#Textures/Blocks/loom_side.png
pygame.init()
Screen = "None"
DB = 0
Width = 800
Height = 600
Frame = pygame.display.set_mode((Width,Height))
pygame.display.set_caption("HypoPixel")
FPS = pygame.time.Clock()
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('Textures/Screens/Skybox/Earth.png',0,0,800,600)
while Loop == True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()
elif event.type == pygame.K_ESCAPE:
Frame.blit('Textures/GUI/loom.png', (0,0))
pygame.display.update()
FPS.tick(60)
我希望得到我制作的织布机GUI。当我尝试按escape时,什么也没发生。
pygame.K_escape
不是事件类型(请参阅),但它是一个事件类型
首先,通过将事件类型与pygame.KEYDOWN进行比较,检查是否按下了某个键:
event.type==pygame.KEYDOWN
然后检查导致该事件的event.key
是否为pygame.K_ESCAPE
键:
event.key==pygame.K\u ESCAPE
此外,要使用的参数必须是曲面
对象,而不是文件名
首先通过将图像加载到曲面
,然后通过blit
将图像加载到曲面
:
sprite=pygame.image.load('Textures/GUI/lome.png')
帧blit(雪碧,(0,0))
当然,可以调用yourRaycast
函数来执行此操作:
Raycast('Textures/GUI/loom.png',0,0800600)
您的代码应该是这样的:
while循环==True:
对于pygame.event.get()中的事件:
如果event.type==pygame.QUIT:
退出()
elif event.type==pygame.KEYDOWN和event.key==pygame.K_转义:
Raycast('Textures/GUI/loom.png',0,0800600)
谢谢,这帮了大忙!另外,关于在blit中创建一个新精灵的部分实际上是由我的Raycast函数定义的!但再次感谢你的帮助