I am working on this simple game using pygame. I encountered this FPS thing using clock.tick() but I don't really understand it. If I have the line "clock.tick(45)", I press and hold the right arrow key, my spaceship will be moving smoothly toward the edge of the app but when I don't have that piece of code, I press the right arrow only once, my spaceship will go all the way to my application's edge without smooth movement. Can anyone explain why is it so? Thank you
`
import pygame
from Enemy import Enemy
from Spaceship import Spaceship
pygame.init()
TITLE = "GAME"
SCREEN_WIDTH = 400
SCREEN_HEIGHT = 500
SPACESHIP_X = 0
SPACESHIP_Y = 400
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption(TITLE)
background = pygame.image.load("images\\spaceBackground.jpg").convert()
running = True
spaceShip = Spaceship()
def draw_window_and_object():
screen.blit(background, (0,0))
screen.blit(spaceShip.spaceShipObject, (SPACESHIP_X, SPACESHIP_Y))
pygame.display.update()
def handle_movement(keys):
global SPACESHIP_X
if keys[pygame.K_RIGHT] and SPACESHIP_X < SCREEN_WIDTH - 50:
SPACESHIP_X += 10
if keys[pygame.K_LEFT] and SPACESHIP_X > 0:
SPACESHIP_X -= 10
clock = pygame.time.Clock()
while running:
clock.tick(50)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
keys_pressed = pygame.key.get_pressed()
handle_movement(keys_pressed)
draw_window_and_object()
pygame.quit()
`