For a few hours now, I have been attempting to build static collider boxes in Windfield using object layers created in Tiled (so I'm using STI).
I can make rectangles easily enough, but polygons are giving me trouble because they take vertices (x1, y1, x2, y2, etc), but the lua file with those vertices has those values nested inside of other tables:
Code: Select all
objects = {
id = 42,
name = "",
type = "",
shape = "polygon",
x = 269,
y = 640,
width = 0,
height = 0,
rotation = 0,
visible = true,
polygon = {
{ x = 0, y = 0 },
{ x = -12, y = 0 },
{ x = 51, y = -63 },
{ x = 51, y = -52 }
},
properties = {}
},
I'm after the polygon table data so I can build shapes using Windfield's world:newPolygonCollider function.
I have tried various methods for grabbing nested tables, but haven't managed to get the x and y values I need. I'll just post my original code:
This code runs for each object in the object table above, then passes the x and y coords along with the polygon table to a function:
Code: Select all
for i, par in pairs(levelMap.layers["semiSolidSlope"].objects) do
spawnSemiSolidSlope(par.x, par.y, par.polygon)
end
Code: Select all
function spawnSemiSolidSlope(x, y, polyTable)
local semiPlatform = world:newPolygonCollider(x, y, polyTable, {collision_class = "semiSolid"})
semiSlopePlatform:setType('static')
table.insert(semiSlopePlatforms, semiSlopePlatform)]]
end
tldr; I need to take the values from tables within tables:
Code: Select all
objects = {
obj = {
{x=1,y-3},
{x=-2,y=4},
{x=6,y=8},
{x=8,y=8}
},{
etc
}
}
Code: Select all
world:newPolygonCollider(x1, y1, x2, y2, x3, y3, etc)