A
A
Afafks1231321321652020-03-16 15:48:07
Python
Afafks123132132165, 2020-03-16 15:48:07

Why is pygame unstable?

When I change the time delay , the player starts to move slower or faster. But that's okay, he trembles and somehow jerks around. What to do?

import pygame

pygame.init();
win = pygame.display.set_mode((320,320));
pygame.display.set_caption("Game")

x = 144
y = 144
width = 32
height = 32
speed = 5

run = True

while run:
  pygame.time.delay(20)
  for event in pygame.event.get():
    if event.type == pygame.QUIT:
      run = False
  keys = pygame.key.get_pressed()
  if keys[pygame.K_UP]:
    y-=speed
  if keys[pygame.K_LEFT]:
    x-=speed
  if keys[pygame.K_RIGHT]:
    x+=speed
  if keys[pygame.K_DOWN]:
    y+=speed
  win.fill((0,0,0))
  pygame.draw.rect(win, (0,0,255), (x,y,width,height))
  pygame.display.update()	
pygame.quit()

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question