Organizing levels and multiple tile maps

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
Flesh Gregor
Prole
Posts: 9
Joined: Thu May 07, 2009 9:30 pm

Organizing levels and multiple tile maps

Post by Flesh Gregor »

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.
User avatar
Tabasco
Citizen
Posts: 72
Joined: Tue Dec 02, 2008 5:04 pm

Re: Organizing levels and multiple tile maps

Post by Tabasco »

I'm not sure if I'm getting exactly what you're asking, but I'll try to answer the best I can.
Mainly I don't understand what you're talking about when you refer to a one frame animation. Unless I'm missing something, that's a static image.

For your tile maps, just create a tile class and have a single map full of tile objects which could contain an arbitrary amount of information, including visibility, collision preference, etc.
Since you're new to lua, you might want to check out this thread on classes.
http://love2d.org/forum/viewtopic.php?f=3&t=651
User avatar
Flesh Gregor
Prole
Posts: 9
Joined: Thu May 07, 2009 9:30 pm

Re: Organizing levels and multiple tile maps

Post by Flesh Gregor »

A static image is exactly what I'm aiming at, I was just referencing the animation function because it already turns your sprite sheet into a grid and iterates through it for you. Essentially I'm asking what is an efficient way to do that for static images. Thanks for the link though, that clears up a lot of my questions and speculations in regards to both questions.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Organizing levels and multiple tile maps

Post by bartbes »

If you want to be able to work with different sizes of tilemaps you have to scale anyway, so just get yourself the size using image:getWidth() and image:getHeight() (where image is a static image as returned by newImage).
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Organizing levels and multiple tile maps

Post by rude »

I think love.graphics.draws is the only viable option right now. Animation in this case is ... not really what it's made for.

In the future, though, maybe we need a class which does something like this:

Code: Select all

-- Precalculates texture coordinates.
frame = love.graphics.newFrame(image, x, y, w, h)

-- Draw it like everything else:
love.graphics.draw(frame, x, y, etc)

-- You can not do this (only for Images).
-- love.graphics.draws(frame, ...)
Then you would get the benefit of only calculating texture coordinates once (instead of each time with draws), and more flexibility than Animation.

I don't know if there's any interest in this feature. Just add it to the feature tracker if you* want it.

* Referring to any person.
Post Reply

Who is online

Users browsing this forum: No registered users and 24 guests