On Sat, Mar 6, 2010 at 11:44 AM, Kris Schnee
<kschnee@xxxxxxxxxx> wrote:
On 3/5/2010 10:40 AM, René Dudfield wrote:
However, sometimes we would like to operate on a whole bunch of
smaller surfaces stuck together.
I've done several projects using a full-screen scrolling tilemap. That is, sprites walking around on a blanket of 2D tiles drawn from an array as big as 1000x1000 referencing a set of 50x50 tiles. That wasn't practical to do using a Pygame Surface, due to the size, so each frame the system figured out the range of all visible tiles (based on the POV character's location) and drew those. It wasn't very efficient, but it did work, and it's an example of a surface built from many actual Surface objects. (Will link to code if you want.)
I did something very similar with Gummworld. The supersurface was not a single Pygame surface, rather a virtual surface made of a 2D array of sprites each with its own image. The Pygame drawing surface was the visible display; only I found that Group.draw()-ing all the terrain sprites and allowing Pygame to automatically crop them was in larger cases more efficient than cropping the drawing scope in Python. Still, it did indeed waste memory having all those sprites, each with their own image, outside the display area. The level design was rectangular, and if the map is irregular then large portions of the supersurface could possibly have many unused sprites; which led to a crude sparse map implementation, where an array cell with a None value would be ignored. It's a simple paradigm in which the special cases tend to center around conserving memory and CPU.