Slick Forums

TileDMap support for more features of the TMX format
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 (

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

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

2.Update the reading method in the constructor of GroupObject
         props.setProperty(name, value);
//read polygon points
Element polyElement = (Element) element.getElementsByTagName("polygon").item(0);
   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
* 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