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
This blog post was posted to It's All Geek to Me on Wednesday May 2nd, 2007 at 10:27PM
 

16 Responses to "Infinite sprites with PyGame"

  • MrTinkles
    May 2nd, 2007, 10:33 p.m.

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

  • Joe
    May 2nd, 2007, 10:56 p.m.

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

  • May 3rd, 2007, 5:52 p.m.

    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. ;)

  • May 3rd, 2007, 6:14 p.m.


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

    Holey moley!

  • May 5th, 2007, 12:29 p.m.

    Heh. Neat trick!

  • Geometrian
    May 6th, 2007, 11:20 p.m.
  • Geometrian
    May 6th, 2007, 11:22 p.m.

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

  • Geometrian
    May 6th, 2007, 11:24 p.m.

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

  • May 6th, 2007, 11:28 p.m.

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

  • Geometrian
    May 6th, 2007, 11:32 p.m.

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

  • May 9th, 2007, 8:53 a.m.

    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?

  • May 9th, 2007, 8:55 a.m.

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

  • July 26th, 2007, 9:55 a.m.
  • July 26th, 2007, 9:32 p.m.

    It comes back in fashion every 5 years!

  • July 27th, 2007, 9:10 a.m.

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

  • August 15th, 2008, 10:54 a.m.

    1Xoq01 re re rerrrreeee gththtt

Leave a Comment

You can use bbcode in the comment: e.g. [b]This is bold[/b], [url]http://www.willmcgugan.com[/url], [code python]import this[/code]
Preview Posting...
Previewing comment, please wait a moment...

My Tweets

Will McGugan

My name is Will McGugan. I am an unabashed geek, an author, a hacker and a Python expert – amongst other things!

Search for Posts
Possibly related posts
Tags
Popular Tags
 
Archives
2010
 
Recent Comments
This is very true, i believe that people need to be able to use a domain if they register it, ...
Hehe Thats a good tatoo idea ;) Have a nice day Joel
- Joel Shapiro on Powered by Ubuntu
Weirdly enough i am a junior dev on an internship. I am @ work and i was way too bored/out ...
I love the idea of locidesktop, and even more the minimal UI. Hope you'll keep it up!
Many thanks! I tried several solutions but the only one that worked was yours.
 
© 2008 Will McGugan.

A technoblog blog, design by Will McGugan