I am trying to make a game in python with pygame and I can pretty much do it exept when I move the image using the arrow keys it sometimes becomes jerky and it jumps pixels instead of moving one pixel at a time.
I would really appreciate it if someone could help me.
Here is my code.
import pygame, sys
clock = pygame.time.Clock()
#Variables
isPlaying = True
windowSize = [600, 400]
playerLocation = [50, 50]
movingUp = False
movingDown = False
#Window
window = pygame.display.set_mode(windowSize)
windowCaption = pygame.display.set_caption('Game')
display = pygame.Surface((300, 200))
#Images
playerImage = pygame.image.load('Data/Images/Player.png')
#Rects
playerRect = pygame.Rect(50, 50, playerImage.get_width(), playerImage.get_height())
#MainLoop
while isPlaying == True:
display.fill((255, 255, 255))
display.blit(playerImage, playerLocation)
if movingUp == True:
playerLocation[1] -= 4
if movingDown == True:
playerLocation[1] += 4
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_UP:
movingUp = True
if event.key == pygame.K_DOWN:
movingDown = True
if event.type == pygame.KEYUP:
if event.key == pygame.K_UP:
movingUp = False
if event.key == pygame.K_DOWN:
movingDown = False
surf = pygame.transform.scale(display, windowSize)
window.blit(surf, (0, 0))
pygame.display.update()
clock.tick(60)
By the way I'm on raspberry pi.