-3

I am making a game for A-Level Computer Science and I'm in the early stages, I am finding that blitting things to the screen really slows the program down. My full code is here and due to the fact that there is nothing running in the background yet apart from working with images and such, the game really shouldn't be as choppy as it is. my question is how can I make my code run faster?

Thanks

Thomas Ayling
  • 95
  • 2
  • 10
  • I was wondering.. you have clock.tick(480) - what kind of monitor do you have which allows for a frame rate of 480? => in 2017 the first 480Hz monitors were only prototypes... – Cribber Jul 13 '18 at 10:39
  • That was just me trying to increase the fraps haha, I have a 120Hz monitor – Thomas Ayling Jul 13 '18 at 10:41
  • What kind of FPS do you achieve at the moment? And what number do you want to achieve? – Cribber Jul 13 '18 at 10:42
  • With the code on the GitHub post it was about 20fps probably less but I've sped it up considerably, I'll update the repo later it's about 40fps now – Thomas Ayling Jul 13 '18 at 10:43

1 Answers1

1

Tips:

  • One bottleneck in pygame is actually font rendering. You should not render the same text (with the same font/color) more than once but rather cache the surfaces once rendered and reuse them.
  • If you're using Python 2, you can use Psyco for rendering and double buffering. Stack Link
Mert Karakas
  • 178
  • 1
  • 4
  • 22