Love2D Lua框架 - 将无组织的渲染表转换为地图结构
我正在将未组织的 2D 渲染地图转换为字符串表,例如:
“Render = {{Image,50,60,2}}”
其中 Image 是图像(我正在使用 Love2D Lua 框架) 50是X轴 60是Y轴 2 是图像 ID(这就是实际表中的内容。)
但是大约有 100 个这样的图像,所有这些都是无组织的,我需要将它们组织成结构化地图。
这是奇怪的一点:当我把它变成一个有组织的字符串时..它..有点逆时针旋转桌子90*角。
说我想要的结果
{
{7,6,5},
{6,5,4},
}
是:
{
{5,4},
{6,5},
{7,6},
}
显然没有错误,因为它在技术上是有效的,只是旋转错误。这是相关代码:
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看我的LÖVE 磁贴教程。 1d-Strings 部分讲述了如何处理“switched x和y”的问题。
Give a look at my LÖVE tile tutorial. Section 1d-Strings speaks about how to handle the "switched x and y" problem.