Notice the use of this SSK function: ‘offset_xy()’ which came out of a discussion here in the forums. It calculates the relative offset of the vertices to ‘center’ them.
Notice that the physics record has an x and y (offset) that has to be added to the vertices. Also notice the object offset by half height/width values. This is because Tiled uses a corner anchor, while I’m placing the bodies by their center.
You will need to take a look at the record for the object you’re drawing and adjust accordingly.
-- Get polygon center \<x,y\> based on vertices local function offset\_xy( t ) local sort = table.sort local coordinatesX, coordinatesY = {}, {} local minX, maxX, minY, maxY local function compare( a, b ) return a \> b end for i = 1, #t\*0.5 do coordinatesY[i] = t[i\*2] end for i = 1, #t\*0.5 do coordinatesX[i] = t[i\*2-1] end sort( coordinatesX, compare ) maxX = coordinatesX[1] minX = coordinatesX[#coordinatesX] sort( coordinatesY, compare ) maxY = coordinatesY[1] minY = coordinatesY[#coordinatesY] local offset\_x = (minX+maxX)\*0.5 local offset\_y = (minY+maxY)\*0.5 return offset\_x, offset\_y end
You probably need to modify the code in Berry that makes the polyline. Extract the x,y coordinates from the input into a table, pass it to the function, take the result and draw a line.
Easy Peasy.
Once you get it working, you might consider submitting the fix to @ldurniat for addition to the Berry module/lib.
@Idurniat : Do you think you can fix this problem from Berry code?
The issue is I am not very skilled to really understand how Berry was created, so I guess Idurniat is the right person to modify this.
Q:1) “Extract the x,y coordinates from the input”, what do you mean by this?
Do you say that I should extract the coordinates from the map.json file? Is that the input file?
Q:2) The function provides the offset, what do I do with the offset x and y values? Subtract from the table of x and y coordinates to adjust?
Sorry for asking silly question, but I think this is an issue in the Berry engine :
Observation : subtracting the offset values from the coordinates, do take the polyline closer. However this effort is a killer for me…there can be 20 points in a polyline, need an automatic solution.
Please suggest @Idurniat or @roaminggamer : Is there any engine which does this adjustment automatically?
I’m staying out of this. If @Idurniat has time to add this feature to Berry that’s great, but since Berry is open source you may simply need to figure this out on your own.
Whatever the case, the change would be made to Berry not your data and once implemented correctly, it will work for all cases.
I have created significant amount of content with Berry, so I am reluctant to move away from it.
I will try to dig through the issue and if possible implement a fix in Berry with help of Idurniat.
My apologies, I am an indie developer who at the moment do not have any budget and learning my way up, otherwise I would have seriously considered it. Thanks for your help so far.