[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] C/C++ and Python



Yanom Mobis kirjoitti:
I've heard some games are made with C/C++ and Python together. Where does Pygame fit into this?



Pygame is written in c, to wrap another c written library, SDL. Python itself is written in c too.

So in a way if you write a game using Python, using Pygame, your game is already using c & python together.

The idea is that the cpu intensive things, like in case of Pygame the drawing operations, are done in native code. So the basic libraries that Python, SDL and Pygame provide you should cover the basic cpu intensive things so that your own code can be in Python only and be fast enough.

If you encounter something where need to do some own code for which Python is too slow, you can always port that part to c and use that from the Python game, like you would already be using the pre-existing modules.

Also for numerical processing of arrays like bitmaps you can use the Pygame surfarray module to get to use numeric python (numpy), which enables you to define array operations in Python so that they are executed using the fast optimized native libraries.

~Toni