파이 게임에서 슈팅 게임을 만들고 있지만이 코드는 다음과 같습니다.
checkfocus = pygame.key.get_focused()
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
#THIS PART DOES NOT WORK
if event.type == pygame.K_w:
print(checkfocus)
print("up")
pygame.key.set_repeat(0, 1)
yvalue -= 20
if yvalue < 0:
yvalue = 0
print(yvalue)
pygame.time.wait(100)
screen.fill((52, 61, 82))
screen.blit(harryshoot, (20, yvalue))
pygame.display.flip()
다른 if event.type
코드 가 잘 작동 함에도 불구하고 어떻게 든 작동하지 않습니다 . 여기서 문제는 무엇입니까? 키보드 입력을받지 못하는 것은 왜이 코드뿐입니까? 키 변경을 시도했지만 도움이되지 않았습니다. ( print("up")
또한 표시되지 않으므로 작동하지 않는 코드 자체가 아닙니다).
pygame.K_w
이벤트 유형이 아니라 키입니다. 이벤트 유형이 pygame.KEYDOWN
이고 키가 pygame.K_w
다음 과 같은지 확인해야합니다 .
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key== pygame.K_w:
# [...]
키보드 이벤트 KEYDOWN
및 KEYUP
( pygame.event 모듈 참조 ) pygame.event.Event
추가 속성이 있는 개체를 만듭니다 . 눌러 진 키가로부터 얻어 질 수 key
속성 (예를 들어 K_RETURN
, K_a
) 및 mod
속성은 부가 개질제 (예와 비트 세트를 포함 KMOD_LSHIFT
). 이 unicode
속성은 키보드 입력의 유니 코드 표현을 제공합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다