Cajun, I'd be interested to hear you elaborate more on your approach if you've got the time.
I think I follow what you were saying, but at the same time I don't think I can utilize that approach given my engine goals.
For instance, while I could treat a layer as a 2d array the size of the screen, that becomes problematic when one tile space has 8 tiles, but the rest of the tile spaces only need 3.
[edit] - the main issue being the need to iterate across the whole map 8 times when only 1 square has 8 tiles and the rest have 3. Assuming an average of 400 tiles per screen, that's roughly 2000 (5 passes) of wasted 'checks'.
This wouldn't be a problem if I confined all tiles in the game to a specific size and didn't allow freeform movement. If I knew everything would fit nicely in it's current tile location, I could just loop through my map and draw each tile at each tile location without regard to any other tile location and the layers needed there. But, since I need to allow multiple sized tiles that won't work.
Let's say at 0,0 I've got a grass tile and a bird tile. The grass is at a layer depth of 0 (background) and the bird is at say 5. (not a 5th layer I guess, just a value representing it's pseudo Z value)
Now, lets say the player is 2 tiles tall, and is at layer depth 3. Also, he's standing at (0,1). If I just zoom through each tile location and draw all of the tiles in that spot, the bird would disappear behind the player in this case.
I guess I'm not really utilizing "layers" at all, per se, but instead pseudo layers. The real reason I need this functionality is I want the game to seamlessly allow the following, for instance:
A player walks into an abandoned house. Instead of loading a new map, the ceiling tiles instead are drawn at 75% transparency and the inner tiles of the houses first floor are now shown. The player walks to the corner of the room and descends a staircase into the basement. Upon reaching the bottom the ceiling tiles have now disappeared and the first floor tiles (the new "ceiling" ) are now drawn at 75% transparency.
Assuming that the basement has 2 pseudo layers... objects that are drawn over the background tiles and the background tiles themselves and assuming the first floor and the roof of the house was the same - well, that right there is essentially '6 layers'. There might be another pseudo layer above the roof of the house too, that holds clouds or some kind of truly 'foreground' images.
My approach as it stands now is to iterate through each spot on the map and toss each tile into a list that is assigned to a specific 'pseudo layer'.
i.e.
List0 holds all objects with a layer val of 0
List 1 holds all objects with a layer val of 1
Then I can just zoom through the lists sequentially and draw each tile - knowing that they'll be Y sorted (I'm going to go across my map row by row when inserting into the list) and also depth sorted (since the first list represents the lowest layer, the next list the second lowest, etc).
I think I follow what you were saying, but at the same time I don't think I can utilize that approach given my engine goals.
For instance, while I could treat a layer as a 2d array the size of the screen, that becomes problematic when one tile space has 8 tiles, but the rest of the tile spaces only need 3.
[edit] - the main issue being the need to iterate across the whole map 8 times when only 1 square has 8 tiles and the rest have 3. Assuming an average of 400 tiles per screen, that's roughly 2000 (5 passes) of wasted 'checks'.
This wouldn't be a problem if I confined all tiles in the game to a specific size and didn't allow freeform movement. If I knew everything would fit nicely in it's current tile location, I could just loop through my map and draw each tile at each tile location without regard to any other tile location and the layers needed there. But, since I need to allow multiple sized tiles that won't work.
Let's say at 0,0 I've got a grass tile and a bird tile. The grass is at a layer depth of 0 (background) and the bird is at say 5. (not a 5th layer I guess, just a value representing it's pseudo Z value)
Now, lets say the player is 2 tiles tall, and is at layer depth 3. Also, he's standing at (0,1). If I just zoom through each tile location and draw all of the tiles in that spot, the bird would disappear behind the player in this case.
I guess I'm not really utilizing "layers" at all, per se, but instead pseudo layers. The real reason I need this functionality is I want the game to seamlessly allow the following, for instance:
A player walks into an abandoned house. Instead of loading a new map, the ceiling tiles instead are drawn at 75% transparency and the inner tiles of the houses first floor are now shown. The player walks to the corner of the room and descends a staircase into the basement. Upon reaching the bottom the ceiling tiles have now disappeared and the first floor tiles (the new "ceiling" ) are now drawn at 75% transparency.
Assuming that the basement has 2 pseudo layers... objects that are drawn over the background tiles and the background tiles themselves and assuming the first floor and the roof of the house was the same - well, that right there is essentially '6 layers'. There might be another pseudo layer above the roof of the house too, that holds clouds or some kind of truly 'foreground' images.
My approach as it stands now is to iterate through each spot on the map and toss each tile into a list that is assigned to a specific 'pseudo layer'.
i.e.
List0 holds all objects with a layer val of 0
List 1 holds all objects with a layer val of 1
Then I can just zoom through the lists sequentially and draw each tile - knowing that they'll be Y sorted (I'm going to go across my map row by row when inserting into the list) and also depth sorted (since the first list represents the lowest layer, the next list the second lowest, etc).