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(); }
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; }
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; }
@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(); } }
body.createFixture(shape, 1); shape.dispose();
shape.dispose();
shape.dispose();
fixtureDef.filter.groupIndex = 0; groundBody.createFixture(fixtureDef); groundPoly.dispose();
public void dispose () { bodyMap.clear(); shape.dispose(); }
@Override public void dispose() { debugRenderer.dispose(); batch.dispose(); square.dispose(); circle.dispose(); world.dispose(); }
public static Body createGround(World world) { BodyDef bodyDef = new BodyDef(); bodyDef.position.set(new Vector2(Constants.GROUND_X, Constants.GROUND_Y)); Body body = world.createBody(bodyDef); PolygonShape shape = new PolygonShape(); shape.setAsBox(Constants.GROUND_WIDTH / 2, Constants.GROUND_HEIGHT / 2); body.createFixture(shape, Constants.GROUND_DENSITY); body.setUserData(new GroundUserData(Constants.GROUND_WIDTH, Constants.GROUND_HEIGHT)); shape.dispose(); return body; }
public static Body createRunner(World world) { BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyDef.BodyType.DynamicBody; bodyDef.position.set(new Vector2(Constants.RUNNER_X, Constants.RUNNER_Y)); PolygonShape shape = new PolygonShape(); shape.setAsBox(Constants.RUNNER_WIDTH / 2, Constants.RUNNER_HEIGHT / 2); Body body = world.createBody(bodyDef); body.setGravityScale(Constants.RUNNER_GRAVITY_SCALE); body.createFixture(shape, Constants.RUNNER_DENSITY); body.resetMassData(); body.setUserData(new RunnerUserData(Constants.RUNNER_WIDTH, Constants.RUNNER_HEIGHT)); shape.dispose(); return body; }