Organizing levels and multiple tile maps
Posted: Fri May 08, 2009 10:12 pm
Hi all, I've been working with love for about a week now and I'm really enjoying it. I'm new to Lua (though I have a background in php and ruby, neither of which are too different) so I have some questions about how to go about organizing tiles that may pertain to Love or Lua or just the process at large.
First, drawing tiles from tile maps. It's really easy to animate sprites from a single sheet because of the addFrame function, but (correct me if I'm wrong) you don't seem to be able to have a 1 frame animation, and I suppose you could let the animation iterate through the whole tile map and then just use seek(frame), but that seems inefficient, and I'm not sure if that would work in the way I want it to. So the remaining option is to get a subsprite with draws(), but I'm not sure how to iterate through that without specifying the specific height and width of the sheet of tiles I'm working from. I would like to have code flexible enough so that I could enter any tile sheet and have the code adjust for it accordingly with the specification of the height and width of tiles. Is there a function in lua or love to detect the dimensions of an image? Does anyone know a better way to handle this (or have a chunk of code that already does this?)
Second, how do I go about applying attributes to each tile? Would it be better to go about this by applying attributes based on the map (e.g. all tiles in map1's array have collision, all tiles in map2's array don't) or to apply these traits directly within the array somehow.
Another option could be to give each tile sheet its own array which would take care of both problems, but if a game ends up needing 20-50 tilesheets, that seems like far too much work (and hardly an elegant solution).
Thanks alot and sorry if any of these problems have been confronted and solved here before, I couldn't find anything.
First, drawing tiles from tile maps. It's really easy to animate sprites from a single sheet because of the addFrame function, but (correct me if I'm wrong) you don't seem to be able to have a 1 frame animation, and I suppose you could let the animation iterate through the whole tile map and then just use seek(frame), but that seems inefficient, and I'm not sure if that would work in the way I want it to. So the remaining option is to get a subsprite with draws(), but I'm not sure how to iterate through that without specifying the specific height and width of the sheet of tiles I'm working from. I would like to have code flexible enough so that I could enter any tile sheet and have the code adjust for it accordingly with the specification of the height and width of tiles. Is there a function in lua or love to detect the dimensions of an image? Does anyone know a better way to handle this (or have a chunk of code that already does this?)
Second, how do I go about applying attributes to each tile? Would it be better to go about this by applying attributes based on the map (e.g. all tiles in map1's array have collision, all tiles in map2's array don't) or to apply these traits directly within the array somehow.
Another option could be to give each tile sheet its own array which would take care of both problems, but if a game ends up needing 20-50 tilesheets, that seems like far too much work (and hardly an elegant solution).
Thanks alot and sorry if any of these problems have been confronted and solved here before, I couldn't find anything.