I’m trying to import collision detection infos from my TiledMap (.tmx) created by Tiled Map Editor (http://www.mapeditor.org/ ). I wanna getting the infos about created areas in the second layer, my object layer. How i can export this areas? And how it is possible to export infos about each tile to check collisions with single tiles?
Is there anything on this? I have also been unable to get collision data out of my map.
I have a Polygon I can pull from my object layer (TiledMapPolygonObject), but the coordinates don’t (seem to) match up correctly to the map coordinates. Additionally, the Monogame.Extended.Collisions project no longer accepts a TiledMap and it’s not clear what to do with the new CreateGrid(int[]) method.
The demo projects don’t offer any help in this regard - the Collisions demo only contains a commented out line of the way it used to work. I’ve been trying unsuccessfully for a few days now to get my map collider imported with no success.
I would really appreciate a response from the community on this topic (as I assume the OP would as well). How can we read our TiledMap collision data?
I actually looked into TiledSharp, but it doesn’t do anything for rendering, where Extended.Tiled has a renderer which works directly with the Extended.Camera and drastically simplified the drawing process. Were you able to convert the TiledSharp import or what other method did you use for rendering the map?
I wrote my own custom rendering and camera classes. I basically just parse the .tmx file using TiledSharp’s Map object/properties and save the data I need (position etc…) into a custom DrawableTile object that’s in a List (or you could use a 2D array). At that point you have the entire map and can just loop through to draw. Implementing a custom 2D camera that supports full-scene scaling, rotation, and parallax layers is super easy and there’s tons of tutorials you can find via Google.
Thank you. One more question if I could: my Polygon object / TmxObject has some coordinates with negative values. As far as my understanding goes, the TopLeft in both Monogame and Tiled is (0,0).
I feel like I must have goofed somewhere, but this is obviously throwing off my collision detection attempt. How can I translate these points into world space?
Yeah, that shouldn’t happen. I would honestly either delete any objects that have negative coordinates or toss the whole map and start over. Is it possible you applied an offset to their position in Tiled?
When I take the (x, y) coordinate and add it to the points in the list, I get the correct positions. I tried both deleting/recreating the polygon and creating an entirely new map; in both cases, this is how the xml comes out. I’m not entirely sure why it gets generated this way, but at least I know how to deal with it now.
Note that per the original question here, Extended.Tiled collision can be (basically) handled by creating a Polygon object from the map points and checking it against the target position.