Tilebased games in Flash 5 – Part 8b

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!

Twitter

    Sorry, no Tweets were found.

Categories