擅长:python、mysql、java
<p>我不认为pygame会错过一个关键事件。在</p>
<p>我认为问题是你没有在任何地方设置<code>isJumping</code>为false,这会在第一次按下后永远停止{<cd2>}的更改。如果我正确地解释了这一点,以下代码应该可以工作:</p>
<pre class="lang-py prettyprint-override"><code>if event.type == pygame.KEYDOWN:
... # Your other code
if event.key == pygame.K_UP and not isJumping: # "== False" is not necessary
yChange -= 10
isJumping = True
if event.type == pygame.KEYUP:
... # Your other code
if event.key == pygame.K_UP and isJumping:
yChange = 0
isJumping = False # < This is the addition to the code
</code></pre>
<p>有一件事要记住,这个跳跃系统看起来不是很自然。关于这一点,请看@SamHolloway的回答。在</p>