简体   繁体   中英

How do I make it so that when I press a key an image pops up and stays there until i let go?

I am basically trying to do what the question says but its not happening. Can anyone explain why?

    if event.type == pygame.KEYDOWN:
    keys = pygame.key.get_pressed()
    if keys[pygame.K_w]:
        screen.blit(player_1, [170, 333])
    if keys[pygame.K_d]:
        screen.blit(player_1, [331, 500])
    if keys[pygame.K_s]:
        screen.blit(player_1, [170, 665])
    if keys[pygame.K_a]:
        screen.blit(player_1, [10, 500])
    if keys[pygame.K_UP]:
        screen.blit(player_2, [195, 333])
    if keys[pygame.K_RIGHT]:
        screen.blit(player_2, [356, 500])
    if keys[pygame.K_DOWN]:
        screen.blit(player_2, [196, 665])
    if keys[pygame.K_LEFT]:
        screen.blit(player_2, [35, 500])

Instead of holding your key down. Try using a Boolean statement bonded to the key you want to pop up an image. Would look something similar to this

 Keys[pygame.K_UP] = false
    If Keys[pygame.K_UP] == true:
         Print "(insert image url here)"
         Else
                (Do nothing) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM