作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个简单的游戏,我希望我的鼠标点击(按钮无关紧要)每次点击只注册一次。现在即使按住它也能工作。
def drawer(x, y):
pygame.draw.circle(screen, (0, 0, 0), [int(x), int(y)],20)
def main():
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
exit()
if event.type == pygame.MOUSEBUTTONDOWN:
playerY_change = -player.vy
if event.type == pygame.MOUSEBUTTONUP:
playerY_change = player.vy
player.y += PlayerY_change
drawer(player.x, player.y)
# Other game code
pygame.display.update()
现在,只要您按住按钮,我希望它仅在每次单击时更改,玩家的运动就会不断变化。我该怎么做?
最佳答案
曾经playerY_change
设置后,玩家连续移动。因此不要设置playerY_change
,但更改 player.y
当您用鼠标单击时:
def main():
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.MOUSEBUTTONDOWN:
player.y -= player.vy
drawer(player.x, player.y)
# Other game code
pygame.display.update()
pygame.quit()
exit()
关于python - 如何让pygame只识别一次鼠标点击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67265064/
我是一名优秀的程序员,十分优秀!