Slick Forums
http://slick.ninjacave.com/forum/

TileDMap support for more features of the TMX format
http://slick.ninjacave.com/forum/viewtopic.php?f=27&t=6659
Page 1 of 1

Author:  SwiftPengu [ Wed Jul 31, 2013 3:13 pm ]
Post subject:  TileDMap support for more features of the TMX format

The current TileDMap class does not support all features of the .tmx format (https://github.com/bjorn/tiled/wiki/TMX-Map-Format).

I've already implemented some kind of support for polygons (note that I have no idea how the TileDMap class works, so my implementation might be inefficient. Maybe the class needs to be rewritten to make it efficient as a whole?)

Changes in TileDMap.java:

1.Add a field to store the polygon points to the GroupObject class
Code:
...
/** the properties of this group */
public Properties props;
   
public List<Point> polygonpoints;
...


2.Update the reading method in the constructor of GroupObject
Code:
...
         props.setProperty(name, value);
      }
   }
}
         
//read polygon points
Element polyElement = (Element) element.getElementsByTagName("polygon").item(0);
if(polyElement!=null){
   String[] coordinates = polyElement.getAttribute("points").split("\\ ");
        //update the field
   polygonpoints = new ArrayList<Point>(coordinates.length);
        //and add the coordinates
   for(String coordinate:coordinates){
                //get the individual coordinates
      String[] point = coordinate.split(",");
      polygonpoints.add(new Point(Float.parseFloat(point[0]),Float.parseFloat(point[1])));
   }
}
...



3.Add this method to the TileDMap class
Code:
/**
* Get the list of polygon points of an object
* Returns null if there are no polygon points defined
*/
public List<Point> getPolygonPoints(int groupID, int objectID){
   if (groupID >= 0 && groupID < objectGroups.size()) {
      ObjectGroup grp = (ObjectGroup) objectGroups.get(groupID);
      if (objectID >= 0 && objectID < grp.objects.size()) {
         GroupObject object = (GroupObject) grp.objects.get(objectID);
         return object.polygonpoints;
      }
   }
   return null;
}

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/