[SDL] Combining Layers

Tomas Andrle tomaasz at iol.cz
Sun Aug 15 12:35:00 PDT 1999


On Sun, 15 Aug 1999 wahle at innercite.com wrote:

> I am kind of new to graphics programming in general... I was wondering if 
> there was a way to have multiple layers, and lay them on top of each 
> other.. So if I have 3 layers, I would lay down layer one, then layer two 
> (which would cover over layer one that it needed and left the rest) and 
> the lay down layer three which would cover layers one and two exept what 
> it didn't need... Does anyone know what I'm talking about? :) Any help 
> would be appreiated.
> 
> See ya
> 

If I understand you correctly, you mean something that if applied to a
top-view 2d shooter would mean layer 0 for the ground, layer 1 for the
spaceships or whatever and layer 2 for the clouds above the ships? If so, I
think there are many ways how to do this and it mainly depends on how much
stuff is in each layer. In the above case, I would simply draw some tiles with
the ground graphics (that would cover <all> pixels on the screen) and then
draw the ships & clouds over it as 'sprites' - each ship would require a
separate 'drawsprite' call.
Similar is the 'parallax scrolling' in some 2d arcades - here I'd recommend to
encode the layers with a simple RLE (run length enc.) compression to skip the
pixels which I don't want to be drawn (to leave the previous layer unchanged).
Again, it depends on how much stuff is drawn in each layer and how many layers
are drawn etc..

Note: The RLE approach is nice in that it can be easily done in assembler
(only do that if nothing else helps, anyway)

Using a 3D rendering API for this could enable hardware acceleration and
'cheap' transparency. However, SDL doesn't do this, so...forget it! :)


Tomas A.





More information about the SDL mailing list