Libgdx Tiled objects collision

I searched the forums with no luck.

I was reading this article 2d platformer guide, scroll down to type 4: vectorial. This approach seems very versatile and approachable when I saw TileD objects and Libgdx’s math package.

So I use the object layer in TileD to provide bounds and extract the polygon & rectangle objects and tried using the Intersector class to determine collision and etc.

The problem is how do i transform the object’s vertices to my TiledMapRenderer/OrthographicCamera’s scale.
The object is too big and not in my camera coordinates so all the math doesn’t work. I tried rendering the object with/without projection matrix but it never showed up.

Should I post my map and code?

Did you need to set the TiledMapRenderer’s view to the camera, by doing mapRenderer.setView(camera)?

How are you drawing the object? Any renderer you’re using, such as ShapeRenderer shouldhave it’s view set to the camera and the projection matrix set to camera.combined.

Edit, some code would also be helpful so we can test it out and see what’s wrong.

I pretty much figure everything out. Setting the scale to map renderer’s unitScale turned it into camera coordinates.

setScale method is in polygons only. I can’t find one in Rectangles.
(I could turn rectangles in polygons)


float unitScale = 1 / 16f;
renderer = new OrthogonalTiledMapRenderer(map, unitScale);

MapObjects objects = ((MapLayer) map.getLayers().get("3")).getObjects();

poly = ((PolygonMapObject) objects.get(0)).getPolygon();
poly.setScale(1/16f, 1/16f);
poly.setPosition(1, 1);

rect1 = ((RectangleMapObject) objects.get(1)).getRectangle();
rect2 = ((RectangleMapObject) objects.get(2)).getRectangle();

sr = new ShapeRenderer();

// rendering
sr.setProjectionMatrix(camera.combined);
sr.begin(ShapeType.Line);
sr.setColor(Color.BLUE);
sr.polygon(poly.getTransformedVertices());

Just need to scale those two rectangle ledges and work on hit testing.
Any difference between 4 sided polygon vs a rectangle?