Skip to content

Map:getTileProperties() does not work with chunked maps #287

@aburkes

Description

@aburkes

Right now I'm in the middle of writing a game engine that requires each tile to have properties, and was rather surprised when I found Map:getTileProperties() did not work, saying it could not index a field named "data", which was nil. Looking further into it, I found Map.layers[1].data was indeed undefined. Looking into the structure of that layer, I did find that my properties were indeed there, but they were instead nestled into subtables under a table called chunks.

This is something of a problem because the code for Map:getTileProperties() is this:

function Map:getTileProperties(layer, x, y)
	local tile = self.layers[layer].data[y][x]

	if not tile then
		return {}
	end

	return tile.properties
end

As you can see, it doesn't look into chunks at all.

I can see why the data is in this chunked format, since this was made from an "infinate" map height. Is there a reason why STI keeps it in that chunked format instead of reassembling it into a single 2D array upon loading? A quick search of init.lua shows the term "chunk" coming up 57 times, and it seems like making it a single continuous array would not only make the getTileProperties method work, it might simplify the codebase overall.

Right now I'm probably going to make my engine fill that data table itself since this might be a niche need, but could probably branch STI and commit if there is interest.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions