2
방금 "w, a, s, d"를 사용하여 창 주위를 돌아 다니는 스프라이트가 생겼습니다. 스페이스 바를 눌러이 스프라이트를 "촬영"하고 싶습니다.파이 게임에서 키 이벤트가있는 스프라이트 이동하기
문제는 내가 스페이스 바를 놓을 때까지 스프라이트가 나타나지만 움직이지 않는다는 것입니다. 스프라이트 샷은 스페이스 바를 누르기 만하면 창 끝까지 전진합니다. 그것을 공개하지 말라.
이 내 메인 루프입니다 :
while pygame.event.poll().type != QUIT:
screen.blit(background, (0, 0))
#"player" is the sprite moving around the window
player.move(width,height)
screen.blit(player.image, player.rect)
key = pygame.key.get_pressed()
if key[K_SPACE]:
xpos = player.rect.right
ypos = player.rect.top
shot_on_screen = True
if shot_on_screen:
xpos += 1
#"kame" is the sprite i want to move forward
screen.blit(shot.kame, (xpos, ypos))
else:
shot.x = player.rect.right
shot.y = player.rect.top
shot_on_screen = False
pygame.display.update()
나는이 파이썬 - 파이 게임의 세계에 새로운 해요, 난 그래도 요청하기 전에 매뉴얼 및 문서를 많이 확인했지만, 당신이 도움이 될 수 있습니다 감사하겠습니다.
감사합니다. "ypos = player.rect.top"을 제거해 주셔서 감사합니다. 문제가 해결 되었으니 이제는 분명히 xD였습니다. – Castell