C
C
coi17512019-01-03 16:22:34
Python
coi1751, 2019-01-03 16:22:34

How to optimize rendering in pygame (Python)?

The idea is this, there is an image of 8k pixels long, in the future the camera will move with the character, until it did, but faced the problem of poor performance. Redrawing the whole picture 60 times per second is pretty fat. How in pygame to implement drawing only a certain part of the screen where changes occur?
To advisers: "just put display.update() out of the loop", if you do this, then we will play the Windows 2007 lag game. The background will not be updated, but the character will, as a result, we draw our character ..

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
rPman, 2019-01-03
@coi1751

Firstly, in the vast majority of cases, 99% of the programmer's work (drawing, organizing the game loop, etc.) is taken over by the game engine/framework. But you are great that you are probably trying to do everything yourself from scratch.
You should have a game world rendering loop, and a properly organized world that, if possible, should not depend at all on whether the rendering succeeds or not. The rendering cycle should try to draw the next frame, make some optimizations for rendering the next one (there are even preparations a few frames ahead, it’s difficult, sometimes you have to resolve lags but increase the smoothness of the graphics), then, if the elapsed time turned out to be less than the time allotted for one frame ( so that it is 30/60fps or whatever you want), waits for the remaining time on pause (works out the game loop for a single-threaded implementation), and everything repeats.
Do not load the processor in vain. Let the video card (relevant libraries and frameworks) be responsible for the graphics, because while you are drawing sprites over each other, copying blocks of RAM, the video card will do all this in parallel, efficiently, and most importantly more convenient. Plus, the video accelerator is already almost in refrigerators, i.e. in every modern processor - desktops, mobiles, game consoles ...
ps not to you personally, but in general:
our poor world, 10-20 years ago, gamedev solved level issues, how to optimize the division function so that the sprite drawing method had time to work out before the return of the crt beam of the monitor ... and now The tasks that a programmer starts with are which constructor/framework to choose and how to turn/configure it so that little men appear on the screen and become a game, without even trying to figure out how it works inside.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question