I’ve got a map with four wall objects on it I’m running using C#, Monogame, Extended and Tiled. You can see them in the image and (hopefully) the small dots that denotes the first point selected as outlined in the Tiled docs.
When it renders the object layer in game though that first point of each object is rendered at tile coordinate 1,1. Is that expected behaviour? Do I have to render each object in context of world space individually or have I got that wrong?
Not sure if the image below makes that clearer or not! It’s where the four objects are rendering.
I’m having a hard time reading your map and diagram, but if they’re rendering in a different location in your game than in Tiled, that means you’re rendering them incorrectly.
Object coordinates are in world space, correct, and the coordinates in the map file are in pixels. However, you need to keep rotations in mind, they may change the position of the object significantly since they’re done about the top left corner. However, if you rotate an object 180 degrees, this “top left corner” is visually the bottom right corner xP Your render location may need to take this into account of transformations are done differently in-engine than in Tiled.
I’ve drawn the objects as they are in Tiled on the screenshot. The image with the white background is how they are when I run the game. The first point of the blue object is the bottom left of the polygon. I’ve checked the figures in the property window and X/Y are accurate in regards to the world position (0, 3360).
They’re all rotated properly and the right size. Just all the objects locate their first position at 70,70 in the world.
Thanks for the colour coding, that helped me a lot in understanding your earlier drawing!
Just to be clear, when I say “world space” I mean map space, not the World feature in Tiled. Every map’s top left corner is 0,0 in this space.
I also think I may have accidentally misled you earlier: when I said “object coordinates”, I meant the X and Y properties on the object itself. The points within a polygon or polyline are in local space to the object, so you’ll need to add the object’s x and y properties to each point’s coordinates if you need them to be in map space. If possible, however, you should keep the points in local space and transform the entire object using your engine’s transform functions to position and rotate it, so that any runtime changes to the object are more predictable and consistent with Tiled’s behaviour. That may also give you more accurate collision detection, depending on how that’s implemented.
I’m not sure how to answer your question because I don’t know how your object rendering system is set up.
The objects should be rendered at x, y, which should mean that each point within the object is at its given coordinates plus the x, y. As I mentioned in my previous post, the x, y coordinates should ideally be applied as a transform on the whole object, rather than being manually added to the raw positions of each point.
Using Monogame.Extended.Tiled.Renderers as they come out of the box. I pass it the GraphicsDevice and TiledMap.
Sorry, out of my depth here and not sure what else I can give you.
Thanks for your help BTW.
Tried it previously using a rectangle for the object and it’s largely the same code and it placed that properly in the world space. Changed to polygons and it doesn’t appear to read the x,y anymore.
I’m not familiar with Monogame so I can’t give specific advice, but looking at the code for the Monogame.Extended.Tiled stuff, it looks like when Polygons are created, they take the points (unchanged from the TMX) and the x, y as a separate position parameter. So, you should not need to worry about doing anything with the points, you should be able to just position the object according to its x, y properties, and Monogame handles the transformations. The position and points are part of the object when it’s created (i.e. when it’s read in from the TMX), and not passed in to the renderers. So, it’s likely not your rendering code, but your initial reading code where the issue lies.
It looks that way looking at the xml that makes up the tmx file. The object nodes have the correct x/y values. The code below loads the map object. Using a breakpoint I’ve stepped through these few lines and the objLayer has the map objects with the x/y data from the file. Just doesn’t use it when locating them in the world.
This sounds like an issue to bring up in the Monogame community if you haven’t already, there are more likely to be people there who are familiar with this issue.