efficient layered tile algorithms/structures how?

Started by
3 comments, last by rtr_gamedev 20 years, 8 months ago
What is the best (most efficient) way to display several layers of tiles? Or are tile layers ideal for the scenario I describe below. I have a top down 2d style shooter similar to XGalaga (but more sophisticated layered effects) I would like to have a base layer (all black tiles) I then want to have another 3 layers which apply tiles which are also black but have randomly placed star pixmaps (star{0,1,2}.xpm) depending on the layer. I then have another layer which has prizes and wall tiles/sprites Then finally I have a layer of sprites which are the characters in my game. The reason I have the earlier layers seperated is to give the effect of things in the distance moving less than things that are closer as the characters move across the map. Currently I have this implemented as a multi-dimensional array a[0..N][512][512] which as you might have guessed is naive and very slow. What other methods are there for getting this "things in the distance move slower effect" ? Thanks
Advertisement
Can yo unot just add a speed factor element to your tile class, and then in your movement phase, multiply each tile by this factor to see how far it moves.

Then, say, make all your distant objects have a factor of 0.4, all your mid ojects 0.8 and your top objects 1.0 ?

Or even easier, have 3 constants, one for each layer. (saves accessing an object to find out it''s movement factor if they can never change layers.)

If this was stored in an object though, you could also have effects like comets moving below and behind the ships, by putting them in a lower layer, but setting their speed factor to 2.0, so they move faster but don''t interfere with game play ?

Bp
'I then want to have another 3 layers which apply tiles which are also black but have randomly
placed star pixmaps (star{0,1,2}.xpm) depending on the layer.'

Why not cout those 3 layers down to 1 and just make a simple particle engine that renders into that layer (since we're talking about randomly placed objects anyway)? Just add a 'distance' variable to the particles, then use a method like Bagpuss suggested to determine each particles speed.

'Currently I have this implemented as a multi-dimensional array a[0..N][512][512] which as you might have guessed is naive and very slow.'

I know it has nothing to do with map size directly, but are you minimizing overdraw when you render your map? A simplistic z-buffer might help. Considering the limited number of layers needed to do this type of game, you should be able to keep the memory size of the z-buffer relatively small.

[edited by - SysOp_1101 on July 31, 2003 5:00:23 PM]
SysOp_1101
How do you draw the tiles? You aren''t just looping through everytile on every layer are you? You should make sure you only draw tiles that are currently on the screen.
"When you die, if you get a choice between going to regular heaven or pie heaven, choose pie heaven. It might be a trick, but if it's not, mmmmmmm, boy."
How to Ask Questions the Smart Way.
I made a really simple galaga clone a while back that I never fully completed but it used 3 layers of starmaps that scrolled at different speeds. Don''t know if that is what you mean but I used a multi-dimensional array as well. The only slow part is initializing it. Once it is initialized it runs very quickly. I would check again to make sure you are only drawing the tiles that are on the screen. Of course on mine I also originally had 3 640x480 starmaps that I just recycled instead of bothering with tiles, but I guess it is kind of the same as having 3 huge tiles
Evillive2

This topic is closed to new replies.

Advertisement