Exemplo n.º 1
0
  private void createBoxAtPos(Body body) {
    FixtureDef fixtureDef = new FixtureDef();
    PolygonShape shape = new PolygonShape();
    shape.setAsBox(1f, 1f);
    fixtureDef.shape = shape;
    fixtureDef.density = 10f;
    fixtureDef.restitution = 0.2f;

    Gdx.app.log(TAG, "creating body with pos: " + body.getPosition());
    body.createFixture(fixtureDef);
  }
Exemplo n.º 2
0
  private void createCircleAtPos(Body body) {

    FixtureDef fixtureDef = new FixtureDef();
    CircleShape shape = new CircleShape();
    shape.setRadius(1f);
    fixtureDef.shape = shape;
    fixtureDef.density = 5f;
    fixtureDef.restitution = 0.8f;

    Gdx.app.log(TAG, "creating body with pos: " + body.getPosition());
    body.createFixture(fixtureDef);
  }
Exemplo n.º 3
0
  @Override
  public void create() {
    cam = new OrthographicCamera(48, 32);
    cam.position.set(0, 15, 0);
    cam.update();

    Box2D.init();
    world = new World(new Vector2(0, -9.8f), true);
    dDebugRenderer = new Box2DDebugRenderer();

    spawnBoxes = false;
    // GROUND
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyDef.BodyType.StaticBody;
    bodyDef.position.set(0, 0);

    ground = world.createBody(bodyDef);
    PolygonShape shape = new PolygonShape();
    shape.setAsBox(15, 1);

    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = shape;
    fixtureDef.density = 0f;

    ground.createFixture(fixtureDef);

    // CIRCLE
    bodyDef.type = BodyDef.BodyType.DynamicBody;
    bodyDef.position.set(0, 10);

    circle = world.createBody(bodyDef);

    CircleShape circleShape = new CircleShape();
    circleShape.setRadius(1);

    fixtureDef.shape = circleShape;
    fixtureDef.density = 10;
    fixtureDef.restitution = 1;

    circle.createFixture(fixtureDef);

    // BOX
    bodyDef.type = BodyDef.BodyType.DynamicBody;
    bodyDef.position.set(0, 15);

    box = world.createBody(bodyDef);

    bodyDef.bullet = false;
    shape.setAsBox(1, 1);

    fixtureDef.friction = 100f;
    fixtureDef.restitution = 0.5f;
    fixtureDef.shape = shape;
    fixtureDef.density = 2;

    box.createFixture(fixtureDef);

    // PLATFORM
    bodyDef.type = BodyDef.BodyType.KinematicBody;
    bodyDef.position.set(-10, 6);

    platform = world.createBody(bodyDef);

    shape.setAsBox(3, .5f);

    fixtureDef.shape = shape;
    fixtureDef.density = 0;
    fixtureDef.friction = 7;
    fixtureDef.restitution = 0;

    platform.createFixture(fixtureDef);

    Gdx.input.setInputProcessor(new MyInputProcessor());

    platform.setLinearVelocity(PLATFORM_VELOCITY, 0);
  }