我读了关于这个问题的其他文章,但我仍然不明白。我只想让我的按钮在按下一次的时候执行,而不是在我必须按下它的时候。我有一个while循环中的按钮,第一次运行良好,但第二次就不工作了。我的密码在这里。感谢您的帮助,因为我的代码写得很差,因为我是新来的,这是很难理解的任何人除了我。在
def newRound():
pos = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
print(click)
if 730 < pos[0] < 850 and 650 < pos[1] < 800:
pygame.draw.rect(Background, (150,150,150), (730,650,120,50))
if click[0] == 1:
startGame()
while intro == 1:
if endRound == True:
Background.blit(mapImg, (0,0))
newRound()
text()
if startRound == True:
for enemy in enemies:
enemy.update()
Background.blit(mapImg, (0,0))
for enemy in enemies:
enemy.draw(Background)
包含不重要位的完整代码
^{pr2}$
你的按钮可以用。。。但你在移动敌人时遇到了问题,而且按钮似乎不起作用。在
你移动敌人直到你得到},所以
hit == 6
,当你再次点击按钮时,hit
已经是{hit == 6
结束移动敌人,你看不到它。在所以你需要
或者使用不同的元素来检查何时结束圆。在
当你结束移动敌人时,你不会将他们从列表中移除
^{pr2}$enemies
,当你再次点击按钮时,你会向列表中添加新的敌人,并且你的列表上有越来越多的敌人。检查len(enemies)
。也就是说所以在你再次使用它之前,先把它列清楚
顺便说一句:你可以用
intro = True
代替intro = 1
。和while intro:
而不是while intro == 1:
。它更具可读性。在相关问题 更多 >
编程相关推荐