private void createBoxes () { // next we create 50 boxes at random locations above the ground // body. First we create a nice polygon representing a box 2 meters // wide and high. PolygonShape boxPoly = new PolygonShape(); boxPoly.setAsBox(1, 1); // next we create the 50 box bodies using the PolygonShape we just // defined. This process is similar to the one we used for the ground // body. Note that we reuse the polygon for each body fixture. for (int i = 0; i < 20; i++) { // Create the BodyDef, set a random position above the // ground and create a new body BodyDef boxBodyDef = new BodyDef(); boxBodyDef.type = BodyType.DynamicBody; boxBodyDef.position.x = -24 + (float)(Math.random() * 48); boxBodyDef.position.y = 10 + (float)(Math.random() * 100); Body boxBody = world.createBody(boxBodyDef); boxBody.createFixture(boxPoly, 1); // add the box to our list of boxes boxes.add(boxBody); } // we are done, all that's left is disposing the boxPoly boxPoly.dispose(); }
/** Returns the shape of this fixture */ public Shape getShape () { if (shape == null) { org.jbox2d.collision.shapes.Shape shape2 = fixture.getShape(); ShapeType type = shape2.getType(); if (type == ShapeType.CHAIN) shape = new ChainShape((org.jbox2d.collision.shapes.ChainShape)shape2); if (type == ShapeType.CIRCLE) shape = new CircleShape((org.jbox2d.collision.shapes.CircleShape)shape2); if (type == ShapeType.EDGE) shape = new EdgeShape((org.jbox2d.collision.shapes.EdgeShape)shape2); if (type == ShapeType.POLYGON) shape = new PolygonShape((org.jbox2d.collision.shapes.PolygonShape)shape2); } return shape; }
Body createBox (BodyType type, float width, float height, float density) { BodyDef def = new BodyDef(); def.type = type; Body box = world.createBody(def); PolygonShape poly = new PolygonShape(); poly.setAsBox(width, height); box.createFixture(poly, density); poly.dispose(); return box; }
PolygonShape groundPoly = new PolygonShape(); groundPoly.setAsBox(50, 1); PolygonShape boxPoly = new PolygonShape(); boxPoly.setAsBox(1, 1);
/** Returns the shape of this fixture */ public Shape getShape () { if (shape == null) { long shapeAddr = jniGetShape(addr); if (shapeAddr == 0) throw new GdxRuntimeException("Null shape address!"); int type = Shape.jniGetType(shapeAddr); switch (type) { case 0: shape = new CircleShape(shapeAddr); break; case 1: shape = new EdgeShape(shapeAddr); break; case 2: shape = new PolygonShape(shapeAddr); break; case 3: shape = new ChainShape(shapeAddr); break; default: throw new GdxRuntimeException("Unknown shape type!"); } } return shape; }
private Body createPlayer () { BodyDef def = new BodyDef(); def.type = BodyType.DynamicBody; Body box = world.createBody(def); PolygonShape poly = new PolygonShape(); poly.setAsBox(0.45f, 1.4f); playerPhysicsFixture = box.createFixture(poly, 1); poly.dispose(); CircleShape circle = new CircleShape(); circle.setRadius(0.45f); circle.setPosition(new Vector2(0, -1.4f)); playerSensorFixture = box.createFixture(circle, 0); circle.dispose(); box.setBullet(true); return box; }
Body body = world.createBody(bd); PolygonShape shape = new PolygonShape(); shape.setAsBox(10.0f, 0.5f); Body body = world.createBody(bd); PolygonShape shape = new PolygonShape(); shape.setAsBox(0.5f, 0.5f); body.createFixture(shape, 20.0f);
@Override protected void createWorld (World world) { { BodyDef bd = new BodyDef(); bd.position.set(0, 0); Body body = world.createBody(bd); EdgeShape shape = new EdgeShape(); shape.set(new Vector2(-10, 0), new Vector2(10, 0)); body.createFixture(shape, 0); shape.dispose(); PolygonShape poly = new PolygonShape(); poly.setAsBox(0.2f, 1.0f, new Vector2(0.5f, 1.0f), 0); body.createFixture(poly, 0); poly.dispose(); } { BodyDef bd = new BodyDef(); bd.type = BodyType.DynamicBody; bd.position.set(0, 20); PolygonShape shape = new PolygonShape(); shape.setAsBox(2, 0.1f); m_body = world.createBody(bd); m_body.createFixture(shape, 1); m_angularVelocity = 33.468121f; m_body.setLinearVelocity(new Vector2(0, -100)); m_body.setAngularVelocity(m_angularVelocity); shape.dispose(); } }
PolygonShape shape = new PolygonShape(); shape.setAsBox(1, 2f);
-0.7122401f, 0.110677004f, -0.6419276f, 0.13151026f, -0.49869835f, 0.08984375f, -0.3190109f}; PolygonShape shape = new PolygonShape(); shape.set(vertices); PolygonShape groundPoly = new PolygonShape(); groundPoly.setAsBox(50, 1);
m_attachment = world.createBody(bd); PolygonShape shape = new PolygonShape(); shape.setAsBox(0.5f, 2.0f); m_attachment.createFixture(shape, 2.0f); m_platform = world.createBody(bd); PolygonShape shape = new PolygonShape(); shape.setAsBox(0.5f, 4.0f, new Vector2(4.0f, 0), 0.5f * (float)Math.PI); Body body = world.createBody(bd); PolygonShape shape = new PolygonShape(); shape.setAsBox(0.75f, 0.75f);
PolygonShape shape = new PolygonShape(); shape.setAsBox(0.6f, 0.125f);
PolygonShape shape = new PolygonShape(); shape.setAsBox(2, 5);
PolygonShape shape = new PolygonShape(); shape.setAsBox(a, a);
PolygonShape shape = new PolygonShape(); shape.setAsBox(0.5f, 0.5f);
Body body = world.createBody(bd); PolygonShape shape = new PolygonShape(); shape.setAsBox(3, 0.5f); m_platform = body.createFixture(shape, 0);
PolygonShape shape = new PolygonShape(); shape.setAsBox(0.5f, 0.125f); FixtureDef fd = new FixtureDef(); vertices[2] = new Vector2(0, 1.5f); PolygonShape shape = new PolygonShape(); shape.set(vertices);
vertices[2] = xf1.mul(new Vector2(0, 0.5f)); PolygonShape poly1 = new PolygonShape(); poly1.set(vertices); vertices[2] = xf2.mul(new Vector2(0, 0.5f)); PolygonShape poly2 = new PolygonShape(); poly2.set(vertices); PolygonShape shape = new PolygonShape(); shape.setAsBox(0.5f, 0.5f);
Body ground = world.createBody(bd); PolygonShape shape = new PolygonShape(); shape.setAsBox(1, 1, new Vector2(4, 3), 0); ground.createFixture(shape, 0); PolygonShape shape = new PolygonShape(); shape.setAsBox(0.5f, 0.5f); PolygonShape shape = new PolygonShape(); shape.set(vertices);
vertices[1] = new Vector2(1, 0); vertices[2] = new Vector2(0, 2); PolygonShape polygon = new PolygonShape(); polygon.set(vertices); Body body = world.createBody(bd); PolygonShape p = new PolygonShape(); p.setAsBox(0.5f, 1.0f); body.createFixture(p, 1);