Skip to content

Points Brief Example

Paul Robinson edited this page May 4, 2012 · 1 revision

Polyline Polygons and normal square objects

 <objectgroup name="polygon" width="5" height="5" visible="0">
  <object x="0" y="64">
   <polygon points="0,0 32,0 0,32"/>
  </object>
</objectgroup>
 <objectgroup name="polylines" width="5" height="5" visible="0">
  <object x="96" y="0">
   <polyline points="0,0 64,0 64,32 32,0 32,32 0,32 0,0"/>
  </object>
 </objectgroup>

The points are in Tiled pixel space.

The above line is some poly points on two layers layers. To access these points, first get the TMXObjectGroup, let say polygon layer, get the only object, get the points 2d Array.

String objectGroupName = "polygon"
for (TMXObjectGroup objG : this.mMap.getTMXObjectGroups()) {
			if(objG.getName().equals(objectGroupName)){
				TMXObject tmxObject = objG.getTMXObjects().get(0);
				int[][] points = tmxObject.getPolygonPoints();
			}
		}

The object X location is across the columns, Y is the location down the rows.

So in the polygon layer single object, there are three sets of points, with the first number of each set is X the second number Y. The points are relative to the object X and Y (so 0,0 is really the location of X: 0 Y: 64)

  • 0,0 (X: 0 Y: 0)
  • 32,0 (X: 32 Y: 0)
  • 0,32 (X: 0 Y: 32)

points[A][B]

The range of A is 3 (0 till 2)

The range of B is either 0 or 1. 0 = X 1 = Y

points[1][0] is the X location of the second set (32,0)

Later on I will provide an image explaining how to use the object X and Y.

In the mean time check out the post on Tiled github issue page.

Here is a quote and a little quick maths to get you started.

Right, in that case the observed behavior makes sense. In isometric, the "pixel size" of an object is a bit weird, since as you will have noticed the objects are transformed to correct for the perspective of the map. For these types of maps, Tiled multiplies both the width and height of the object (as specified in tiles) with the tile height in pixels that you filled in when creating the map. So when loading an isometric map, you would divide the object dimensions only by the tile height and forget about the tile width, to get the size of the object in tiles.

I guess this is one of those peculiarities that should really be well documented somewhere... it is also the reason that I somewhat regret storing object sizes in pixels rather than tiles, cause the latter would have been much clearer in this case.

Clone this wiki locally