Example usage for com.badlogic.gdx.maps Map getLayers

List of usage examples for com.badlogic.gdx.maps Map getLayers

Introduction

In this page you can find the example usage for com.badlogic.gdx.maps Map getLayers.

Prototype

public MapLayers getLayers() 

Source Link

Usage

From source file:com.cafeitvn.myballgame.screen.Box2DMapObjectParser.java

License:Apache License

/**
 * creates the given {@link Map Map's} {@link MapObjects} in the given {@link World}  
 * @param world the {@link World} to create the {@link MapObjects} of the given {@link Map} in
 * @param map the {@link Map} which {@link MapObjects} to create in the given {@link World}
 * @return the given {@link World} with the parsed {@link MapObjects} of the given {@link Map} created in it
 *///w  ww  . j  a  va2s  .co m
public World load(World world, Map map) {
    if (!ignoreMapUnitScale)
        unitScale = (Float) getProperty(map.getProperties(), aliases.unitScale, unitScale, Float.class);
    tileWidth = (Integer) getProperty(map.getProperties(), "tilewidth", tileWidth, Integer.class);
    tileHeight = (Integer) getProperty(map.getProperties(), "tileheight", tileHeight, Integer.class);

    for (MapLayer mapLayer : map.getLayers())
        load(world, mapLayer);

    return world;
}

From source file:com.cafeitvn.myballgame.screen.Box2DMapObjectParser.java

License:Apache License

/**
 * @param map the {@link Map} which hierarchy to print
 * @return a human readable {@link String} containing the hierarchy of the {@link MapObjects} of the given {@link Map}
 *//*  w w  w  . j av  a  2  s  .  c  o m*/
public String getHierarchy(Map map) {
    String hierarchy = map.getClass().getSimpleName() + "\n";

    Iterator<String> keys = map.getProperties().getKeys();
    while (keys.hasNext()) {
        String key = keys.next();
        hierarchy += key + ": " + map.getProperties().get(key) + "\n";
    }

    for (MapLayer layer : map.getLayers()) {
        hierarchy += "\t" + layer.getName() + " (" + layer.getClass().getSimpleName() + "):\n";
        String layerHierarchy = getHierarchy(layer).replace("\n", "\n\t\t");
        layerHierarchy = layerHierarchy.endsWith("\n\t\t")
                ? layerHierarchy.substring(0, layerHierarchy.lastIndexOf("\n\t\t"))
                : layerHierarchy;
        hierarchy += !layerHierarchy.equals("") ? "\t\t" + layerHierarchy : layerHierarchy;
    }

    return hierarchy;
}

From source file:com.indignado.games.smariano.utils.dermetfan.box2d.Box2DMapObjectParser.java

License:Apache License

/**
 * creates the given {@link com.badlogic.gdx.maps.Map Map's} {@link com.badlogic.gdx.maps.MapObjects} in the given {@link com.badlogic.gdx.physics.box2d.World}
 *
 * @param world the {@link com.badlogic.gdx.physics.box2d.World} to create the {@link com.badlogic.gdx.maps.MapObjects} of the given {@link com.badlogic.gdx.maps.Map} in
 * @param map   the {@link com.badlogic.gdx.maps.Map} which {@link com.badlogic.gdx.maps.MapObjects} to create in the given {@link com.badlogic.gdx.physics.box2d.World}
 * @return the given {@link com.badlogic.gdx.physics.box2d.World} with the parsed {@link com.badlogic.gdx.maps.MapObjects} of the given {@link com.badlogic.gdx.maps.Map} created in it
 *//* ww w .  j  ava 2s  .c  o  m*/
public World load(World world, Map map) {
    if (!ignoreMapUnitScale)
        unitScale = getProperty(map.getProperties(), aliases.unitScale, unitScale);
    box2dObjectFactory.setUnitScale(unitScale);
    tileWidth = getProperty(map.getProperties(), "tilewidth", (int) tileWidth);
    tileHeight = getProperty(map.getProperties(), "tileheight", (int) tileHeight);

    for (MapLayer mapLayer : map.getLayers())
        load(world, mapLayer);

    return world;
}

From source file:com.indignado.games.smariano.utils.dermetfan.box2d.Box2DMapObjectParser.java

License:Apache License

/**
 * @param map the {@link com.badlogic.gdx.maps.Map} which hierarchy to print
 * @return a human readable {@link String} containing the hierarchy of the {@link com.badlogic.gdx.maps.MapObjects} of the given {@link com.badlogic.gdx.maps.Map}
 *//*from   ww  w  .  ja v a  2 s.  co m*/
public String getHierarchy(Map map) {
    String hierarchy = map.getClass().getName() + "\n", key, layerHierarchy;

    Iterator<String> keys = map.getProperties().getKeys();
    while (keys.hasNext())
        hierarchy += (key = keys.next()) + ": " + map.getProperties().get(key) + "\n";

    for (MapLayer layer : map.getLayers()) {
        hierarchy += "\t" + layer.getName() + " (" + layer.getClass().getName() + "):\n";
        layerHierarchy = getHierarchy(layer).replace("\n", "\n\t\t");
        layerHierarchy = layerHierarchy.endsWith("\n\t\t")
                ? layerHierarchy.substring(0, layerHierarchy.lastIndexOf("\n\t\t"))
                : layerHierarchy;
        hierarchy += !layerHierarchy.equals("") ? "\t\t" + layerHierarchy : layerHierarchy;
    }

    return hierarchy;
}

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  ava 2 s  .  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();
    }
}

From source file:com.stercore.code.net.dermetfan.utils.libgdx.maps.MapUtils.java

License:Apache License

/** @param map the map to represent
 *  @param indent the indentation size (indent is {@code '\t'})
 *  @return a human-readable hierarchy of the given map and its descendants */
public static String readableHierarchy(Map map, int indent) {
    String hierarchy = "";
    for (int i = 0; i < indent; i++)
        hierarchy += '\t';
    hierarchy += ClassReflection.getSimpleName(map.getClass()) + '\n';
    hierarchy += readableHierarchy(map.getProperties(), indent + 1);
    if (map instanceof TiledMap)
        hierarchy += readableHierarchy(((TiledMap) map).getTileSets(), indent + 1);
    hierarchy += readableHierarchy(map.getLayers(), indent + 1);
    return hierarchy;
}

From source file:com.stercore.code.net.dermetfan.utils.libgdx.maps.TmxMapWriter.java

License:Apache License

/** @param map the {@link Map} to write in TMX format
 *  @param format the {@link Format} to use
 *  @return this {@link TmxMapWriter} */
public TmxMapWriter tmx(Map map, Format format) throws IOException {
    append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    append("<!DOCTYPE map SYSTEM \"http://mapeditor.org/dtd/1.0/map.dtd\">\n");

    MapProperties props = map.getProperties();
    int height = getProperty(props, "height", 0);
    int tileHeight = getProperty(props, "tileheight", 0);
    int oldLayerHeight = layerHeight;
    layerHeight = height * tileHeight;/*from  w w w. j av a 2 s  .  co m*/

    element("map");
    attribute("version", "1.0");
    attribute("orientation", getProperty(props, "orientation", "orthogonal"));
    attribute("width", getProperty(props, "width", 0));
    attribute("height", height);
    attribute("tilewidth", getProperty(props, "tilewidth", 0));
    attribute("tileheight", tileHeight);

    @SuppressWarnings("unchecked")
    Array<String> excludedKeys = Pools.obtain(Array.class);
    excludedKeys.clear();
    excludedKeys.add("version");
    excludedKeys.add("orientation");
    excludedKeys.add("width");
    excludedKeys.add("height");
    excludedKeys.add("tilewidth");
    excludedKeys.add("tileheight");
    tmx(props, excludedKeys);
    excludedKeys.clear();
    Pools.free(excludedKeys);

    if (map instanceof TiledMap)
        tmx(((TiledMap) map).getTileSets());

    tmx(map.getLayers(), format);

    pop();

    layerHeight = oldLayerHeight;
    return this;
}

From source file:de.fhkoeln.game.utils.libgdx.maps.MapUtils.java

License:Apache License

/** @param map the map to represent
 *  @param indent the indentation size (indent is {@code '\t'})
 *  @return a human-readable hierarchy of the given map and its descendants */
public static String readableHierarchy(Map map, int indent) {
    String hierarchy = "";
    for (int i = 0; i < indent; i++)
        hierarchy += '\t';
    hierarchy += map.getClass().getSimpleName() + '\n';
    hierarchy += readableHierarchy(map.getProperties(), indent + 1);
    if (map instanceof TiledMap)
        hierarchy += readableHierarchy(((TiledMap) map).getTileSets(), indent + 1);
    hierarchy += readableHierarchy(map.getLayers(), indent + 1);
    return hierarchy;
}

From source file:net.dermetfan.gdx.maps.MapUtils.java

License:Apache License

/** @param map the map to represent
 *  @param indent the indentation size (indent is {@code '\t'})
 *  @return a human-readable hierarchy of the given map and its descendants */
public static String readableHierarchy(Map map, int indent) {
    StringBuilder hierarchy = new StringBuilder();
    for (int i = 0; i < indent; i++)
        hierarchy.append('\t');
    hierarchy.append(ClassReflection.getSimpleName(map.getClass())).append('\n');
    hierarchy.append(readableHierarchy(map.getProperties(), indent + 1));
    if (map instanceof TiledMap)
        hierarchy.append(readableHierarchy(((TiledMap) map).getTileSets(), indent + 1));
    hierarchy.append(readableHierarchy(map.getLayers(), indent + 1));
    return hierarchy.toString();
}

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

License:Apache License

/** creates the given {@link Map Map's} {@link MapObjects} in the given {@link World}  
 *  @param world the {@link World} to create the {@link MapObjects} of the given {@link Map} in
 *  @param map the {@link Map} which {@link MapObjects} to create in the given {@link World}
 *  @return the given {@link World} with the parsed {@link MapObjects} of the given {@link Map} created in it */
public World load(World world, Map map) {
    MapProperties oldMapProperties = mapProperties;
    mapProperties = map.getProperties();

    world.setGravity(vec2.set(getProperty(mapProperties, aliases.gravityX, world.getGravity().x),
            getProperty(mapProperties, aliases.gravityY, world.getGravity().y)));
    world.setAutoClearForces(getProperty(mapProperties, aliases.autoClearForces, world.getAutoClearForces()));

    if (!ignoreMapUnitScale)
        unitScale = getProperty(mapProperties, aliases.unitScale, unitScale);
    tileWidth = getProperty(mapProperties, aliases.tileWidth, tileWidth);
    tileHeight = getProperty(mapProperties, aliases.tileHeight, tileHeight);

    for (MapLayer mapLayer : map.getLayers())
        load(world, mapLayer);//from w  ww. j a  v  a 2 s. co m

    mapProperties = oldMapProperties;
    return world;
}