Tilebased games in Flash 5 - Part 8 addon

Iīve recieved a few mails regarding the z-sorting in the isometric example in tutorial 8. Which in my example isnīt very good... Like I said, there are probably many ways to do that and how it should be approached probably depends on what kind of game it is, how it works and so on.

Anyway... I thought it could be a good idea to make an example.

The best way would probably be to just give the tiles and the sprites the depth of their y-position on the screen. But that wonīt work in flash, since two movieclips canīt seem to share the same depth, at least not when created.

So each tile needs to have a unique depth. So letīs start with the map-building loop.
for ( var i=0; i < mapH; ++i ) {
	for ( var j=0; j < mapH; ++j ) {
		var d = (i*tileH) + (j*tileW) + i;
		this.clip.attachMovie("tile", "t_"+i+"_"+j, d);
Only thing thatīs new is the d-variable, this makes the tiles get depths like down below(seen from above), the tileW and tileH is set to 26.

Then in character itīs the same thing really, just use the down-right corner of the character as the point to sort against.
The result is down below, download fla here.

The bad thing(at least I think) is that I need to swap the depth of the tile aswell. A funny thing though is that now, using swapDepths, two tiles seem to be able to share the same depth without dissapearing... well, well...

Finally hereīs an example that visualises the depth swapping:

And thatīs it!

(C) OutsideOfSociety 2002.