Search in sources :

Example 6 with MapProperties

use of com.badlogic.gdx.maps.MapProperties in project libgdx by libgdx.

the class AtlasTmxMapLoader method loadTileset.

protected void loadTileset(TiledMap map, Element element, FileHandle tmxFile, AtlasResolver resolver) {
    if (element.getName().equals("tileset")) {
        String name = element.get("name", null);
        int firstgid = element.getIntAttribute("firstgid", 1);
        int tilewidth = element.getIntAttribute("tilewidth", 0);
        int tileheight = element.getIntAttribute("tileheight", 0);
        int spacing = element.getIntAttribute("spacing", 0);
        int margin = element.getIntAttribute("margin", 0);
        String source = element.getAttribute("source", null);
        int offsetX = 0;
        int offsetY = 0;
        String imageSource = "";
        int imageWidth = 0, imageHeight = 0;
        FileHandle image = null;
        if (source != null) {
            FileHandle tsx = getRelativeFileHandle(tmxFile, source);
            try {
                element = xml.parse(tsx);
                name = element.get("name", null);
                tilewidth = element.getIntAttribute("tilewidth", 0);
                tileheight = element.getIntAttribute("tileheight", 0);
                spacing = element.getIntAttribute("spacing", 0);
                margin = element.getIntAttribute("margin", 0);
                Element offset = element.getChildByName("tileoffset");
                if (offset != null) {
                    offsetX = offset.getIntAttribute("x", 0);
                    offsetY = offset.getIntAttribute("y", 0);
                }
                Element imageElement = element.getChildByName("image");
                if (imageElement != null) {
                    imageSource = imageElement.getAttribute("source");
                    imageWidth = imageElement.getIntAttribute("width", 0);
                    imageHeight = imageElement.getIntAttribute("height", 0);
                    image = getRelativeFileHandle(tsx, imageSource);
                }
            } catch (IOException e) {
                throw new GdxRuntimeException("Error parsing external tileset.");
            }
        } else {
            Element offset = element.getChildByName("tileoffset");
            if (offset != null) {
                offsetX = offset.getIntAttribute("x", 0);
                offsetY = offset.getIntAttribute("y", 0);
            }
            Element imageElement = element.getChildByName("image");
            if (imageElement != null) {
                imageSource = imageElement.getAttribute("source");
                imageWidth = imageElement.getIntAttribute("width", 0);
                imageHeight = imageElement.getIntAttribute("height", 0);
                image = getRelativeFileHandle(tmxFile, imageSource);
            }
        }
        String atlasFilePath = map.getProperties().get("atlas", String.class);
        if (atlasFilePath == null) {
            FileHandle atlasFile = tmxFile.sibling(tmxFile.nameWithoutExtension() + ".atlas");
            if (atlasFile.exists())
                atlasFilePath = atlasFile.name();
        }
        if (atlasFilePath == null) {
            throw new GdxRuntimeException("The map is missing the 'atlas' property");
        }
        // get the TextureAtlas for this tileset
        FileHandle atlasHandle = getRelativeFileHandle(tmxFile, atlasFilePath);
        atlasHandle = resolve(atlasHandle.path());
        TextureAtlas atlas = resolver.getAtlas(atlasHandle.path());
        String regionsName = name;
        for (Texture texture : atlas.getTextures()) {
            trackedTextures.add(texture);
        }
        TiledMapTileSet tileset = new TiledMapTileSet();
        MapProperties props = tileset.getProperties();
        tileset.setName(name);
        props.put("firstgid", firstgid);
        props.put("imagesource", imageSource);
        props.put("imagewidth", imageWidth);
        props.put("imageheight", imageHeight);
        props.put("tilewidth", tilewidth);
        props.put("tileheight", tileheight);
        props.put("margin", margin);
        props.put("spacing", spacing);
        if (imageSource != null && imageSource.length() > 0) {
            int lastgid = firstgid + ((imageWidth / tilewidth) * (imageHeight / tileheight)) - 1;
            for (AtlasRegion region : atlas.findRegions(regionsName)) {
                // handle unused tile ids
                if (region != null) {
                    int tileid = region.index + 1;
                    if (tileid >= firstgid && tileid <= lastgid) {
                        StaticTiledMapTile tile = new StaticTiledMapTile(region);
                        tile.setId(tileid);
                        tile.setOffsetX(offsetX);
                        tile.setOffsetY(flipY ? -offsetY : offsetY);
                        tileset.putTile(tileid, tile);
                    }
                }
            }
        }
        for (Element tileElement : element.getChildrenByName("tile")) {
            int tileid = firstgid + tileElement.getIntAttribute("id", 0);
            TiledMapTile tile = tileset.getTile(tileid);
            if (tile == null) {
                Element imageElement = tileElement.getChildByName("image");
                if (imageElement != null) {
                    // Is a tilemap with individual images.
                    String regionName = imageElement.getAttribute("source");
                    regionName = regionName.substring(0, regionName.lastIndexOf('.'));
                    AtlasRegion region = atlas.findRegion(regionName);
                    if (region == null)
                        throw new GdxRuntimeException("Tileset region not found: " + regionName);
                    tile = new StaticTiledMapTile(region);
                    tile.setId(tileid);
                    tile.setOffsetX(offsetX);
                    tile.setOffsetY(flipY ? -offsetY : offsetY);
                    tileset.putTile(tileid, tile);
                }
            }
            if (tile != null) {
                String terrain = tileElement.getAttribute("terrain", null);
                if (terrain != null) {
                    tile.getProperties().put("terrain", terrain);
                }
                String probability = tileElement.getAttribute("probability", null);
                if (probability != null) {
                    tile.getProperties().put("probability", probability);
                }
                Element properties = tileElement.getChildByName("properties");
                if (properties != null) {
                    loadProperties(tile.getProperties(), properties);
                }
            }
        }
        Array<Element> tileElements = element.getChildrenByName("tile");
        Array<AnimatedTiledMapTile> animatedTiles = new Array<AnimatedTiledMapTile>();
        for (Element tileElement : tileElements) {
            int localtid = tileElement.getIntAttribute("id", 0);
            TiledMapTile tile = tileset.getTile(firstgid + localtid);
            if (tile != null) {
                Element animationElement = tileElement.getChildByName("animation");
                if (animationElement != null) {
                    Array<StaticTiledMapTile> staticTiles = new Array<StaticTiledMapTile>();
                    IntArray intervals = new IntArray();
                    for (Element frameElement : animationElement.getChildrenByName("frame")) {
                        staticTiles.add((StaticTiledMapTile) tileset.getTile(firstgid + frameElement.getIntAttribute("tileid")));
                        intervals.add(frameElement.getIntAttribute("duration"));
                    }
                    AnimatedTiledMapTile animatedTile = new AnimatedTiledMapTile(intervals, staticTiles);
                    animatedTile.setId(tile.getId());
                    animatedTiles.add(animatedTile);
                    tile = animatedTile;
                }
                String terrain = tileElement.getAttribute("terrain", null);
                if (terrain != null) {
                    tile.getProperties().put("terrain", terrain);
                }
                String probability = tileElement.getAttribute("probability", null);
                if (probability != null) {
                    tile.getProperties().put("probability", probability);
                }
                Element properties = tileElement.getChildByName("properties");
                if (properties != null) {
                    loadProperties(tile.getProperties(), properties);
                }
            }
        }
        for (AnimatedTiledMapTile tile : animatedTiles) {
            tileset.putTile(tile.getId(), tile);
        }
        Element properties = element.getChildByName("properties");
        if (properties != null) {
            loadProperties(tileset.getProperties(), properties);
        }
        map.getTileSets().addTileSet(tileset);
    }
}
Also used : AnimatedTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.AnimatedTiledMapTile) FileHandle(com.badlogic.gdx.files.FileHandle) Element(com.badlogic.gdx.utils.XmlReader.Element) MapProperties(com.badlogic.gdx.maps.MapProperties) IOException(java.io.IOException) Texture(com.badlogic.gdx.graphics.Texture) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) Array(com.badlogic.gdx.utils.Array) IntArray(com.badlogic.gdx.utils.IntArray) LongArray(com.badlogic.gdx.utils.LongArray) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) AnimatedTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.AnimatedTiledMapTile) IntArray(com.badlogic.gdx.utils.IntArray) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) StaticTiledMapTile(com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile) AtlasRegion(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion)

Example 7 with MapProperties

use of com.badlogic.gdx.maps.MapProperties in project Entitas-Java by Rubentxu.

the class Box2DMapObjectParser method createJoint.

/**
     * creates a {@link Joint} from a {@link MapObject}
     *
     * @param mapObject the {@link Joint} to parse
     * @return the parsed {@link Joint}
     */
public Joint createJoint(MapObject mapObject) {
    MapProperties properties = mapObject.getProperties();
    JointDef jointDef = null;
    String type = properties.get("type", String.class);
    if (!type.equals(aliases.joint))
        throw new IllegalArgumentException("type of " + mapObject + " is  \"" + type + "\" instead of \"" + aliases.joint + "\"");
    String jointType = properties.get(aliases.jointType, String.class);
    // get all possible values
    if (jointType.equals(aliases.distanceJoint)) {
        DistanceJointDef distanceJointDef = new DistanceJointDef();
        distanceJointDef.dampingRatio = getProperty(properties, aliases.dampingRatio, distanceJointDef.dampingRatio);
        distanceJointDef.frequencyHz = getProperty(properties, aliases.frequencyHz, distanceJointDef.frequencyHz);
        distanceJointDef.length = getProperty(properties, aliases.length, distanceJointDef.length) * (tileWidth + tileHeight) / 2 * unitScale;
        distanceJointDef.localAnchorA.set(getProperty(properties, aliases.localAnchorAX, distanceJointDef.localAnchorA.x) * tileWidth * unitScale, getProperty(properties, aliases.localAnchorAY, distanceJointDef.localAnchorA.y) * tileHeight * unitScale);
        distanceJointDef.localAnchorB.set(getProperty(properties, aliases.localAnchorBX, distanceJointDef.localAnchorB.x) * tileWidth * unitScale, getProperty(properties, aliases.localAnchorBY, distanceJointDef.localAnchorB.y) * tileHeight * unitScale);
        jointDef = distanceJointDef;
    } else if (jointType.equals(aliases.frictionJoint)) {
        FrictionJointDef frictionJointDef = new FrictionJointDef();
        frictionJointDef.localAnchorA.set(getProperty(properties, aliases.localAnchorAX, frictionJointDef.localAnchorA.x) * tileWidth * unitScale, getProperty(properties, aliases.localAnchorAY, frictionJointDef.localAnchorA.y) * tileHeight * unitScale);
        frictionJointDef.localAnchorB.set(getProperty(properties, aliases.localAnchorBX, frictionJointDef.localAnchorB.x) * tileWidth * unitScale, getProperty(properties, aliases.localAnchorBY, frictionJointDef.localAnchorB.y) * tileHeight * unitScale);
        frictionJointDef.maxForce = getProperty(properties, aliases.maxForce, frictionJointDef.maxForce);
        frictionJointDef.maxTorque = getProperty(properties, aliases.maxTorque, frictionJointDef.maxTorque);
        jointDef = frictionJointDef;
    } else if (jointType.equals(aliases.gearJoint)) {
        GearJointDef gearJointDef = new GearJointDef();
        gearJointDef.joint1 = joints.get(properties.get(aliases.joint1, String.class));
        gearJointDef.joint2 = joints.get(properties.get(aliases.joint2, String.class));
        gearJointDef.ratio = getProperty(properties, aliases.ratio, gearJointDef.ratio);
        jointDef = gearJointDef;
    } else if (jointType.equals(aliases.mouseJoint)) {
        MouseJointDef mouseJointDef = new MouseJointDef();
        mouseJointDef.dampingRatio = getProperty(properties, aliases.dampingRatio, mouseJointDef.dampingRatio);
        mouseJointDef.frequencyHz = getProperty(properties, aliases.frequencyHz, mouseJointDef.frequencyHz);
        mouseJointDef.maxForce = getProperty(properties, aliases.maxForce, mouseJointDef.maxForce);
        mouseJointDef.target.set(getProperty(properties, aliases.targetX, mouseJointDef.target.x) * tileWidth * unitScale, getProperty(properties, aliases.targetY, mouseJointDef.target.y) * tileHeight * unitScale);
        jointDef = mouseJointDef;
    } else if (jointType.equals(aliases.prismaticJoint)) {
        PrismaticJointDef prismaticJointDef = new PrismaticJointDef();
        prismaticJointDef.enableLimit = getProperty(properties, aliases.enableLimit, prismaticJointDef.enableLimit);
        prismaticJointDef.enableMotor = getProperty(properties, aliases.enableMotor, prismaticJointDef.enableMotor);
        prismaticJointDef.localAnchorA.set(getProperty(properties, aliases.localAnchorAX, prismaticJointDef.localAnchorA.x) * tileWidth * unitScale, getProperty(properties, aliases.localAnchorAY, prismaticJointDef.localAnchorA.y) * tileHeight * unitScale);
        prismaticJointDef.localAnchorB.set(getProperty(properties, aliases.localAnchorBX, prismaticJointDef.localAnchorB.x) * tileWidth * unitScale, getProperty(properties, aliases.localAnchorBY, prismaticJointDef.localAnchorB.y) * tileHeight * unitScale);
        prismaticJointDef.localAxisA.set(getProperty(properties, aliases.localAxisAX, prismaticJointDef.localAxisA.x), getProperty(properties, aliases.localAxisAY, prismaticJointDef.localAxisA.y));
        prismaticJointDef.lowerTranslation = getProperty(properties, aliases.lowerTranslation, prismaticJointDef.lowerTranslation) * (tileWidth + tileHeight) / 2 * unitScale;
        prismaticJointDef.maxMotorForce = getProperty(properties, aliases.maxMotorForce, prismaticJointDef.maxMotorForce);
        prismaticJointDef.motorSpeed = getProperty(properties, aliases.motorSpeed, prismaticJointDef.motorSpeed);
        prismaticJointDef.referenceAngle = getProperty(properties, aliases.referenceAngle, prismaticJointDef.referenceAngle);
        prismaticJointDef.upperTranslation = getProperty(properties, aliases.upperTranslation, prismaticJointDef.upperTranslation) * (tileWidth + tileHeight) / 2 * unitScale;
        jointDef = prismaticJointDef;
    } else if (jointType.equals(aliases.pulleyJoint)) {
        PulleyJointDef pulleyJointDef = new PulleyJointDef();
        pulleyJointDef.groundAnchorA.set(getProperty(properties, aliases.groundAnchorAX, pulleyJointDef.groundAnchorA.x) * tileWidth * unitScale, getProperty(properties, aliases.groundAnchorAY, pulleyJointDef.groundAnchorA.y) * tileHeight * unitScale);
        pulleyJointDef.groundAnchorB.set(getProperty(properties, aliases.groundAnchorBX, pulleyJointDef.groundAnchorB.x) * tileWidth * unitScale, getProperty(properties, aliases.groundAnchorBY, pulleyJointDef.groundAnchorB.y) * tileHeight * unitScale);
        pulleyJointDef.lengthA = getProperty(properties, aliases.lengthA, pulleyJointDef.lengthA) * (tileWidth + tileHeight) / 2 * unitScale;
        pulleyJointDef.lengthB = getProperty(properties, aliases.lengthB, pulleyJointDef.lengthB) * (tileWidth + tileHeight) / 2 * unitScale;
        pulleyJointDef.localAnchorA.set(getProperty(properties, aliases.localAnchorAX, pulleyJointDef.localAnchorA.x) * tileWidth * unitScale, getProperty(properties, aliases.localAnchorAY, pulleyJointDef.localAnchorA.y) * tileHeight * unitScale);
        pulleyJointDef.localAnchorB.set(getProperty(properties, aliases.localAnchorBX, pulleyJointDef.localAnchorB.x) * tileWidth * unitScale, getProperty(properties, aliases.localAnchorBY, pulleyJointDef.localAnchorB.y) * tileHeight * unitScale);
        pulleyJointDef.ratio = getProperty(properties, aliases.ratio, pulleyJointDef.ratio);
        jointDef = pulleyJointDef;
    } else if (jointType.equals(aliases.revoluteJoint)) {
        RevoluteJointDef revoluteJointDef = new RevoluteJointDef();
        revoluteJointDef.enableLimit = getProperty(properties, aliases.enableLimit, revoluteJointDef.enableLimit);
        revoluteJointDef.enableMotor = getProperty(properties, aliases.enableMotor, revoluteJointDef.enableMotor);
        revoluteJointDef.localAnchorA.set(getProperty(properties, aliases.localAnchorAX, revoluteJointDef.localAnchorA.x) * tileWidth * unitScale, getProperty(properties, aliases.localAnchorAY, revoluteJointDef.localAnchorA.y) * tileHeight * unitScale);
        revoluteJointDef.localAnchorB.set(getProperty(properties, aliases.localAnchorBX, revoluteJointDef.localAnchorB.x) * tileWidth * unitScale, getProperty(properties, aliases.localAnchorBY, revoluteJointDef.localAnchorB.y) * tileHeight * unitScale);
        revoluteJointDef.lowerAngle = getProperty(properties, aliases.lowerAngle, revoluteJointDef.lowerAngle);
        revoluteJointDef.maxMotorTorque = getProperty(properties, aliases.maxMotorTorque, revoluteJointDef.maxMotorTorque);
        revoluteJointDef.motorSpeed = getProperty(properties, aliases.motorSpeed, revoluteJointDef.motorSpeed);
        revoluteJointDef.referenceAngle = getProperty(properties, aliases.referenceAngle, revoluteJointDef.referenceAngle);
        revoluteJointDef.upperAngle = getProperty(properties, aliases.upperAngle, revoluteJointDef.upperAngle);
        jointDef = revoluteJointDef;
    } else if (jointType.equals(aliases.ropeJoint)) {
        RopeJointDef ropeJointDef = new RopeJointDef();
        ropeJointDef.localAnchorA.set(getProperty(properties, aliases.localAnchorAX, ropeJointDef.localAnchorA.x) * tileWidth * unitScale, getProperty(properties, aliases.localAnchorAY, ropeJointDef.localAnchorA.y) * tileHeight * unitScale);
        ropeJointDef.localAnchorB.set(getProperty(properties, aliases.localAnchorBX, ropeJointDef.localAnchorB.x) * tileWidth * unitScale, getProperty(properties, aliases.localAnchorBY, ropeJointDef.localAnchorB.y) * tileHeight * unitScale);
        ropeJointDef.maxLength = getProperty(properties, aliases.maxLength, ropeJointDef.maxLength) * (tileWidth + tileHeight) / 2 * unitScale;
        jointDef = ropeJointDef;
    } else if (jointType.equals(aliases.weldJoint)) {
        WeldJointDef weldJointDef = new WeldJointDef();
        weldJointDef.localAnchorA.set(getProperty(properties, aliases.localAnchorAX, weldJointDef.localAnchorA.x) * tileWidth * unitScale, getProperty(properties, aliases.localAnchorAY, weldJointDef.localAnchorA.y) * tileHeight * unitScale);
        weldJointDef.localAnchorB.set(getProperty(properties, aliases.localAnchorBX, weldJointDef.localAnchorB.x) * tileWidth * unitScale, getProperty(properties, aliases.localAnchorBY, weldJointDef.localAnchorB.y) * tileHeight * unitScale);
        weldJointDef.referenceAngle = getProperty(properties, aliases.referenceAngle, weldJointDef.referenceAngle);
        jointDef = weldJointDef;
    } else if (jointType.equals(aliases.wheelJoint)) {
        WheelJointDef wheelJointDef = new WheelJointDef();
        wheelJointDef.dampingRatio = getProperty(properties, aliases.dampingRatio, wheelJointDef.dampingRatio);
        wheelJointDef.enableMotor = getProperty(properties, aliases.enableMotor, wheelJointDef.enableMotor);
        wheelJointDef.frequencyHz = getProperty(properties, aliases.frequencyHz, wheelJointDef.frequencyHz);
        wheelJointDef.localAnchorA.set(getProperty(properties, aliases.localAnchorAX, wheelJointDef.localAnchorA.x) * tileWidth * unitScale, getProperty(properties, aliases.localAnchorAY, wheelJointDef.localAnchorA.y) * tileHeight * unitScale);
        wheelJointDef.localAnchorB.set(getProperty(properties, aliases.localAnchorBX, wheelJointDef.localAnchorB.x) * tileWidth * unitScale, getProperty(properties, aliases.localAnchorBY, wheelJointDef.localAnchorB.y) * tileHeight * unitScale);
        wheelJointDef.localAxisA.set(getProperty(properties, aliases.localAxisAX, wheelJointDef.localAxisA.x), getProperty(properties, aliases.localAxisAY, wheelJointDef.localAxisA.y));
        wheelJointDef.maxMotorTorque = getProperty(properties, aliases.maxMotorTorque, wheelJointDef.maxMotorTorque);
        wheelJointDef.motorSpeed = getProperty(properties, aliases.motorSpeed, wheelJointDef.motorSpeed);
        jointDef = wheelJointDef;
    }
    jointDef.bodyA = bodies.get(properties.get(aliases.bodyA, String.class));
    jointDef.bodyB = bodies.get(properties.get(aliases.bodyB, String.class));
    jointDef.collideConnected = getProperty(properties, aliases.collideConnected, jointDef.collideConnected);
    Joint joint = jointDef.bodyA.getWorld().createJoint(jointDef);
    String name = mapObject.getName();
    if (joints.containsKey(name)) {
        int duplicate = 1;
        while (joints.containsKey(name + duplicate)) duplicate++;
        name += duplicate;
    }
    joints.put(name, joint);
    return joint;
}
Also used : MapProperties(com.badlogic.gdx.maps.MapProperties)

Example 8 with MapProperties

use of com.badlogic.gdx.maps.MapProperties in project Entitas-Java by Rubentxu.

the class Box2DMapObjectParser method createFixture.

/**
     * creates a {@link Fixture} from a {@link MapObject}
     *
     * @param mapObject the {@link MapObject} to parse
     * @return the parsed {@link Fixture}
     */
public Fixture createFixture(MapObject mapObject) {
    MapProperties properties = mapObject.getProperties();
    String type = properties.get("type", String.class);
    Body body = bodies.get(type.equals(aliases.object) ? mapObject.getName() : properties.get(aliases.body, String.class));
    if (!type.equals(aliases.fixture) && !type.equals(aliases.object))
        throw new IllegalArgumentException("type of " + mapObject + " is  \"" + type + "\" instead of \"" + aliases.fixture + "\" or \"" + aliases.object + "\"");
    FixtureDef fixtureDef = new FixtureDef();
    Shape shape = null;
    if (mapObject instanceof RectangleMapObject) {
        shape = new PolygonShape();
        Rectangle rectangle = new Rectangle(((RectangleMapObject) mapObject).getRectangle());
        rectangle.x *= unitScale;
        rectangle.y *= unitScale;
        rectangle.width *= unitScale;
        rectangle.height *= unitScale;
        ((PolygonShape) shape).setAsBox(rectangle.width / 2, rectangle.height / 2, new Vector2(rectangle.x - body.getPosition().x + rectangle.width / 2, rectangle.y - body.getPosition().y + rectangle.height / 2), body.getAngle());
    } else if (mapObject instanceof PolygonMapObject) {
        shape = new PolygonShape();
        Polygon polygon = ((PolygonMapObject) mapObject).getPolygon();
        polygon.setPosition(polygon.getX() * unitScale - body.getPosition().x, polygon.getY() * unitScale - body.getPosition().y);
        polygon.setScale(unitScale, unitScale);
        ((PolygonShape) shape).set(polygon.getTransformedVertices());
    } else if (mapObject instanceof PolylineMapObject) {
        shape = new ChainShape();
        Polyline polyline = ((PolylineMapObject) mapObject).getPolyline();
        polyline.setPosition(polyline.getX() * unitScale - body.getPosition().x, polyline.getY() * unitScale - body.getPosition().y);
        polyline.setScale(unitScale, unitScale);
        float[] vertices = polyline.getTransformedVertices();
        Vector2[] vectores = new Vector2[vertices.length / 2];
        for (int i = 0, j = 0; i < vertices.length; i += 2, j++) {
            vectores[j].x = vertices[i];
            vectores[j].y = vertices[i + 1];
        }
        ((ChainShape) shape).createChain(vectores);
    } else if (mapObject instanceof CircleMapObject) {
        shape = new CircleShape();
        Circle circle = ((CircleMapObject) mapObject).getCircle();
        circle.setPosition(circle.x * unitScale - body.getPosition().x, circle.y * unitScale - body.getPosition().y);
        circle.radius *= unitScale;
        ((CircleShape) shape).setPosition(new Vector2(circle.x, circle.y));
        ((CircleShape) shape).setRadius(circle.radius);
    } else if (mapObject instanceof EllipseMapObject) {
        Ellipse ellipse = ((EllipseMapObject) mapObject).getEllipse();
        if (ellipse.width == ellipse.height) {
            CircleMapObject circleMapObject = new CircleMapObject(ellipse.x, ellipse.y, ellipse.width / 2);
            circleMapObject.setName(mapObject.getName());
            circleMapObject.getProperties().putAll(mapObject.getProperties());
            circleMapObject.setColor(mapObject.getColor());
            circleMapObject.setVisible(mapObject.isVisible());
            circleMapObject.setOpacity(mapObject.getOpacity());
            return createFixture(circleMapObject);
        }
        IllegalArgumentException exception = new IllegalArgumentException("Cannot parse " + mapObject.getName() + " because  that are not circles are not supported");
        Gdx.app.error(getClass().getName(), exception.getMessage(), exception);
        throw exception;
    } else if (mapObject instanceof TextureMapObject) {
        IllegalArgumentException exception = new IllegalArgumentException("Cannot parse " + mapObject.getName() + " because s are not supported");
        Gdx.app.error(getClass().getName(), exception.getMessage(), exception);
        throw exception;
    } else
        assert false : mapObject + " is a not known subclass of " + MapObject.class.getName();
    fixtureDef.shape = shape;
    fixtureDef.density = getProperty(properties, aliases.density, fixtureDef.density);
    fixtureDef.filter.categoryBits = getProperty(properties, aliases.categoryBits, GRUPO.STATIC.getCategory());
    fixtureDef.filter.groupIndex = getProperty(properties, aliases.groupIndex, fixtureDef.filter.groupIndex);
    fixtureDef.filter.maskBits = getProperty(properties, aliases.maskBits, Box2DPhysicsObject.MASK_STATIC);
    fixtureDef.friction = getProperty(properties, aliases.friciton, fixtureDef.friction);
    fixtureDef.isSensor = getProperty(properties, aliases.isSensor, fixtureDef.isSensor);
    fixtureDef.restitution = getProperty(properties, aliases.restitution, fixtureDef.restitution);
    Fixture fixture = body.createFixture(fixtureDef);
    fixture.setUserData(body.getUserData());
    shape.dispose();
    String name = mapObject.getName();
    if (fixtures.containsKey(name)) {
        int duplicate = 1;
        while (fixtures.containsKey(name + duplicate)) duplicate++;
        name += duplicate;
    }
    fixtures.put(name, fixture);
    return fixture;
}
Also used : MapObject(com.badlogic.gdx.maps.MapObject) MapProperties(com.badlogic.gdx.maps.MapProperties)

Aggregations

MapProperties (com.badlogic.gdx.maps.MapProperties)8 Element (com.badlogic.gdx.utils.XmlReader.Element)4 FileHandle (com.badlogic.gdx.files.FileHandle)2 AnimatedTiledMapTile (com.badlogic.gdx.maps.tiled.tiles.AnimatedTiledMapTile)2 StaticTiledMapTile (com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile)2 Array (com.badlogic.gdx.utils.Array)2 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)2 IntArray (com.badlogic.gdx.utils.IntArray)2 IOException (java.io.IOException)2 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)1 Texture (com.badlogic.gdx.graphics.Texture)1 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)1 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)1 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)1 AtlasRegion (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion)1 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)1 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)1 MapObject (com.badlogic.gdx.maps.MapObject)1 TmxMapLoader (com.badlogic.gdx.maps.tiled.TmxMapLoader)1 OrthoCamController (com.badlogic.gdx.tests.utils.OrthoCamController)1