Code: Select all
map = {
{0,1,1,1,0},
{1,1,0,1,1},
{1,1,1,1,1}
}
Code: Select all
map = {
{0,1,1,1,0},
{1,1,0,1,1},
{1,1,1,1,1}
}
The solution is a outline line of this given tilesNoreoAlles wrote: ↑Mon Jun 06, 2022 11:02 am Hey, does anyone got a algorythim that i can use freely, wich builds polygonal meshes made of squares from a map like this:It should connect all the 1s to one big mesh and if there are unconnected 1s they should make a new mesh.Code: Select all
map = { {0,1,1,1,0}, {1,1,0,1,1}, {1,1,1,1,1} }
Code: Select all
for y = minY, maxY do
for x = minX, maxX do
-- this tile
cellsMap[y][x].v = not cellsMap[y][x].v
cellsMap[y][x].h = not cellsMap[y][x].h
-- right tile border
cellsMap[y][x+1].v = not cellsMap[y][x+1].v
-- bottom tile border
cellsMap[y+1][x].h = not cellsMap[y+1][x].h
Code: Select all
map = {
{0,0,0,0,0},
{0,1,1,0,0},
{0,0,0,1,0},
{0,0,0,0,0},
}
Code: Select all
{x=2, y=2, v=true, h=true},
{x=3, y=2, v=false, h=true},
{x=4, y=2, v=true, h=false},
{x=2, y=3, v=true, h=true},
{x=3, y=3, v=false, h=true},
{x=4, y=3, v=false, h=true},
{x=5, y=3, v=true, h=false},
{x=4, y=4, v=false, h=true},
Hm, Box2D mesh?NoreoAlles wrote: ↑Mon Jun 06, 2022 1:22 pm I do got a spritebatch, i just need a way to make a box2d mesh out of that shape, im soryy if i didnt get that point accross, i am not so good at english.
I did that with a body, shape and fixture for each individual block, wich made me get caught on the edges of blocks, but i didnt think just using one big body.pgimeno wrote: ↑Mon Jun 06, 2022 8:43 pmHm, Box2D mesh?NoreoAlles wrote: ↑Mon Jun 06, 2022 1:22 pm I do got a spritebatch, i just need a way to make a box2d mesh out of that shape, im soryy if i didnt get that point accross, i am not so good at english.
Box2D can only handle convex shapes, which for tile-based shapes means rectangles. If you have something more complex, you need to make a body with multiple fixtures, each with a shape. For simplicity, you could have square shapes with the positions in the grid and add as many fixtures as there are squares belonging to each block; I don't know if that would behave sanely though.
Users browsing this forum: Google [Bot] and 74 guests