Answer the question
In order to leave comments, you need to log in
Why doesn't the pygame.display.update() function update my screen?
I am writing a primitive game and at the end of the main loop, as expected, I update the screen with the function pygame.display.update()
, but the screen is not updated until I start to move the mouse cursor over the window or move part of the window out of the monitor area. What is the problem?
the code itself:
from entity import *
from cfg import *
pygame.display.set_caption('runner')
player = player()
clock = pygame.time.Clock()
FPS = 60
clock.tick(FPS)
pygame.init()
pygame.display.set_caption('runner')
def main():
run = True
while run:
for e in pygame.event.get():
if e.type == pygame.QUIT:
run = False
display.fill((100, 100, 100))
player.render()
player.move()
pygame.display.update()
if __name__ == '__main__':
main()
from cfg import *
class player:
def __init__(self, posX=50, posY=50, size=20, moveSpeed=5, motion='none'):
self.posX = posX
self.posY = posY
self.size = size
self.moveSpeed = moveSpeed
self.motion = motion
def move(self):
motion = 'none'
for e in pygame.event.get():
keys = pygame.key.get_pressed()
if keys[pygame.K_UP or pygame.K_w]:
motion = 'up'
if keys[pygame.K_DOWN or pygame.K_s]:
motion = 'down'
if e.type == pygame.KEYUP:
motion = 'none'
if motion == 'up':
if self.posY >= self.size * 2:
self.posY -= self.moveSpeed
elif motion == 'down':
if self.posY <= screenHeight - self.size * 2:
self.posY += self.moveSpeed
def render(self):
pygame.draw.circle(display, (255, 255, 255), (self.posX, self.posY), self.size)
import pygame
screenWidth = 600
screenHeight = 300
display = pygame.display.set_mode((screenWidth, screenHeight))
Answer the question
In order to leave comments, you need to log in
Why is there no cycle.
it doesn't work for this reason
Check out this course.
https://younglinux.info/pygame
You need to loop control, update and render.
And if you are a fan of video courses))
I can recommend Gosha the Dudar's pygame course.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question