Slick Forums

Discuss the Slick 2D Library
It is currently Sun Nov 19, 2017 3:04 am

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Wed Jul 31, 2013 3:13 pm 
Offline

Joined: Tue Dec 11, 2012 3:21 pm
Posts: 1
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;
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group