[英]Pygame event not working
This is my code I have for a game I am making and I manage to get the first text written to the screen then it manages to print the events but it won't run the second part of the code. 这是我对我正在制作的游戏的代码,我设法将第一个文本写入屏幕,然后它设法打印事件,但它不会运行代码的第二部分。 I am assuming that
if event.type == pygame.K_RETURN:
doesn't work. 我假设
if event.type == pygame.K_RETURN:
不起作用。 I am either doing something wrong or it's not working. 我要么做错了,要么就是不行。
while True:
for event in pygame.event.get():
#print(event)
if event.type==pygame.KEYDOWN:
print("key pressed")
if event.type == pygame.K_RETURN:
print(event)
print("enter key pressed")
screen.fill(blue)
textSurf, textRect = text_objects(t2, smallText)
textRect.center = ((700),(100))
screen.blit(textSurf, textRect)
pygame.display.update()
pygame.display.update()
Yes, if event.type == pygame.K_RETURN:
should be if event.key == pygame.K_RETURN:
. 是的,
if event.type == pygame.K_RETURN:
if event.key == pygame.K_RETURN:
.
The pygame.KEYDOWN
and pygame.KEYUP
event types have a key
attribute that is used to check which key was pressed. pygame.KEYDOWN
和pygame.KEYUP
事件类型有一个key
属性,用于检查按下了哪个键。
You can find a list of event types and their attributes in the docs: http://www.pygame.org/docs/ref/event.html 您可以在文档中找到事件类型及其属性的列表: http : //www.pygame.org/docs/ref/event.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.