User avatar
Posts: 1253
Joined: Sun Mar 17, 2013 6:03 am
Location: NOIDA, India
Contact: Website

pygame code optimisation help

Sun Sep 18, 2016 4:16 pm

I wrote a very basic code in pygame for an "In home Infotainment" application. For some reason the code runs very heavily on my PC and lags too much on my Raspberry Pi 3. I've seen other pygame apps run very smoothly.
Can some one help me optimise the code.
My apologies for shameless YouTube Plugs...
twitter @sahajsarup
skype srics1996

Sleep Mode zZ
Posts: 319
Joined: Sun Aug 19, 2012 5:56 am
Location: Finland

Re: pygame code optimisation help

Sun Sep 18, 2016 5:48 pm

Pygame is usually (and recommended to) run without hardware acceleration. That means that it is slow and to make it workable, you should restrict all unnecessary drawing (blitting etc.) and updating of the screen.

The cost of these procedures (at least of drawing and updating, I haven't actually tried blitting) is directly proportional to the amount of pixels that you are manipulating. Draw only what you need to draw (or blit) and update only those parts of the screen, not the whole screen. (Keep a list of "dirty" rectangles, i.e. rectangles where you have made changes in the last frame, and give that list to the update() call as an argument. IIRC.)

Return to “General discussion”