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)
Delete the lines
and the first occurence of
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:
Example code: