Java 类com.badlogic.gdx.maps.objects.PolylineMapObject 实例源码

项目:joe    文件:TiledMapLevelLoadable.java   
private void processFreeBodies(Array<MapObject> bodies) {
    for (MapObject object : bodies) {
        FixtureBodyDefinition fixtureBodyDefinition;
        if (object instanceof RectangleMapObject) {
            fixtureBodyDefinition = TiledUtils.createRectangleFixtureBodyDef((RectangleMapObject)object);
        } else if (object instanceof CircleMapObject) {
            fixtureBodyDefinition = TiledUtils.createCircleFixtureBodyDef((CircleMapObject)object);
        } else if (object instanceof EllipseMapObject) {
            fixtureBodyDefinition = TiledUtils.createEllipseFixtureBodyDef((EllipseMapObject)object);
        } else if (object instanceof PolylineMapObject || object instanceof PolygonMapObject) {
            fixtureBodyDefinition = TiledUtils.createPolyFixtureBodyDef(object);
        } else {
            throw new InvalidConfigException(filename, "Unknown MapObject type");
        }

        freeBodyDefinitions.add(fixtureBodyDefinition);
    }
}
项目:joe    文件:TiledUtils.java   
public static FixtureDef getFixtureDefFromBodySkeleton(MapObject object) {
    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.density = 1;
    fixtureDef.friction = 0;
    fixtureDef.restitution = 0;

    Shape shape = null;
    if (object instanceof TextureMapObject) {
        shape = getTextureMapShape(object);
    } else if (object instanceof RectangleMapObject) {
        shape = getRectangleShape(object);
    } else if (object instanceof CircleMapObject) {
        shape = getCircleShape(object);
    } else if (object instanceof EllipseMapObject) {
        shape = getEllipseShape(object);
    } else if (object instanceof PolygonMapObject) {
        shape = getPolygonShape(object);
    } else if (object instanceof PolylineMapObject) {
        shape = getPolylineShape(object);
    }

    fixtureDef.shape = shape;

    return fixtureDef;
}
项目:DropTheCube-LD32    文件:Box2DUtils.java   
private static Shape getPolyline(PolylineMapObject object) {
    float[] vertices = object.getPolyline().getTransformedVertices();
    Vector2[] worldVertices = new Vector2[vertices.length / 2];

    for(int i = 0; i < vertices.length / 2; ++i){
        Vector2 vector = new Vector2();
        vector.x = vertices[i * 2];
        vector.y = vertices[i * 2 + 1];

        worldVertices[i] = Pixels.toMeters(new Vector2(vector));
    }

    ChainShape shape = new ChainShape();
    shape.createChain(worldVertices);
    return shape;
}
项目:joe    文件:TiledUtils.java   
private static Shape getPolylineShape(MapObject object) {
    Polyline polyline = ((PolylineMapObject)object).getPolyline();
    float[] vertices = polyline.getTransformedVertices();
    for (int i = 0; i < vertices.length; i++) {
        vertices[i] *= MainCamera.getInstance().getTileMapScale();
    }

    ChainShape shape = new ChainShape();
    shape.createChain(vertices);

    return shape;
}
项目:SupaBax    文件:BodyBuilder.java   
/**
 * 
 * @param world
 * @param map
 */
public void createBodies(ArrayList<Entity> entities, World world, TiledMap map){
    MapObjects objects;

    objects = map.getLayers().get("ground").getObjects();
    for(MapObject object : objects){
        if(object instanceof RectangleMapObject){
            createRectangle(world, (RectangleMapObject) object, 0.5f, 0.4f, 0.6f);
        } else if(object instanceof PolygonMapObject){
            createPolygon(world, (PolygonMapObject) object, 0.5f, 0.4f, 0.6f);
        } else if(object instanceof PolylineMapObject){
            createPolyline(world, (PolylineMapObject) object, 0.5f, 0.4f, 0.6f);
        } else if(object instanceof EllipseMapObject){
            createEllipse(world, (EllipseMapObject) object, 0.5f, 0.4f, 0.6f);
        } else{
            Gdx.app.error("Error", "Invalid map object");
        }
    }

    /*
    objects = map.getLayers().get("dynamic").getObjects();
    for(MapObject object : objects){
        RectangleMapObject entity = (RectangleMapObject) object;
        Rectangle position = entity.getRectangle();
        entities.add(new Box(world, new Vector2(position.x / SupaBox.PPM, position.y / SupaBox.PPM), new Vector2(0f, 0f), 1f, 1f));
    }
    */
}
项目:SupaBax    文件:BodyBuilder.java   
/**
 * 
 * @param world
 * @param polylineObject
 * @param density
 * @param friction
 * @param restitution
 */
private void createPolyline(World world, PolylineMapObject polylineObject, float density, float friction, float restitution){
    Polyline polyline = polylineObject.getPolyline();
    ChainShape shape = new ChainShape();
    float[] vertices = polyline.getTransformedVertices();
    float[] worldVertices = new float[vertices.length];

    for(int i = 0; i < vertices.length; i++){
        worldVertices[i] = vertices[i] / SupaBox.PPM;
    }

    shape.createChain(worldVertices);

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

    Body body = world.createBody(bodyDef);

    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = shape;
    fixtureDef.density = density;
    fixtureDef.friction = friction;
    fixtureDef.restitution = restitution;

    body.createFixture(fixtureDef);

    shape.dispose();
}
项目:practicos    文件:GeneradorNivel.java   
private Shape getPolyline(PolylineMapObject polylineObject) {
    float[] vertices = polylineObject.getPolyline().getTransformedVertices();
    Vector2[] worldVertices = new Vector2[vertices.length / 2];

    for (int i = 0; i < vertices.length / 2; ++i) {
        worldVertices[i] = new Vector2();
        worldVertices[i].x = vertices[i * 2] / GameWorld.units;
        worldVertices[i].y = vertices[i * 2 + 1] / GameWorld.units;
    }

    ChainShape chain = new ChainShape(); 
    chain.createChain(worldVertices);
    return chain;
}
项目:sioncore    文件:MapBodyManager.java   
private Shape getPolyline(PolylineMapObject polylineObject) {
    float[] vertices = polylineObject.getPolyline().getTransformedVertices();
    Vector2[] worldVertices = new Vector2[vertices.length / 2];

    for (int i = 0; i < vertices.length / 2; ++i) {
        worldVertices[i] = new Vector2();
        worldVertices[i].x = vertices[i * 2] / units;
        worldVertices[i].y = vertices[i * 2 + 1] / units;
    }

    ChainShape chain = new ChainShape(); 
    chain.createChain(worldVertices);
    return chain;
}
项目:JavaLib    文件:MapBodyManager.java   
private Shape getPolyline(PolylineMapObject polylineObject) {
    float[] vertices = polylineObject.getPolyline().getVertices(); // Changed
    Vector2[] worldVertices = new Vector2[vertices.length / 2];

    for (int i = 0; i < vertices.length / 2; ++i) {
        worldVertices[i] = new Vector2();
        worldVertices[i].x = vertices[i * 2] * m_units;
        worldVertices[i].y = vertices[i * 2 + 1] * m_units;
    }

    ChainShape chain = new ChainShape();
    chain.createChain(worldVertices);
    return chain;
}
项目:school-game    文件:WaypointNPC.java   
/**
 * Initialisiert den NPC.
 * Erstellt eine Liste aller Wegpunkte.
 */
@Override
public void onInit()
{
    super.onInit();

    float[] vertices;

    if (rawObject instanceof PolylineMapObject)
    {
        PolylineMapObject polyline = (PolylineMapObject) rawObject;
        loop = false;

        vertices = polyline.getPolyline().getTransformedVertices();
    }
    else if (rawObject instanceof PolygonMapObject)
    {
        PolygonMapObject polygon = (PolygonMapObject) rawObject;
        loop = true;

        vertices = polygon.getPolygon().getTransformedVertices();
    }
    else
    {
        Gdx.app.log("WARNING", objectId + ": MapObject must be Polyline or Polygon.");

        worldObjectManager.removeObject(this);

        return;
    }

    waypoints = new Vector2[vertices.length / 2];

    for (int i = 0; i < vertices.length / 2; i++)
    {
        waypoints[i] = new Vector2();
        waypoints[i].x = vertices[i * 2];
        waypoints[i].y = vertices[i * 2 + 1];
    }

    if (waypoints.length < 2)
    {
        Gdx.app.log("WARNING", objectId + ": Must have at least 2 Waypoints.");

        worldObjectManager.removeObject(this);

        return;
    }

    body = createCircleBody(waypoints[0].cpy(), 10);
    targetIndex = 1;
}
项目:practicos    文件:GeneradorNivel.java   
private void crearColisiones() {

Array<Body> slopes = new Array<Body>();
FixtureDef fixDef = new FixtureDef();


MapObjects objects = cls.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 EllipseMapObject) {
    shape = getEllipse((EllipseMapObject)object);
}
else if (object instanceof CircleMapObject) {
    shape = getCircle((CircleMapObject)object);
}
else {
    continue;
}


fixDef.shape = shape;
fixDef.filter.categoryBits = GameWorld.BIT_PARED;
  fixDef.filter.maskBits = GameWorld.BIT_JUGADOR | GameWorld.BIT_ENEMIGOS | GameWorld.BIT_SENSOR;


Body suelo = GameWorld.mundo.createBody(bodyDef);
suelo.createFixture(fixDef).setUserData("cls");

slopes.add(suelo);

shape.dispose();
  }
}
项目:sioncore    文件:MapBodyManager.java   
/**
 * @param map map to be used to create the static bodies. 
 * @param layerName name of the layer that contains the shapes.
 */
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();
    }
}