Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7727807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:33:20+00:00 2026-06-01T05:33:20+00:00

How would i add key commands to the sprite plumbers? Below is my attempt

  • 0

How would i add key commands to the sprite plumbers? Below is my attempt so far but there is no outcome when pressing the up button. How would i set ud, and ld to change by 10 when button up button is pressed?

pink = (255, 64, 64)
w = 640
h = 480
ld = 0
ud = 0
screen = pygame.display.set_mode((w, h))
running = 1
def key_event(self, event):

         if event.key == pygame.K_UP:
             ud - 10
             ld  + 10
def show_sprites():
    screen.blit(plumbers,(50+ld ,100+ud ))
def setup_background():
    screen.fill((pink))
    screen.blit(cloud_background,(0,0))
    brick_width, brick_height = brick_tile.get_width(), brick_tile.get_height()
    for x,y in itertools.product(range(0,640,brick_width),
                                 range(390,480,brick_height)):
        screen.blit(brick_tile, (x,y))

 while running:

    setup_background()
    event = pygame.event.poll()
    show_sprites()
    pygame.display.flip()

  if event.type == pygame.QUIT:
        sys.exit()
    for event in pygame.event.get():
         if event.type == pygame.QUIT:
             running = False
         elif event.type == pygame.KEYDOWN:
             w.key_event(event)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T05:33:22+00:00Added an answer on June 1, 2026 at 5:33 am

    Delete the lines

    event = pygame.event.poll()
    

    and the first occurence of

    if event.type == pygame.QUIT:
        sys.exit()
    

    The problem is that both poll and get take events off the event queue so you are losing the key up events in the call to poll.

    In other words what happens is:

    1. You press the UP key
    2. This inserts the KEYDOWN event into the queue
    3. you call event = pygame.event.poll()
    4. this returns the KEYDOWN event
    5. you check to see if this is QUIT, it is not so you continue
    6. you call pygame.event.get(), but the queue is now empty so the for loop does not get entered

    Example code:

    import pygame
    pink = (255, 64, 64)
    w = 640
    h = 480
    ud = 0
    ld = 0
    screen = pygame.display.set_mode((w, h))
    running = 1
    def key_event(event):
        global ud
        if event.key == pygame.K_UP:
            ud -= 10
            print 'ud',ud           
    
    def setup_background():
        screen.fill((pink))
    
    while running:
    
        setup_background()
        pygame.display.flip()
    
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                 running = False
            elif event.type == pygame.KEYDOWN:
                 key_event(event)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would I add key value pairs to the body of a NSMutableURLRequest? I
I'd like to write a gmail extension that would add a button on the
The title speaks for itself, but I would add some pointers I've noticed along
I would like to add Key bindings to my JFileChooser in order to open
I'm using Elmah with ASP.NET and wondering how I would add custom data, such
I thought every time you do a flash[:notice]=Message it would add it to the
I don't understand how using a 'challenge token' would add any sort of prevention:
I am wondering if anyone knows a java script library that would add a
I want to stringify a number and add zero-padding, like how printf(%05d) would add
How would I add together the values pulled from two separate jQuery.html() calls? Example:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.