1 回答
TA贡献1871条经验 获得超13个赞
Pygame 从来没有该game.controls()函数的任何事件,因为它们都被主循环中的子句消耗掉了。
def main():
game = game_func()
while True:
for event in pygame.event.get(): # CONSUME EVERY EVENT
if event.type == pygame.QUIT:
end()
game.blit()
game.controls() # NO EVENTS LEFT FOR THIS
也许如果事件不是pygame.QUIT,则将其传递给game.controls(). 例如:
def main():
game = game_func()
while True:
game.blit()
for event in pygame.event.get():
if event.type == pygame.QUIT:
end()
else:
game.controls( event )
和控制是:
class game_func:
...
def controls(self, event):
if event.type == pygame.KEYDOWN:
self.input = True
添加回答
举报