Example usage for com.badlogic.gdx.maps MapProperties get

List of usage examples for com.badlogic.gdx.maps MapProperties get

Introduction

In this page you can find the example usage for com.badlogic.gdx.maps MapProperties get.

Prototype

public <T> T get(String key, T defaultValue, Class<T> clazz) 

Source Link

Document

Returns the object for the given key, casting it to clazz.

Usage

From source file:com.siondream.core.physics.MapBodyManager.java

License:Open Source License

/**
 * @param map map to be used to create the static bodies. 
 * @param layerName name of the layer that contains the shapes.
 *///from w  ww  . j  a v a 2s  .c om
public void createPhysics(Map map, String layerName) {
    MapLayer layer = map.getLayers().get(layerName);

    if (layer == null) {
        logger.error("layer " + layerName + " does not exist");
        return;
    }

    MapObjects objects = layer.getObjects();
    Iterator<MapObject> objectIt = objects.iterator();

    while (objectIt.hasNext()) {
        MapObject object = objectIt.next();

        if (object instanceof TextureMapObject) {
            continue;
        }

        Shape shape;
        BodyDef bodyDef = new BodyDef();
        bodyDef.type = BodyDef.BodyType.StaticBody;

        if (object instanceof RectangleMapObject) {
            RectangleMapObject rectangle = (RectangleMapObject) object;
            shape = getRectangle(rectangle);
        } else if (object instanceof PolygonMapObject) {
            shape = getPolygon((PolygonMapObject) object);
        } else if (object instanceof PolylineMapObject) {
            shape = getPolyline((PolylineMapObject) object);
        } else if (object instanceof CircleMapObject) {
            shape = getCircle((CircleMapObject) object);
        } else {
            logger.error("non suported shape " + object);
            continue;
        }

        MapProperties properties = object.getProperties();
        String material = properties.get("material", "default", String.class);
        FixtureDef fixtureDef = materials.get(material);

        if (fixtureDef == null) {
            logger.error("material does not exist " + material + " using default");
            fixtureDef = materials.get("default");
        }

        fixtureDef.shape = shape;
        //fixtureDef.filter.categoryBits = Env.game.getCategoryBitsManager().getCategoryBits("level");

        Body body = world.createBody(bodyDef);
        body.createFixture(fixtureDef);

        bodies.add(body);

        fixtureDef.shape = null;
        shape.dispose();
    }
}