本文整理汇总了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;
}
示例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);
}
}
示例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;
}
示例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!");
}
示例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;
}
示例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!");
}
示例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;
}
示例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));
}
*/
}
示例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();
}
示例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;
}
示例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;
}
示例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);
}
}
}
示例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);
}
示例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;
}
示例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;
}