com.badlogic.gdx.physics.box2d.Body.createFixture()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(145)

本文整理了Java中com.badlogic.gdx.physics.box2d.Body.createFixture()方法的一些代码示例,展示了Body.createFixture()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Body.createFixture()方法的具体详情如下:
包路径:com.badlogic.gdx.physics.box2d.Body
类名称:Body
方法名:createFixture

Body.createFixture介绍

[英]Creates a fixture and attach it to this body. Use this function if you need to set some fixture parameters, like friction. Otherwise you can create the fixture directly from a shape. If the density is non-zero, this function automatically updates the mass of the body. Contacts are not created until the next time step.
[中]创建设备并将其附着到此实体。如果需要设置某些夹具参数(如摩擦力),请使用此功能。否则,可以直接从形状创建设备。如果“密度”为非零,此函数将自动更新实体的质量。在下一个时间步骤之前不会创建联系人。

代码示例

代码示例来源:origin: libgdx/libgdx

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();
}

代码示例来源:origin: libgdx/libgdx

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;
}

代码示例来源:origin: libgdx/libgdx

Body createCircle (BodyType type, float radius, float density) {
  BodyDef def = new BodyDef();
  def.type = type;
  Body box = world.createBody(def);
  CircleShape poly = new CircleShape();
  poly.setRadius(radius);
  box.createFixture(poly, density);
  poly.dispose();
  return box;
}

代码示例来源:origin: libgdx/libgdx

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;
}

代码示例来源:origin: libgdx/libgdx

groundBody.createFixture(groundPoly, 10);
groundPoly.dispose();
  boxBody.createFixture(boxPoly, 10);
  circleBody.createFixture(circleShape, 10);

代码示例来源:origin: libgdx/libgdx

ground.createFixture(fd);
shape.dispose();
body.createFixture(shape, 1);
body.createFixture(shape, 1);

代码示例来源:origin: libgdx/libgdx

private Body createEdge (BodyType type, float x1, float y1, float x2, float y2, float density) {
  BodyDef def = new BodyDef();
  def.type = type;
  Body box = world.createBody(def);
  EdgeShape poly = new EdgeShape();
  poly.set(new Vector2(0, 0), new Vector2(x2 - x1, y2 - y1));
  box.createFixture(poly, density);
  box.setTransform(x1, y1, 0);
  poly.dispose();
  return box;
}

代码示例来源:origin: libgdx/libgdx

@Override
protected void createWorld (World world) {
  {
    BodyDef bd = new BodyDef();
    Body ground = world.createBody(bd);
    EdgeShape shape = new EdgeShape();
    shape.set(new Vector2(-40, 0), new Vector2(40, 0));
    ground.createFixture(shape, 0);
    shape.dispose();
  }
  {
    CircleShape shape = new CircleShape();
    shape.setRadius(1.0f);
    for (int i = 0; i < e_count; i++) {
      BodyDef bd = new BodyDef();
      bd.type = BodyType.DynamicBody;
      bd.position.set(0, 4.0f + 3.0f * i);
      Body body = world.createBody(bd);
      body.createFixture(shape, 1.0f);
    }
    shape.dispose();
  }
}

代码示例来源:origin: libgdx/libgdx

groundBody.createFixture(shape, 0.0f);
fd.shape = shape;
fd.friction = 0.8f;
m_platform = body.createFixture(fd);
body.createFixture(shape, 20.0f);

代码示例来源:origin: libgdx/libgdx

ground.createFixture(shape, 0.0f);
ground.createFixture(shape, 0);
shape.dispose();
  body.createFixture(fd);

代码示例来源:origin: libgdx/libgdx

ground.createFixture(shape, 0.0f);
shape.dispose();
  body.createFixture(fd);

代码示例来源:origin: libgdx/libgdx

@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();
  }
}

代码示例来源:origin: libgdx/libgdx

ground.createFixture(shape, 0);
shape.dispose();
m_platform = body.createFixture(shape, 0);
m_bottom = 10.0f - 0.5f;
m_top = 10.0f + 0.5f;
CircleShape shape = new CircleShape();
shape.setRadius(m_radius);
m_character = body.createFixture(shape, 20.0f);
shape.dispose();

代码示例来源:origin: libgdx/libgdx

@Override
public boolean keyDown (int keyCode) {
  if (keyCode == Input.Keys.COMMA) {
    if (m_bullet != null) {
      world.destroyBody(m_bullet);
      m_bullet = null;
    }
    {
      CircleShape shape = new CircleShape();
      shape.setRadius(0.25f);
      FixtureDef fd = new FixtureDef();
      fd.shape = shape;
      fd.density = 20.0f;
      fd.restitution = 0.05f;
      BodyDef bd = new BodyDef();
      bd.type = BodyType.DynamicBody;
      bd.bullet = true;
      bd.position.set(-31, 5);
      m_bullet = world.createBody(bd);
      m_bullet.createFixture(fd);
      m_bullet.setLinearVelocity(new Vector2(400, 0));
    }
  }
  return false;
}

代码示例来源:origin: libgdx/libgdx

EdgeShape shape = new EdgeShape();
shape.set(new Vector2(-40, 0), new Vector2(40, 0));
ground.createFixture(shape, 0);
shape.dispose();
body.createFixture(shape, 5.0f);

代码示例来源:origin: libgdx/libgdx

shape.set(new Vector2(-40, 0), new Vector2(40, 0));
ground.createFixture(shape, 0.0f);
shape.dispose();
  bd.position.set(0.5f + i, y);
  Body body = world.createBody(bd);
  body.createFixture(fd);

代码示例来源:origin: libgdx/libgdx

ground.createFixture(shape, 0.0f);
shape.dispose();
    bd.position.set(y);
    Body body = world.createBody(bd);
    body.createFixture(shape, 5.0f);

代码示例来源:origin: libgdx/libgdx

ground.createFixture(fd);
shape.dispose();
m_attachment.createFixture(shape, 2.0f);
shape.dispose();
fd.density = 2.0f;
m_platform.createFixture(fd);
shape.dispose();
fd.density = 2.0f;
body.createFixture(fd);
shape.dispose();

代码示例来源:origin: libgdx/libgdx

shape.set(new Vector2(-40, 0), new Vector2(40.0f, 0));
ground.createFixture(shape, 0);
shape.dispose();
  bd.position.set(-14.5f + 1.0f * i, 5.0f);
  Body body = world.createBody(bd);
  body.createFixture(fd);
bd.position.set(-8.0f + 8.0f * i, 12.0f);
Body body = world.createBody(bd);
body.createFixture(fd);
body.createFixture(fd);

代码示例来源:origin: libgdx/libgdx

public void create () {
  cam = new OrthographicCamera(48, 32);
  cam.position.set(0, 15, 0);
  renderer = new Box2DDebugRenderer();
  world = new World(new Vector2(0, -10), true);
  Body body = world.createBody(new BodyDef());
  CircleShape shape = new CircleShape();
  shape.setRadius(1f);
  MassData mass = new MassData();
  mass.mass = 1f;
  body.setMassData(mass);
  body.setFixedRotation(true);
  body.setType(BodyType.KinematicBody);
  body.createFixture(shape, 1);
  body.setBullet(true);
  body.setTransform(new Vector2(0, 0), body.getAngle());
  body.setLinearVelocity(new Vector2(50f, 0));
}

相关文章