I have a problem moving the objects continuously while pressing a key.
As far as I know, pygame events only trigger when receiving a new signal and that the key pressed is not a signal that continues with every frame. From the code below, when I press w for example, the object only moves when pressing and when releasing the key. I can't achieve the object to move as long as I keep pressing the key. I've also tried out the if statements by checking event.key instead of checking the get_pressed() list, but I came up with the same result.
while not crashed:
for event in pygame.event.get():
if event.type == pygame.QUIT:
crashed = True
keys = pygame.key.get_pressed()
print(keys[pygame.K_w])
if keys[pygame.K_w] and keys[pygame.K_d]:
x_change = 3
x += x_change
y_change = -3
y += y_change
elif keys[pygame.K_w] and keys[pygame.K_a]:
x_change = -3
x += x_change
y_change = -3
y += y_change
elif keys[pygame.K_s] and keys[pygame.K_d]:
x_change = 3
x += x_change
y_change = 3
y += y_change
elif keys[pygame.K_s] and keys[pygame.K_a]:
x_change = -3
x += x_change
y_change = 3
y += y_change
elif keys[pygame.K_a]:
x_change = -3
x += x_change
elif keys[pygame.K_d]:
x_change = 3
x += x_change
elif keys[pygame.K_w]:
y_change = -3
y += y_change
elif keys[pygame.K_s]:
y_change = 3
y += y_change
#ERASE OLD
screen.fill(WHITE)
#FILL NEW
all_sprites_list.draw(screen)
wall.changePosition(x,y)
player.draw(start_x,start_y)
pygame.display.update()
clock.tick(60)