Example usage for com.badlogic.gdx.maps.objects PolygonMapObject setVisible

List of usage examples for com.badlogic.gdx.maps.objects PolygonMapObject setVisible

Introduction

In this page you can find the example usage for com.badlogic.gdx.maps.objects PolygonMapObject setVisible.

Prototype

public void setVisible(boolean visible) 

Source Link

Usage

From source file:com.rubentxu.juegos.core.utils.dermetfan.box2d.Box2DMapObjectParser.java

License:Apache License

/**
 * creates {@link Fixture Fixtures} from a {@link MapObject}
 *
 * @param mapObject the {@link MapObject} to parse
 * @return an array of parsed {@link Fixture Fixtures}
 *//*from ww  w .j  av  a 2s .c  o  m*/
public Fixture[] createFixtures(MapObject mapObject) {
    Polygon polygon;

    if (!(mapObject instanceof PolygonMapObject)
            || isConvex(polygon = ((PolygonMapObject) mapObject).getPolygon()))
        return new Fixture[] { createFixture(mapObject) };

    Polygon[] convexPolygons;
    if (triangulate) {
        if (areVerticesClockwise(polygon)) { // ensure the vertices are in counterclockwise order (not really necessary according to EarClippingTriangulator's javadoc, but sometimes better)
            Array<Vector2> vertices = new Array<Vector2>(toVector2Array(polygon.getVertices()));
            Vector2 first = vertices.removeIndex(0);
            vertices.reverse();
            vertices.insert(0, first);
            polygon.setVertices(toFloatArray(vertices.items));
        }
        convexPolygons = toPolygonArray(toVector2Array(
                new EarClippingTriangulator().computeTriangles(polygon.getTransformedVertices()).toArray()), 3);
    } else {
        Array<Array<Vector2>> convexPolys = BayazitDecomposer
                .convexPartition(new Array<Vector2>(toVector2Array(polygon.getTransformedVertices())));
        convexPolygons = new Polygon[convexPolys.size];
        for (int i = 0; i < convexPolygons.length; i++)
            convexPolygons[i] = new Polygon(
                    toFloatArray((Vector2[]) convexPolys.get(i).toArray(Vector2.class)));
    }

    // create the fixtures using the convex polygons
    Fixture[] fixtures = new Fixture[convexPolygons.length];
    for (int i = 0; i < fixtures.length; i++) {
        PolygonMapObject convexObject = new PolygonMapObject(convexPolygons[i]);
        convexObject.setColor(mapObject.getColor());
        convexObject.setName(mapObject.getName());
        convexObject.setOpacity(mapObject.getOpacity());
        convexObject.setVisible(mapObject.isVisible());
        convexObject.getProperties().putAll(mapObject.getProperties());
        fixtures[i] = createFixture(convexObject);
    }

    return fixtures;
}

From source file:com.stercore.code.net.dermetfan.utils.libgdx.box2d.Box2DMapObjectParser.java

License:Apache License

/** creates {@link Fixture Fixtures} from a {@link MapObject}
 *  @param mapObject the {@link MapObject} to parse
 *  @param body the {@link Body} to create the {@link Fixture Fixtures} on
 *  @return an array of parsed {@link Fixture Fixtures} */
public Fixture[] createFixtures(MapObject mapObject, Body body) {
    if ((mapObject = listener.createFixtures(mapObject)) == null)
        return null;

    Polygon polygon;//from  ww  w .jav  a  2s . c o  m

    if (!(mapObject instanceof PolygonMapObject)
            || isConvex(polygon = ((PolygonMapObject) mapObject).getPolygon())
                    && (!Box2DUtils.checkPreconditions
                            || polygon.getVertices().length / 2 <= Box2DUtils.maxPolygonVertices))
        return new Fixture[] { createFixture(mapObject, body) };

    Polygon[] convexPolygons = triangulate ? triangulate(polygon) : decompose(polygon);
    Fixture[] fixtures = new Fixture[convexPolygons.length];
    for (int i = 0; i < fixtures.length; i++) {
        PolygonMapObject convexObject = new PolygonMapObject(convexPolygons[i]);
        convexObject.setColor(mapObject.getColor());
        convexObject.setName(mapObject.getName());
        convexObject.setOpacity(mapObject.getOpacity());
        convexObject.setVisible(mapObject.isVisible());
        convexObject.getProperties().putAll(mapObject.getProperties());
        fixtures[i] = createFixture(convexObject, body);
    }

    return fixtures;
}

From source file:net.dermetfan.gdx.physics.box2d.Box2DMapObjectParser.java

License:Apache License

/** creates {@link Fixture Fixtures} from a {@link MapObject}
 *  @param mapObject the {@link MapObject} to parse
 *  @param body the {@link Body} to create the {@link Fixture Fixtures} on
 *  @return an array of parsed {@link Fixture Fixtures} */
public Fixture[] createFixtures(MapObject mapObject, Body body) {
    if ((mapObject = listener.createFixtures(mapObject)) == null)
        return null;

    Polygon polygon;/*  www .  j a  v a2  s .c  om*/

    if (!(mapObject instanceof PolygonMapObject)
            || isConvex(polygon = ((PolygonMapObject) mapObject).getPolygon())
                    && Box2DUtils.check.isValidPolygonShape(polygon.getVertices()))
        return new Fixture[] { createFixture(mapObject, body) };

    Polygon[] convexPolygons = toPolygonArray(triangulate ? triangulate(polygon.getTransformedVertices())
            : decompose(polygon.getTransformedVertices()));
    Fixture[] fixtures = new Fixture[convexPolygons.length];
    for (int i = 0; i < fixtures.length; i++) {
        PolygonMapObject convexObject = new PolygonMapObject(convexPolygons[i]);
        convexObject.setColor(mapObject.getColor());
        convexObject.setName(mapObject.getName());
        convexObject.setOpacity(mapObject.getOpacity());
        convexObject.setVisible(mapObject.isVisible());
        convexObject.getProperties().putAll(mapObject.getProperties());
        fixtures[i] = createFixture(convexObject, body);
    }

    return fixtures;
}

From source file:net.dermetfan.utils.libgdx.box2d.Box2DMapObjectParser.java

License:Apache License

/** creates {@link Fixture Fixtures} from a {@link MapObject}
 *  @param mapObject the {@link MapObject} to parse
 *  @param body the {@link Body} to create the {@link Fixture Fixtures} on
 *  @return an array of parsed {@link Fixture Fixtures} */
public Fixture[] createFixtures(MapObject mapObject, Body body) {
    Polygon polygon;//w  w  w  . jav a 2 s  .co  m

    if (!(mapObject instanceof PolygonMapObject)
            || isConvex(polygon = ((PolygonMapObject) mapObject).getPolygon()))
        return new Fixture[] { createFixture(mapObject, body) };

    Polygon[] convexPolygons;
    if (triangulate) {
        if (areVerticesClockwise(polygon)) { // ensure the vertices are in counterclockwise order (not really necessary according to EarClippingTriangulator's javadoc, but sometimes better)
            Array<Vector2> vertices = new Array<Vector2>(toVector2Array(polygon.getVertices()));
            Vector2 first = vertices.removeIndex(0);
            vertices.reverse();
            vertices.insert(0, first);
            polygon.setVertices(toFloatArray(vertices.items));
        }
        convexPolygons = triangulate(polygon);
    } else
        convexPolygons = decompose(polygon);

    // create the fixtures using the convex polygons
    Fixture[] fixtures = new Fixture[convexPolygons.length];
    for (int i = 0; i < fixtures.length; i++) {
        PolygonMapObject convexObject = new PolygonMapObject(convexPolygons[i]);
        convexObject.setColor(mapObject.getColor());
        convexObject.setName(mapObject.getName());
        convexObject.setOpacity(mapObject.getOpacity());
        convexObject.setVisible(mapObject.isVisible());
        convexObject.getProperties().putAll(mapObject.getProperties());
        fixtures[i] = createFixture(convexObject, body);
    }

    return fixtures;
}