当前位置: 首页>>代码示例>>Java>>正文


Java PolygonMapObject类代码示例

本文整理汇总了Java中com.badlogic.gdx.maps.objects.PolygonMapObject的典型用法代码示例。如果您正苦于以下问题:Java PolygonMapObject类的具体用法?Java PolygonMapObject怎么用?Java PolygonMapObject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PolygonMapObject类属于com.badlogic.gdx.maps.objects包,在下文中一共展示了PolygonMapObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: makePolygonGround

import com.badlogic.gdx.maps.objects.PolygonMapObject; //导入依赖的package包/类
/**
 * Creates polygon ground from the given object, at the given world.
 *
 * @param world  The world were the ground will be.
 * @param object The object used to initialize the ground.
 * @return The body of the created ground.
 */
static Body makePolygonGround(World world, PolygonMapObject object) {
    Polygon polygon = object.getPolygon();

    // Body and Fixture variables
    BodyDef bdef = new BodyDef();
    FixtureDef fdef = new FixtureDef();
    PolygonShape shape = new PolygonShape();

    bdef.type = BodyDef.BodyType.StaticBody;
    bdef.position.set(PIXEL_TO_METER * polygon.getX(), PIXEL_TO_METER * polygon.getY());

    Body body = world.createBody(bdef);

    float[] new_vertices = polygon.getVertices().clone();
    for (int i = 0; i < new_vertices.length; i++)
        new_vertices[i] *= PIXEL_TO_METER;

    shape.set(new_vertices);
    fdef.shape = shape;
    fdef.filter.categoryBits = GROUND_BIT;
    body.createFixture(fdef);

    return body;
}
 
开发者ID:AndreFCruz,项目名称:feup-lpoo-armadillo,代码行数:32,代码来源:B2DFactory.java

示例2: processFreeBodies

import com.badlogic.gdx.maps.objects.PolygonMapObject; //导入依赖的package包/类
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);
    }
}
 
开发者ID:alexschimpf,项目名称:joe,代码行数:19,代码来源:TiledMapLevelLoadable.java

示例3: getFixtureDefFromBodySkeleton

import com.badlogic.gdx.maps.objects.PolygonMapObject; //导入依赖的package包/类
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;
}
 
开发者ID:alexschimpf,项目名称:joe,代码行数:26,代码来源:TiledUtils.java

示例4: getPositionFromMapObject

import com.badlogic.gdx.maps.objects.PolygonMapObject; //导入依赖的package包/类
private Vector2 getPositionFromMapObject(MapObject mapObject) {
	if (mapObject instanceof PolygonMapObject) {
		Polygon polygon = ((PolygonMapObject) mapObject).getPolygon();
		return new Vector2(polygon.getX(), polygon.getY());
	} else if (mapObject instanceof RectangleMapObject) {
		Rectangle rectangle = ((RectangleMapObject) mapObject).getRectangle();
		return new Vector2(rectangle.getX(), rectangle.getY());
	} else if (mapObject instanceof EllipseMapObject) {
		Ellipse ellipse = ((EllipseMapObject) mapObject).getEllipse();
		return new Vector2(ellipse.x, ellipse.y);
	} else if (mapObject instanceof CircleMapObject) {
		Circle circle = ((CircleMapObject) mapObject).getCircle();
		return new Vector2(circle.x, circle.y);
	}
	throw new GdxRuntimeException("Only Polygons, Rectangles, Ellipses and Circles are supported!");
}
 
开发者ID:mganzarcik,项目名称:fabulae,代码行数:17,代码来源:GameMapLoader.java

示例5: getPolygonShape

import com.badlogic.gdx.maps.objects.PolygonMapObject; //导入依赖的package包/类
private static Shape getPolygonShape(MapObject object) {
    Polygon polygon = ((PolygonMapObject)object).getPolygon();
    float[] vertices = polygon.getTransformedVertices();
    for (int i = 0; i < vertices.length; i++) {
        vertices[i] *= MainCamera.getInstance().getTileMapScale();
    }

    PolygonShape shape = new PolygonShape();
    shape.set(vertices);

    return shape;
}
 
开发者ID:alexschimpf,项目名称:joe,代码行数:13,代码来源:TiledUtils.java

示例6: getPolygonFromMapObject

import com.badlogic.gdx.maps.objects.PolygonMapObject; //导入依赖的package包/类
private Polygon getPolygonFromMapObject(MapObject mapObject) {
	if (mapObject instanceof PolygonMapObject) {
		return ((PolygonMapObject) mapObject).getPolygon();
	} else if (mapObject instanceof RectangleMapObject) {
		return MathUtil.polygonFromRectangle(((RectangleMapObject) mapObject).getRectangle());
	}
	throw new GdxRuntimeException("Only Polygons and Rectangles are supported!");
}
 
开发者ID:mganzarcik,项目名称:fabulae,代码行数:9,代码来源:GameMapLoader.java

示例7: getPolygon

import com.badlogic.gdx.maps.objects.PolygonMapObject; //导入依赖的package包/类
private static PolygonShape getPolygon(PolygonMapObject object) {
	PolygonShape shape = new PolygonShape();
	float[] vertices = object.getPolygon().getTransformedVertices();
	
	float[] worldVertices = new float[vertices.length];
	
	for(int i = 0; i < vertices.length; ++i){
		worldVertices[i] = Pixels.toMeters(vertices[i]);
	}
	
	shape.set(worldVertices);
	
	return shape;
}
 
开发者ID:Portals,项目名称:DropTheCube-LD32,代码行数:15,代码来源:Box2DUtils.java

示例8: createBodies

import com.badlogic.gdx.maps.objects.PolygonMapObject; //导入依赖的package包/类
/**
 * 
 * @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));
	}
	*/
}
 
开发者ID:ryanshappell,项目名称:SupaBax,代码行数:33,代码来源:BodyBuilder.java

示例9: createPolygon

import com.badlogic.gdx.maps.objects.PolygonMapObject; //导入依赖的package包/类
/**
 * 
 * @param world
 * @param polygonObject
 * @param density
 * @param friction
 * @param restitution
 */
private void createPolygon(World world, PolygonMapObject polygonObject, float density, float friction, float restitution){
	Polygon polygon = polygonObject.getPolygon();
	PolygonShape shape = new PolygonShape();
	float[] vertices = polygon.getTransformedVertices();
	float[] worldVertices = new float[vertices.length];
	
	for(int i = 0; i < vertices.length; i++){
		worldVertices[i] = vertices[i] / SupaBox.PPM;
	}
	
	shape.set(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();
}
 
开发者ID:ryanshappell,项目名称:SupaBax,代码行数:36,代码来源:BodyBuilder.java

示例10: getPolygon

import com.badlogic.gdx.maps.objects.PolygonMapObject; //导入依赖的package包/类
private Shape getPolygon(PolygonMapObject polygonObject) {
	PolygonShape polygon = new PolygonShape();
	float[] vertices = polygonObject.getPolygon().getTransformedVertices();
	
	float[] worldVertices = new float[vertices.length];
	
	for (int i = 0; i < vertices.length; ++i) {
	    worldVertices[i] = vertices[i] / GameWorld.units;
	}
	
	polygon.set(worldVertices);
	return polygon;
}
 
开发者ID:programacion2VideojuegosUM2015,项目名称:practicos,代码行数:14,代码来源:GeneradorNivel.java

示例11: getPolygon

import com.badlogic.gdx.maps.objects.PolygonMapObject; //导入依赖的package包/类
private Shape getPolygon(PolygonMapObject polygonObject) {
	PolygonShape polygon = new PolygonShape();
	float[] vertices = polygonObject.getPolygon().getTransformedVertices();
	
	float[] worldVertices = new float[vertices.length];
	
	for (int i = 0; i < vertices.length; ++i) {
	    worldVertices[i] = vertices[i] / units;
	}
	
	polygon.set(worldVertices);
	return polygon;
}
 
开发者ID:saltares,项目名称:sioncore,代码行数:14,代码来源:MapBodyManager.java

示例12: createGroundObjects

import com.badlogic.gdx.maps.objects.PolygonMapObject; //导入依赖的package包/类
public static void createGroundObjects(Map map, MapLayer layer, Box2DWorld world) {

        Matrix4 transformMat4 = getTransformationMatrix(map);

        for(MapObject object : layer.getObjects()) {
            if(object instanceof PolygonMapObject) {
                polygonGround(object, map, world, transformMat4);
            }
        }
    }
 
开发者ID:lukz,项目名称:Simple-Isometric-Game,代码行数:11,代码来源:MapProcessor.java

示例13: polygonGround

import com.badlogic.gdx.maps.objects.PolygonMapObject; //导入依赖的package包/类
private static void polygonGround(MapObject object, Map map, Box2DWorld world, Matrix4 transformMat4) {
    PolygonMapObject polyObject = (PolygonMapObject)object;
    Polygon polygon = new Polygon(polyObject.getPolygon().getTransformedVertices());
    polygon.setScale(world.WORLD_TO_BOX, world.WORLD_TO_BOX);

    Vector3 tempVec3 = new Vector3();

    // Transform each vertex by transformation matrix
    for(int ix = 0, iy = 1; iy < polygon.getVertices().length; ix += 2, iy += 2) {
        tempVec3.set(polygon.getVertices()[ix], polygon.getVertices()[iy], 0);
        tempVec3.mul(transformMat4);
        polygon.getVertices()[ix] = tempVec3.x;// - body.getPosition().x;
        polygon.getVertices()[iy] = tempVec3.y;// - body.getPosition().y;
    }

    Polygon[] convexPolygons = GeometryUtils.decompose(polygon);

    BodyDef bd = new BodyDef();
    bd.type = BodyDef.BodyType.StaticBody;
    bd.fixedRotation = true;
    Body body = world.getWorld().createBody(bd);

    for(Polygon convexPolygon : convexPolygons) {
        FixtureDef fixtureDef = new FixtureDef();
        fixtureDef.density = 1f;
        fixtureDef.friction = 0.0f;
        fixtureDef.restitution = 0.0f;

        PolygonShape shape = new PolygonShape();

        shape.set(convexPolygon.getTransformedVertices());
        fixtureDef.shape = shape;

        body.createFixture(fixtureDef);
    }

    body.setUserData(map);
}
 
开发者ID:lukz,项目名称:Simple-Isometric-Game,代码行数:39,代码来源:MapProcessor.java

示例14: createFixtures

import com.badlogic.gdx.maps.objects.PolygonMapObject; //导入依赖的package包/类
/**
 * creates {@link Fixture Fixtures} from a {@link MapObject}
 *
 * @param mapObject the {@link MapObject} to parse
 * @return an array of parsed {@link Fixture Fixtures}
 */
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;
}
 
开发者ID:Rubentxu,项目名称:DreamsLibGdx,代码行数:44,代码来源:Box2DMapObjectParser.java

示例15: getPolygon

import com.badlogic.gdx.maps.objects.PolygonMapObject; //导入依赖的package包/类
private Shape getPolygon(PolygonMapObject polygonObject) {
	PolygonShape polygon = new PolygonShape();
	float[] vertices = polygonObject.getPolygon().getVertices();
	float[] worldVertices = new float[vertices.length];

	for (int i = 0; i < vertices.length; ++i) {
		worldVertices[i] = vertices[i] * m_units;
	}

	polygon.set(worldVertices);
	return polygon;
}
 
开发者ID:LostCodeStudios,项目名称:JavaLib,代码行数:13,代码来源:MapBodyManager.java


注:本文中的com.badlogic.gdx.maps.objects.PolygonMapObject类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。