我想創建一個函數,如果按下某個鍵,變量就會改變。這將被放入一個在屏幕上移動精靈的類。當釋放按鍵時,while循環被打破。然而,沒有任何反應。 while循環正在運行,我沒有錯誤。有誰知道爲什麼會發生這種情況?我不確定我是否正確使用模塊「pygame.key.get_pressed()」。python's'pygame.key.get_pressed()'模塊沒有識別按鍵
import pygame
from pygame.locals import *
def move():
for event in pygame.event.get():
if event.type == QUIT:
pygame.QUIT()
sys.exit()
while True:
pressed = pygame.key.get_pressed()
if pressed[pygame.K_UP]:
print("something happens")
#runs this, but when up arrow key is pressed does nothing
if event.type == KEYUP:
False
screen = pygame.display.set_mode((512,384))
move()
pygame.display.update()
'get_pressed()'如果你不執行'pygame.event.get(不工作)' - 但你執行'pygame.event.get( )'只有一次。 – furas