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

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

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

Body.getType介绍

[英]Get the type of this body.
[中]获取此实体的类型。

代码示例

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

private Color getColorByBody (Body body) {
  if (body.isActive() == false)
    return SHAPE_NOT_ACTIVE;
  else if (body.getType() == BodyType.StaticBody)
    return SHAPE_STATIC;
  else if (body.getType() == BodyType.KinematicBody)
    return SHAPE_KINEMATIC;
  else if (body.isAwake() == false)
    return SHAPE_NOT_AWAKE;
  else
    return SHAPE_AWAKE;
}

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

@Override
public void beginContact (Contact contact) {
  System.out.println(String.format("beginContact() addr=%d", getContactAddr(contact)));
  System.out.println(String.format("beginContact() addrA=%d, addrB=%d", 
    getFixtureAddrA(contact), 
    getFixtureAddrB(contact)));
  System.out.println(String.format("beginContact() fixA=%s, fixB=%s", 
    contact.getFixtureA(), 
    contact.getFixtureB()));
  
  final Body toRemove = contact.getFixtureA().getBody().getType() == BodyType.DynamicBody ?
    contact.getFixtureA().getBody() :
    contact.getFixtureB().getBody();
    Gdx.app.postRunnable(new Runnable() {
      @Override
      public void run () {
        world.destroyBody(toRemove);
      }
    });
}

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

@Override
  public void render () {
    if (m_platform.getType() == BodyType.KinematicBody) {
      Vector2 p = m_platform.getTransform().getPosition();
      Vector2 v = m_platform.getLinearVelocity();

      if ((p.x < -10 && v.x < 0) || (p.x > 10 && v.x > 0)) {
        v.x = -v.x;
        m_platform.setLinearVelocity(v);
      }
    }

    super.render();

    // if (renderer.batch != null) {
    // renderer.batch.begin();
    // // renderer.batch.drawText(renderer.font, "Keys: (d) dynamic, (s) static, (k) kinematic", 0, Gdx.app.getGraphics()
    // // .getHeight(), Color.WHITE);
    // renderer.batch.end();
    // }
  }
}

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

protected void renderBody (Body body) {
  Transform transform = body.getTransform();
  int len = body.getFixtureList().size;
  Array<Fixture> fixtures = body.getFixtureList();
  for (int i = 0; i < len; i++) {
    Fixture fixture = fixtures.get(i);
    if (drawBodies) {
      if (body.isActive() == false && drawInactiveBodies)
        drawShape(fixture, transform, SHAPE_NOT_ACTIVE);
      else if (body.getType() == BodyType.StaticBody)
        drawShape(fixture, transform, SHAPE_STATIC);
      else if (body.getType() == BodyType.KinematicBody)
        drawShape(fixture, transform, SHAPE_KINEMATIC);
      else if (body.isAwake() == false)
        drawShape(fixture, transform, SHAPE_NOT_AWAKE);
      else
        drawShape(fixture, transform, SHAPE_AWAKE);
    }
    if (drawAABBs) {
      drawAABB(fixture, transform);
    }
  }
}

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

@Override
public boolean touchDown (int x, int y, int pointer, int button) {
  // translate the mouse coordinates to world coordinates
  camera.unproject(testPoint.set(x, y, 0));
  // ask the world which bodies are within the given
  // bounding box around the mouse pointer
  hitBody = null;
  world.QueryAABB(callback, testPoint.x - 0.0001f, testPoint.y - 0.0001f, testPoint.x + 0.0001f, testPoint.y + 0.0001f);
  if (hitBody == groundBody) hitBody = null;
  // ignore kinematic bodies, they don't work with the mouse joint
  if (hitBody != null && hitBody.getType() == BodyType.KinematicBody) return false;
  // if we hit something we create a new mouse joint
  // and attach it to the hit body.
  if (hitBody != null) {
    MouseJointDef def = new MouseJointDef();
    def.bodyA = groundBody;
    def.bodyB = hitBody;
    def.collideConnected = true;
    def.target.set(testPoint.x, testPoint.y);
    def.maxForce = 1000.0f * hitBody.getMass();
    mouseJoint = (MouseJoint)world.createJoint(def);
    hitBody.setAwake(true);
  }
  return false;
}

代码示例来源:origin: com.badlogicgames.gdx/gdx-box2d

private Color getColorByBody (Body body) {
  if (body.isActive() == false)
    return SHAPE_NOT_ACTIVE;
  else if (body.getType() == BodyType.StaticBody)
    return SHAPE_STATIC;
  else if (body.getType() == BodyType.KinematicBody)
    return SHAPE_KINEMATIC;
  else if (body.isAwake() == false)
    return SHAPE_NOT_AWAKE;
  else
    return SHAPE_AWAKE;
}

代码示例来源:origin: dsaltares/libgdx-cookbook

@Override
public boolean reportFixture(Fixture fixture) {
  // TODO Auto-generated method stub
  if(fixture.getBody().getType() != BodyType.StaticBody) {
    bodiesWithinArea.add(fixture.getBody());
  }
  return true;
}

相关文章