我试图使用键盘箭头移动屏幕左右两侧的文本,但无法使其工作。我的代码是:
while True :
font = pygame.font.SysFont("Times New Roman", 20) # Font type # Font style
frame = pygame.display.set_mode ((Renderer.CANVAS_WIDTH, Renderer.CANVAS_HEIGHT))
frame.fill ((49,33,148))
for event in pygame.event.get ():
if event.type == QUIT :
pygame.quit ()
sys.exit ()
if event.type == pygame.KEYDOWN :
f = pygame.font.SysFont("Times New Roman", 20) # Font type # Font style
Track = font.render("Track : ", True, (255,255,0) )
Game ()
pygame.draw.rect(frame, (30,21,95),(50,400,700,170)) # draw a blue box on the screen
Track = font.render("Track : ", True, (255,255,0) )
frame.blit(Track,(80,410))
Labs = font.render ("Labs :", True, (255,255,0))
frame.blit(Labs,(80,440))
Distance = font.render ("Distance :", True, (255,255,0))
frame.blit(Distance,(80,480))
pygame.display.update () # Update the screen
pygame.quit ()
quit ()
您应该使用此代码使用pygame在键盘上移动文本
不过,这只会在你按下按键时起作用,它不会让你按住它。要做到这一点有点复杂。参见:
^{pr2}$相关问题 更多 >
编程相关推荐