I am using software to create tile map. on map there are different objects ex circle, rectangle, ellipse, polygon etc...
I have problem creating ellipse shape. other than that every thing works fine.
** //loop though map objects and store in 'shape variable'.
//so if its circle than store in 'shpae variable'.
//if its ellipse than store in 'shape varibale'. and so on
note: ellipse doesnt work right.
**
private void createTileLayer(String layerName) {
MapLayer layer = tileMap.getLayers().get(layerName);
for (MapObject mo : layer.getObjects()) {
Shape shape = null;
shape = createShapes(mo, shape);
...
}
....
}
** this method is just fill with if statments. and run different methods below.
note: ellipse doesnt work right.
**
private Shape createShapes(MapObject mo, Shape shape) {
if (mo instanceof RectangleMapObject) {
shape = getRectangle((RectangleMapObject) mo);
} else if (mo instanceof PolygonMapObject) {
shape = getPolygon((PolygonMapObject) mo);
} else if (mo instanceof PolylineMapObject) {
shape = getPolyline((PolylineMapObject) mo);
} else if (mo instanceof CircleMapObject) {
shape = getCircle((CircleMapObject) mo);
} else if (mo instanceof EllipseMapObject) {
shape = getEllipse((EllipseMapObject) mo);
}
return shape;
}
** these method below create shapes.
note: ellipse doesnt work right.
**
private static PolygonShape getRectangle(RectangleMapObject rectangleObject) {
Rectangle rectangle = rectangleObject.getRectangle();
PolygonShape polygon = new PolygonShape();
Vector2 size = new Vector2(
(rectangle.x + rectangle.width * 0.5f) / PPM,
(rectangle.y + rectangle.height * 0.5f) / PPM);
polygon.setAsBox(rectangle.width * 0.5f / PPM, rectangle.height * 0.5f
/ PPM, size, 0.0f);
return polygon;
}
private static CircleShape getCircle(CircleMapObject circleObject) {
Circle circle = circleObject.getCircle();
CircleShape circleShape = new CircleShape();
circleShape.setRadius(circle.radius / PPM);
circleShape.setPosition(new Vector2(circle.x / PPM, circle.y / PPM));
return circleShape;
}
private static EllipseShape getEllipse(EllipseMapObject circleObject) {
Ellipse ellipse = circleObject.getEllipse();
EllipseShape ellipseShape = new CircleShape();
ellipseShape.setRadius(ellipse.radius / PPM);
ellipseShape.setPosition(new Vector2(ellipse.x / PPM, ellipse.y / PPM));
return ellipseShape;
}