按键事件没有被拾取

时间:2019-05-13 06:12:00

标签: python pygame

ship.movi​​ng标记没有设置为True,是否没有敲击键盘?

import sys
import pygame

def check_events(ship):
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()

        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_RIGHT:
                ship.moving_right = True
            elif event.key == pygame.K_LEFT:
                ship.moving_left = True


        elif event.type == pygame.KEYUP:
            if event.key == pygame.K_RIGHT:
                ship.moving_right = False
            elif event.key == pygame.K_LEFT:
                ship.moving_left = False

在按下右侧的同时,ship.movi​​ng_right应该设置为true。 反之亦然。

0 个答案:

没有答案