}
}
protected void loadObject (MapLayer layer, Element element) {
if (element.getName().equals("object")) {
MapObject object = null;
float scaleX = convertObjectToTileSpace ? 1.0f / mapTileWidth : 1.0f;
float scaleY = convertObjectToTileSpace ? 1.0f / mapTileHeight : 1.0f;
float x = element.getFloatAttribute("x", 0) * scaleX;
float y = (mapHeightInPixels - element.getFloatAttribute("y", 0)) * scaleY;
float width = element.getFloatAttribute("width", 0) * scaleX;
float height = element.getFloatAttribute("height", 0) * scaleY;
if (element.getChildCount() > 0) {
Element child = null;
if ((child = element.getChildByName("polygon")) != null) {
String[] points = child.getAttribute("points").split(" ");
float[] vertices = new float[points.length * 2];
for (int i = 0; i < points.length; i++) {
String[] point = points[i].split(",");
vertices[i * 2] = Float.parseFloat(point[0]) * scaleX;
vertices[i * 2 + 1] = -Float.parseFloat(point[1]) * scaleY;
}
Polygon polygon = new Polygon(vertices);
polygon.setPosition(x, y);
object = new PolygonMapObject(polygon);
} else if ((child = element.getChildByName("polyline")) != null) {
String[] points = child.getAttribute("points").split(" ");
float[] vertices = new float[points.length * 2];
for (int i = 0; i < points.length; i++) {
String[] point = points[i].split(",");
vertices[i * 2] = Float.parseFloat(point[0]) * scaleX;
vertices[i * 2 + 1] = -Float.parseFloat(point[1]) * scaleY;
}
Polyline polyline = new Polyline(vertices);
polyline.setPosition(x, y);
object = new PolylineMapObject(polyline);
} else if ((child = element.getChildByName("ellipse")) != null) {
object = new EllipseMapObject(x, y - height, width, height);
}
}
if (object == null) {
object = new RectangleMapObject(x, y - height, width, height);
}
object.setName(element.getAttribute("name", null));
String rotation = element.getAttribute("rotation", null);
if (rotation != null) {
object.getProperties().put("rotation", Float.parseFloat(rotation));
}
String type = element.getAttribute("type", null);
if (type != null) {
object.getProperties().put("type", type);
}
int gid = element.getIntAttribute("gid", -1);
if (gid != -1) {
object.getProperties().put("gid", gid);
}
object.getProperties().put("x", x * scaleX);
object.getProperties().put("y", (y - height) * scaleY);
object.setVisible(element.getIntAttribute("visible", 1) == 1);
Element properties = element.getChildByName("properties");
if (properties != null) {
loadProperties(object.getProperties(), properties);
}
layer.getObjects().add(object);
}
}