0

What is wrong with my game??

Here is my game code in pygame and I don't know why when I press the left or right arrow the sprite doesn't move. Please help!!!!! import pygame pygame.init() w = 1000 h = 1000 all_sprites = pygame.sprite.Group() bg = pygame.image.load(r'/Users/lanik2009/Downloads/sky (1).png') sprite = pygame.image.load(r'/Users/lanik2009/Downloads/p1_jump.png') rect = sprite.get_rect() speedx = 0 screen = pygame.display.set_mode((w, h)) pygame.display.set_caption('My game') screen.blit(bg, (0,0)) screen.blit(sprite, (500,900)) control = pygame.key.get_pressed() if control[pygame.K_LEFT]: speedx = -5 if control[pygame.K_RIGHT]: speedx = 5 rect.x += speedx running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False pygame.quit() quit() pygame.display.update()

23rd Apr 2021, 12:06 AM
Ailana
Ailana - avatar
1 Antwort
0
There is some code, which is supposed to be included in the loop, but isn't.
23rd Apr 2021, 6:14 AM
Seb TheS
Seb TheS - avatar