почему я не получаю сообщение для печати? - PullRequest
0 голосов
/ 07 августа 2020
 while running:
        screen.fill((255,255,255))

        screen.blit(background,(0,0))   
        
        for event in pygame.event.get():

            if event.type == pygame.QUIT:
                running = False


# keystroke controlling   i am not getting this print message 

            if event.type == pygame.KEYDOWN:
                if event.type == pygame.K_SPACE:

                    print("space is pressed ")

            if event.type == pygame.KEYUP:

                if event.type == pygame.K_SPACE:

                    print("released")
                                 
        
        playerx += playerx_change
        player(playerx , playery)
        cactus(cactusx , cactusy)
        pygame.display.update()

game()

1 Ответ

2 голосов
/ 07 августа 2020

Это потому, что event.type не может быть одновременно KEYUP И K_SPACE. Перепишите код как:

            if event.type == pygame.KEYDOWN:

                if event.key == pygame.K_SPACE:

                    print("space is pressed ")

            if event.type == pygame.KEYUP:

                if event.key == pygame.K_SPACE:

                    print("released")
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...