pygame.key.get_pressed() is not working

前端 未结 4 595
失恋的感觉
失恋的感觉 2020-12-11 17:38

I\'ve read similar questions to this on Stack Overflow but they have not helped. Here is my code:

import pygame
from pygame.locals import *

pygame.init()
sc         


        
4条回答
  •  半阙折子戏
    2020-12-11 17:55

    May I suggest using an event que instead? It's probably a better idea:

    while True: #game loop
        for event in pygame.event.get(): #loop through all the current events, such as key presses. 
            if event.type == QUIT:
                die()
    
            elif event.type == KEYDOWN:
                if event.key == K_ESCAPE: #it's better to have these as multiple statments in case you want to track more than one type of key press in the future. 
                    pauseGame()
    

提交回复
热议问题