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;
}

Edited 2 Years Ago by android_gl

note: ellipse doesnt work right.

define "doesnt work right". is there an error. is the output not what you expect? what do you expect, and what do you get?

output and errors:
error1: EllipseShape cannot be resolved to a type
error2: radius cannot be resolved or is not a field
alot i dont thing i am using ellipse logic right

///////////////////////////////////////

i was thing this:

private static EllipseShape getEllipse(EllipseMapObject circleObject) {
    Ellipse ellipse = circleObject.getEllipse();
    EllipseShape ellipseShape = new EllipseShape();
    ellipseShape.setPosition(new Vector2(ellipse.x+ellipse.width/ PPM, ellipse.y+ellipse.height / PPM));
    return ellipseShape;
}

than i get 1 error:
error1: EllipseShape cannot be resolved to a type

Edited 2 Years Ago by android_gl

SllipseShape seems to be either not existing, or not in scope and/or imported.
my guess for radius: you didn't declare it, or outside the scope where you use it.

ok here is the problem i think:

else if (mo instanceof EllipseMapObject) {
            shape = getEllipse((EllipseMapObject) mo);
        }

in this method i am trying to create ellipse and store in variables called shape.

problem is that there is no 'EllipseShape' in libgdx. but I dont know how can i use 'EllipseMapObject' to store Ellipse in 'Shape' variable.

private static EllipseShape getEllipse(EllipseMapObject circleObject) {
        Ellipse ellipse = circleObject.getEllipse();
        EllipseShape ellipseShape = new EllipseShape();
        ellipseShape.setPosition(new Vector2(ellipse.x+ellipse.width/ PPM, ellipse.y+ellipse.height / PPM));
        return ellipseShape;
    }

there is CircleShape, chanShape, PolygenShape but no EllipseShape. i dont understant how can I store 'Ellipse' in 'Shape variable' if there is no EllipseShape.

p.s new to libgdx

Edited 2 Years Ago by android_gl

you can't. either you create an EllipseMapObject, or you'll have to find a way to create an 'Ellipse' using the existing types.
for instance: a circle that you 'stretch out'

o ok. i think this should work.

private static CircleShape getEllipse(EllipseMapObject ellipseObject) {
    Ellipse ellipse = ellipseObject.getEllipse();
    CircleShape circleShape = new CircleShape();
    ellipseShape.setPosition(new Vector2(ellipse.x / PPM, ellipse.y / PPM));
    return ellipseShape;
}
This question has already been answered. Start a new discussion instead.