|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
小甲鱼老师在讲Pygame事件中说并且示例:按下之后松开A、B、C、D等按键会且仅会出现KeyDown和KeyUp
("如果我们按下字母h不动,他就会只有keydown"——小甲鱼老师)
但在我这边出现了这样一种情况
(不知道为什么我电脑不能传图片,所以下面是照着图片输入的内容。源码是小甲鱼老师在课上讲的“黑客帝国”的示例)
<Event(768-KeyDown{'unlcode':'s','key':115,'mod':4096,'scancode':22,'window':None})>
<Event(771-TextInput{'text':'s','window':'None'})>
<Event(771-TextInput{'text':'s','window':'None'})>
<Event(771-TextInput{'text':'s','window':'None'})>
<Event(771-TextInput{'text':'s','window':'None'})>
<Event(771-TextInput{'text':'s','window':'None'})>
<Event(771-TextInput{'text':'s','window':'None'})>
<Event(771-TextInput{'text':'s','window':'None'})>
<Event(769-KeyUp{'unlcode':'s','key':115,'mod':4096,'scancode':22,'window':None})>
电脑会一直出现textinput
- import pygame
- import sys
- pygame.init()
- size = width, height = 600, 400
- screen = pygame.display.set_mode(size)
- pygame.display.set_caption('FishC Demo')
- bg = (0, 0, 0)
- position = 0
- font = pygame.font.Font(None, 20)
- line_height = font.get_linesize()
- screen.fill(bg)
- while True:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- sys.exit()
- screen.blit(font.render(str(event), True, (0, 255, 0)), (0, position))
- position += line_height
- if position > height:
- position = 0
- screen.fill(bg)
- pygame.display.flip()
复制代码 |
|