【发布时间】:2011-10-10 00:09:07
【问题描述】:
我刚刚让一个精灵使用“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()
我是这个 python-pygame 世界的新手,在询问之前我已经检查了很多手册和文档,希望你能提供帮助,谢谢。
【问题讨论】: