4
votes

I'm relatively new to python and have made some useful tools and some small games w/ 10 sprites in python; based on performance I think my next logical step is making C extensions to improve performance in pygame.

My first initial question is in pygame, can I make a main loop in C (or would I have to interface with SDL?). And sprites, could I make C code that strictly handles the sprites, and only use python for scripting purposes of the game?

1
If it runs fast enough, you don't need to rewrite part of it in C. In fact, it would propably be counter-productive. - user395760
I would actually disagree as my friend has made a breakout variant among other games that only get 10-15 fps because of "sprites" in pygame - noboody

1 Answers

3
votes

Without any insight to your code, I can make these suggestions. Since you are rightly concerned about performance, instead of trying to improve performance by writing C modules, try optimising the python code you have written. A good article on how to do this can be found in this article about patterns at Python.org.

To answer your question about the main loop, it depends on what you mean by a main loop. Do you mean int main(int argc, char *argv[]) or are you talking about SDL_main?

You can create a C program which runs python for scripting purposes. You can run it as a python script, which run C modules for extra performance. I don't know if you can mix and match using SDL in python and also in C, but don't see why it wouldn't work, but I haven't tried doing it.