adrix89 wrote:Then how do I render another layer on the sprite?
A map's draw_list is simply an array of functions that are called in order when the map is "drawn". By default those function are the tile and object layers' draw functions in the order they appear in Tiled. You can manipulate draw_list however you want to and add, remove, or switch around any function. This includes draw functions that aren't layers, or really whatever you want.
adrix89 wrote:If I were you I'd gut object layer or make it only information and implement a proper draw ordering,because stored objects just evaporate once you load a new map because that object doesn't exist anymore in the data structure as an object on a object layer
Old objects still exists after you load a new map, but in the old map. As I said before maps are self contained and do not share data (actually saying this made me realize they don't even share image data. I should probably cache that). This doesn't stop you from moving over the objects that you want to keep to the new map. Moreover, there's nothing stopping you from only using the object layer for information. Just remove the layer from the map's draw_list and read what you want from it.
I think the biggest confusion here is that you don't realize that the draw ordering is completely customized through the map's draw_list.
Here's an example on how to do this:
Code: Select all
-- You have two layers "ground" and "overhead"
-- map.draw_list[1] is ground
-- map.draw_list[2] is overhead
-- Let's insert a sprite's draw function inbetween those:
table.insert(map.draw_list, 2, sprite.draw)
-- Now the sprite will be drawn between the two layers
-- What if we don't know the specific number of the layer, only the name?
-- You can search for the layer number using the function map.drawPosition(drawitem)
table.insert(map.draw_list, map.drawPosition(map.tl["overhead"]), sprite.draw)
-- So there's nothing stopping you from implementing your own layers
I hope that answers your questions. If you're still having trouble let me know.
EDIT: I'm sorry but I got the names of my variables mixed up here. draw_order is actually what I was referring to above.