I'm coding something with pygame but my screen doesn't update with pygame.display.flip() Can someone help me please ?
My code : Main file :
import pygame
pygame.init()
from game import Game
pygame.display.set_caption("Run !")
screen = pygame.display.set_mode((1080, 680))
game = Game()
running = True
while running:
game.update(screen)
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
elif event.type == pygame.KEYDOWN:
game.key_pressed[event.key] = True
elif event.type == pygame.KEYUP:
game.key_pressed[event.key] = False
Game file :
import pygame
from player import Player
class Game(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
self.player = Player()
self.key_pressed = {}
def update(self, screen):
screen.blit(self.player.image, self.player.rect)
if self.key_pressed.get(pygame.K_RIGHT):
self.player.move_right()
if self.key_pressed.get(pygame.K_LEFT):
self.player.move_left()
if self.key_pressed.get(pygame.K_UP):
self.player.move_up()
if self.key_pressed.get(pygame.K_DOWN):
self.player.move_down()
pygame.display.flip()
And the player file :
import pygame
class Player(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
self.velocity = 3
self.image = pygame.image.load('res/player.png')
self.image = pygame.transform.rotozoom(self.image, 0, 0.9)
self.rect = self.image.get_rect()
def move_right(self):
self.rect.x += self.velocity
def move_left(self):
self.rect.x -= self.velocity
def move_up(self):
self.rect.y -= self.velocity
def move_down(self):
self.rect.y += self.velocity
I can see the player move (it is a blue square), but the previous image isn't deleted. So I see a blue line instead of a square when it moves
Thank you very much !