5
\$\begingroup\$

We are trying to make a small 2d game which requires an excessive amount of sprites spawning and moving around the screen at the same time. We did try doing this in python but it started choking at around the 500 mark. Are there any good ways to handle this in python?

\$\endgroup\$
3
  • \$\begingroup\$ What exactly are your sprites doing? I assume they're not just being drawn. \$\endgroup\$ May 18, 2011 at 11:55
  • \$\begingroup\$ Too many unknowns here such as what code is being executed for each sprite, what platform you're on, etc. Python isn't your problem here is my bet, it's your approach to coding and managing the sprites. \$\endgroup\$
    – Tim Holt
    May 18, 2011 at 14:22
  • \$\begingroup\$ Hardware instancing would be pretty good for this. \$\endgroup\$
    – House
    May 18, 2011 at 15:33

2 Answers 2

8
\$\begingroup\$

If you have a very large number of sprites, it might be time to let hardware handle it and move your sprite rendering into VBOs via pygl or the like. Realistically though, massive numbers of sprites can usually be turned on it's head as a "find the sprite under this pixel" problem instead. Maybe not so easy in python, but you might find a library already written for "particles" that handles this situation better. Collecting your sprites by wich frame they are on for example.

A good answer to this question would require a bit more knowledge about the type, speed, clumping, or even how regular the sprites might be. Do you have thousands of sprites because there are that many entities? or is it moving land-pieces? do they move in groups? Each assumption we can make about the sprites can offer a better / faster rendering solution.

As usual, what is your input data, and what do you want out.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ +1 for particles. Look up how to do a good particle system on your platform of choice and you will learn a lot about tricks for managing a massive number of sprites. \$\endgroup\$
    – Lunin
    May 18, 2011 at 18:31
4
\$\begingroup\$

Late to the party, but I think the simple answer is, "Learn what code profiling is and how to apply it". Because you cannot make any assumptions as to what is causing your performance drop until you do.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .