Using Pygame with PyPy

I am very new to python, but I would like to learn it by making games and pygame perhaps the best option. Since PyPy is the fastest python implementation (I think), I decided to use it. But I do not know how to make these two work together.

I'm on the windows.

If someone would be so kind as to give me step by step what I need to do, I would be very grateful.

So far I have installed (extracted to a folder) PyPy, set pypy.exe as the default value for opening .py files, installed Pygame and tried to run one of the example .py files. I get a "pygame not found" error with the first import line in the file.

+5
source share
2 answers

pygame is not compatible with pypy , so you will have to stick with cPython to use it.

+7
source

Pygame games actually spend very little time running python code. The vast, vast majority is spent on SDL fill and flip operations. Most fill not needed. How important is it? Well, take my computer. Let's say you are writing a game in which there is a loop that simply draws the background in one color. It will receive about 40 frames per second. This is because it is mainly suitable for each pixel individually and is written to it. This uses 200 x 300 = 60,000 operations per frame to do nothing.

So, instead of painting the whole background, just draw the parts that were drawn on the previous frame.

This makes your code a bit more complex, but it gives a huge increase in performance.

Also, be sure to run cProfile to find out where the problem areas are. Look, don't guess.

+4
source

Source: https://habr.com/ru/post/947984/


All Articles