Why do Isometric objects get miss positioned when imported into Visual Studio using XTiled ?!

hello,
i have been trying to figure out why object poly lines don’t appear on the map when i run my game because it seems that the objects get positioned in other coordinates, and i can’t so help please.
this pic is from my game.exe

this pic is from the original map on Tiled

The polylines are projected on the ground, just like the rectangle and ellipse objects. If your intension is to use or render them as unprojected objects, then you should unproject them first. Could that be your issue?

The coordinate space they’re in is based on the tile height. Here’s the code Tiled uses to convert from the stored “pixels” to screen coordinates:

QPointF IsometricRenderer::pixelToScreenCoords(qreal x, qreal y) const
{
    const int tileWidth = map()->tileWidth();
    const int tileHeight = map()->tileHeight();
    const int originX = map()->height() * tileWidth / 2;
    const qreal tileY = y / tileHeight;
    const qreal tileX = x / tileHeight;

    return QPointF((tileX - tileY) * tileWidth / 2 + originX,
                   (tileX + tileY) * tileHeight / 2);
}

i’m fairly new to Tiled & XTiled so i don’t know what i want beyond these collision objects being placed in their respective position.
so can you tell me which part of the code i have to tweak ?? , or if you don’t have time just tell me where to look and ill do the rest, thanks a lot.

Are you using XTiled both for reading the map and rendering those polygons? Assuming you’re rendering the polygons yourself, you’ll have to use the conversion function I provided somewhere to get your polygons to end up on the screen the same way they do in Tiled.

I can’t help you with the actual code in XTiled. Maybe @michael_neel can.

yes 'm using XTiled for both reading and rendering the map, and where can i get that conversion function you’re talking about?

I’m talking about the pixelToScreenCoords function I included in my initial reply.

Hi Sam,

XTiled does not do this positioning in it’s code, you’ll have to add it. I
mentioned this on the project’s issue page too. At this point, with XNA
abandoned by Microsoft, I’m not spending time on the project but you are
welcome to fork the project or look into those that have and may have added
support for objects in other map formats.

Mike

okay got it, thanks a lot guys @bjorn @michael_neel
this is the code where XTiled take the objects layers’ polylines and stores them for rendering later on, tell me if you make something of this?! or if i can translate then store them ?


o.Polyline = null;
if (oElem.Element("polyline") != null) {
     List points = new List();
     foreach (var point in oElem.Element("polyline").Attribute("points").Value.Split(" ".ToCharArray(),StringSplitOptions.RemoveEmptyEntries)) {

  String[] coord = point.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  points.Add(new Point(o.Bounds.X + Convert.ToInt32(coord[0]), o.Bounds.Y + Convert.ToInt32(coord[1])));      
}
      o.Polyline = Polyline.FromPoints(points);
      o.Bounds = o.Polyline.Bounds;
                    }