Page 1 of 1

Help with Issue 71, 'Getting Started With Pygame Zero', pp52-57

Posted: Sun Mar 31, 2019 8:07 pm
by BMardle
Hello, everyone.
I've been reading the article on Pygame Zero in issue 71, which describes how to make a very simple driving game. It works fine under Windows 7, taking about 40 seconds to win a game, but on my Raspberry Pi 2 the game gets slower and slower as it runs, taking about 114 seconds to win a game. Any idea how to fix it?
My Pi 2 is running Stretch and I updated everything that could be updated.
Oh... it occurred to me that the slowdown might be because there are an every-increasing number of images drawn (the barriers on the sides of the track), but I tried tweaking the code to only draw barriers that are on the screen. That didn't make much difference.

Re: Help with Issue 71, 'Getting Started With Pygame Zero', pp52-57

Posted: Mon Apr 01, 2019 11:58 am
by MarkyV
Hi,

It is as you suspect the growing number of actors being processed. I didn't put any culling code in as it would have made it too complicated as a starter program - but you could re-use the actors as they disappear off the screen then the maximum number being processed would remain constant.

Mark

Re: Help with Issue 71, 'Getting Started With Pygame Zero', pp52-57

Posted: Wed Apr 03, 2019 12:18 pm
by BMardle
I've largely solved the problem. It was the checks on whether the car had collided with the barriers that was the main culprit. Once I changed the code so it only checked for collisions with barriers on the screen, the frame rate at the end of the game went up from 11fps to 50fps!

This makes me wonder 2 things:

If the frame rate of a program using Pygame Zero varies a lot, wouldn't it be better to specify the speed of things in pixels per second (rather than pixels per frame)?

Is there a profiler for Python?