Friday, June 14, 2019

libgdx - generate box2d bodies from isometric tiled map



I followed the tutorial here to generate box2d bodies from a tiled map and that worked fine.... for orthogonal tiled maps. Unfortunately isometric maps use their own coordinate system where (0, 0) is at the leftmost corner of the map, and this causes the bodies to be in the wrong place.


I tried implementing a transformation matrix or just transforming the body but I don't think that is possible (or at least I could never find a way). How else can this be solved? Here is the relevant method that needs to be changed:


private Shape getPolygon(PolygonMapObject polygonObject) {
PolygonShape polygon = new PolygonShape();


float[] vertices = polygonObject.getPolygon().getTransformedVertices();

float[] worldVertices = new float[vertices.length];


for (int i = 0; i < vertices.length; ++i) {
worldVertices[i] = vertices[i] / units;
}

polygon.set(worldVertices);
return polygon;
}

As you can see I need a way to convert the isometric coordinates to game coordinates using just plain math or something else like a matrix. I think the only line needing to be changed is the line in the for loop.




No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...