May 2, 2007 will

Infinite sprites with PyGame

The one thing that has always bugged me about sprites in PyGame is that they are so damn finite. Why should I be restricted to an upper bounded number of sprites in my game? Fortunately, I figured out a way of breaking the finite sprite limit, and render an infinite number of sprites to the screen - without any reduction in the frame rate!

Now before you try to convince me this is impossible with such arguments that as "an infinite number of sprites requires an infinite amount of memory", bare in mind that I consider the laws of mathematics to be more rules than actual laws. And rules were meant to be broken, as they say. Not convinced? Download and run this demo, and tell me when you run out of memory. Requires Python and PyGame.

Download Infinite Sprites infinitesprites
Use Markdown for formatting
*Italic* **Bold** `inline code` Links to [Google](http://www.google.com) > This is a quote > ```python import this ```
your comment will be previewed here
gravatar
MrTinkles

Wow, very nice, very smoooth up till 950, which somthing in the backround sent it lagy for 0.5 of a sec, very noice

gravatar
Joe

Nice job! Another great demo/lesson. I'm really looking forward to your book.

gravatar
michael schurter

Only 950? I'm up to over 12,000!

Obligatory screenshot:
http://michael.susens-schurter.com/files/pygame-sprites.png

This is on Debian Sid, Python 2.4.4, PyGame 1.7.1, 2.8GHz CPU and 1 GB RAM. I also removed the FULLSCREEN flag, so I could continue to get work done while it ran. ;)

gravatar
Will


Only 950? I’m up to over 12,000!

Holey moley!

gravatar
Popcorn Mariachi

Heh. Neat trick!

gravatar
Geometrian

Holey Moley this!
http://img460.imageshack.us/img460/7060/14594229wd4.png

gravatar
Geometrian

Actually a cheat... Changed the number of sprites to start around 14590000.
:)

gravatar
Geometrian

Have gotten several thousand the 'right' way though...
1.7Ghz Centrino Duo
1 gb RAM
GeForce Go 7600

gravatar
Will

A devious ruse! I would have believed it if you hadn't come clean. :-|

gravatar
Geometrian

I would have been lying- and doing something that much would have been suicide for my computer...

gravatar
John

I'm having some problems using the SubPixelSurface when the hight of the image is different from the width! The result image gets all screwed up. Any ideas?

gravatar
Will

That was a bug in the first version. Download it again, and it you should find that it is fixed. :-)

gravatar
Will

It comes back in fashion every 5 years!

gravatar
Gareth Noyce

Shame Pygame doesn't really. You're right about the exe hassles though, sorting out distribution would have helped lift it years ago...

gravatar
derf

1Xoq01 re re rerrrreeee gththtt