I am trying to create a series of complex polygons via display.newPolygon and associate them a physics body with the same outline.
I can’t seem to be able to use an outline body since I don’t have an image to use, so I did it like this. Size of the content area is 800x1200.
Here is the relevant part of code where both the polygon and the physics edge shape body are created:
-- cookedHotspots contains couples of values which form the polygon and the chain. They are numbers with many decimals, e.g -- 9.6960542, 45.05634919999999 -- .... for i = 1, #cookedHotspots do local a, b = lonLat2XY(cookedHotspots[i][1], cookedHotspots[i][2]) arenas[i] = display.newPolygon(a + 800 / 2, b + 1200 / 2, cookedHotspots[i][4]) arenas[i].fill = {1,1,1} -- aggiunta fisicità physics.addBody(arenas[i], "static", {chain = cookedHotspots[i][4], connectFirstAndLastChainVertex = true}) end
No matter what I try, there is a misalignment between the polygon and the edge shape body, as shown by the following picture:
[sharedmedia=core:attachments:4217]
If I increase the size of the bounding box to accomodate more polygons, the misalignment increases wildly, same data passed.
[sharedmedia=core:attachments:4218]
Any idea of why it happens? I can only think of different ways of rounding between the polygon code and the physics code since I am passing the exact same vertex structure to both the polygon constructor and the physics body.