Love2D Lua framework - Converting an unorganised rendering table into a map structure
문제
I'm turning a 2D rendered map which is unorganised into a string table, EG from:
"Render = {{Image,50,60,2}}"
Where Image is the image (I'm using Love2D Lua framework) 50 is the X axis 60 is the Y axis 2 is the Image ID (This is what will be in the actual table.)
But there's like 100 of these, all unorganised and stuff, and I need to oragnise them into a structured map.
Here's the odd bit: When I morph it into an organised string.. It.. Kinda rotates the table on a 90* angle anticlockwise.
Saying I want the result of
{
{7,6,5},
{6,5,4},
}
I would get:
{
{5,4},
{6,5},
{7,6},
}
Obviously no error since it technically works, just rotates wrongly. Here's the relevant code:
function OrganiseRenderIntoMap()
MapString = ""
Map2 = {}
MaxSoFarX = 0
MaxSoFarY = 0
for _,v in pairs(Render) do
if v[2] > MaxSoFarX then
MaxSoFarX = v[2]
elseif v[3] > MaxSoFarY then
MaxSoFarY = v[3]
end
end
for currx = 0, MaxSoFarX, 32 do
Map2[currx] = {}
MapString = MapString.."{"
for curry = 0, MaxSoFarY, 32 do
MapString = MapString..GetRenderPos(currx,curry)..","
Map2[currx][curry] = GetRenderPos(currx,curry)
end
MapString = MapString.."},\n"
end
return MapString
end
function GetRenderPos(locx,locy)
for _,v in pairs(Render) do
if v[2] == locx and v[3] == locy then
return v[4]
end
end
end
해결책
Give a look at my LÖVE tile tutorial. Section 1d-Strings speaks about how to handle the "switched x and y" problem.