List of usage examples for com.badlogic.gdx.physics.box2d PolygonShape setRadius
@Override
public void setRadius(float radius)
From source file:com.agateau.pixelwheels.utils.Box2DUtils.java
License:Open Source License
public static Body createStaticBodyForMapObject(World world, MapObject object) { final float u = Constants.UNIT_FOR_PIXEL; float rotation = object.getProperties().get("rotation", 0f, Float.class); BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyDef.BodyType.StaticBody; bodyDef.angle = -rotation * MathUtils.degreesToRadians; if (object instanceof RectangleMapObject) { Rectangle rect = ((RectangleMapObject) object).getRectangle(); /*//w ww. j av a 2 s . c om A D x--------x | | x--------x B C */ float[] vertices = new float[8]; // A vertices[0] = 0; vertices[1] = 0; // B vertices[2] = 0; vertices[3] = -rect.getHeight(); // C vertices[4] = rect.getWidth(); vertices[5] = -rect.getHeight(); // D vertices[6] = rect.getWidth(); vertices[7] = 0; scaleVertices(vertices, u); bodyDef.position.set(u * rect.getX(), u * (rect.getY() + rect.getHeight())); Body body = world.createBody(bodyDef); PolygonShape shape = new PolygonShape(); shape.set(vertices); body.createFixture(shape, 1); return body; } else if (object instanceof PolygonMapObject) { Polygon polygon = ((PolygonMapObject) object).getPolygon(); float[] vertices = polygon.getVertices().clone(); scaleVertices(vertices, u); bodyDef.position.set(polygon.getX() * u, polygon.getY() * u); Body body = world.createBody(bodyDef); PolygonShape shape = new PolygonShape(); shape.set(vertices); body.createFixture(shape, 1); return body; } else if (object instanceof EllipseMapObject) { Ellipse ellipse = ((EllipseMapObject) object).getEllipse(); float radius = ellipse.width * u / 2; float x = ellipse.x * u + radius; float y = ellipse.y * u + radius; bodyDef.position.set(x, y); Body body = world.createBody(bodyDef); CircleShape shape = new CircleShape(); shape.setRadius(radius); body.createFixture(shape, 1); return body; } throw new RuntimeException("Unsupported MapObject type: " + object); }
From source file:vault.clockwork.actors.PlanetActor.java
License:Open Source License
/** * Ctor.// w w w . j a v a 2 s .c o m * @param id */ public PlanetActor(int id) { super(id); PolygonShape shape = new PolygonShape(); shape.setRadius(32.f * Physics.SCALE); BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyDef.BodyType.KinematicBody; bodyDef.position.set(1.f, 1.f); body = Game.physics.world.createBody(bodyDef); fixture = body.createFixture(shape, 2.f); fixture.setUserData(this); shape.dispose(); // create the plank sprite sprPlanet = new Sprite(Game.assets.get("assets/planet.png", Texture.class)); sprPlanet.setBounds(-42.f, -42.f, 150.f, 150.f); sprPlanet.setOriginCenter(); sprPlanet.setRotation(0.f); }