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

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

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

Body.getFixtureList介绍

[英]Get the list of all fixtures attached to this body. Do not modify the list!
[中]获取连接到此实体的所有装置的列表。不要修改列表!

代码示例

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

public CirclePlatform (int x, int y, float radius, float da) {
  platform = createCircle(BodyType.KinematicBody, radius, 1);
  platform.setTransform(x, y, 0);
  platform.getFixtureList().get(0).setUserData("p");
  platform.setAngularVelocity(da);
  platform.setUserData(this);
}

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

public MovingPlatform (float x, float y, float width, float height, float dx, float dy, float da, float maxDist) {
  platform = createBox(BodyType.KinematicBody, width, height, 1);
  pos.x = x;
  pos.y = y;
  dir.x = dx;
  dir.y = dy;
  this.maxDist = maxDist;
  platform.setTransform(pos, 0);
  platform.getFixtureList().get(0).setUserData("p");
  platform.setAngularVelocity(da);
  platform.setUserData(this);
}

代码示例来源: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

protected void renderBody (Body body) {
  Transform transform = body.getTransform();
  for (Fixture fixture : body.getFixtureList()) {
    if (drawBodies) {
      drawShape(fixture, transform, getColorByBody(body));
      if (drawVelocities) {
        Vector2 position = body.getPosition();
        drawSegment(position, body.getLinearVelocity().add(position), VELOCITY_COLOR);
      }
    }
    if (drawAABBs) {
      drawAABB(fixture, transform);
    }
  }
}

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

/** Destroy a rigid body given a definition. No reference to the definition is retained. This function is locked during
 * callbacks.
 * @warning This automatically deletes all associated shapes and joints.
 * @warning This function is locked during callbacks. */
public void destroyBody (Body body) {
  Array<JointEdge> jointList = body.getJointList();
  while (jointList.size > 0)
    destroyJoint(body.getJointList().get(0).joint);
  jniDestroyBody(addr, body.addr);
  body.setUserData(null);
  this.bodies.remove(body.addr);
  Array<Fixture> fixtureList = body.getFixtureList();
  while(fixtureList.size > 0) {
    Fixture fixtureToDelete = fixtureList.removeIndex(0);
     this.fixtures.remove(fixtureToDelete.addr).setUserData(null);
     freeFixtures.free(fixtureToDelete);
   }
  
  freeBodies.free(body);
}

代码示例来源:origin: dozingcat/Vector-Pinball

public static Ball create(World world, float x, float y, float radius,
    Color primaryColor, Color secondaryColor) {
  Body ballBody = Box2DFactory.createCircle(world, x, y, radius, false);
  ballBody.setBullet(true);
  // Default is radius of 0.5, if different we want the mass to be the same (could be
  // configurable if needed), so adjust density proportional to square of the radius.
  if (radius != 0.5f) {
    ballBody.getFixtureList().get(0).setDensity((0.5f*0.5f) / (radius*radius));
    ballBody.resetMassData();
  }
  return new Ball(ballBody, primaryColor, secondaryColor);
}

代码示例来源:origin: dozingcat/Vector-Pinball

public void draw(IFieldRenderer renderer) {
  CircleShape shape = (CircleShape)body.getFixtureList().get(0).getShape();
  Vector2 center = body.getPosition();
  float radius = shape.getRadius();
  renderer.fillCircle(center.x, center.y, radius, primaryColor);
  // Draw a smaller circle to show the ball's rotation.
  float angle = body.getAngle();
  float smallCenterX = center.x + (radius / 2) * MathUtils.cos(angle);
  float smallCenterY = center.y + (radius / 2) * MathUtils.sin(angle);
  renderer.fillCircle(smallCenterX, smallCenterY, radius / 4, secondaryColor);
}

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

protected void renderBody (Body body) {
  Transform transform = body.getTransform();
  for (Fixture fixture : body.getFixtureList()) {
    if (drawBodies) {
      drawShape(fixture, transform, getColorByBody(body));
      if (drawVelocities) {
        Vector2 position = body.getPosition();
        drawSegment(position, body.getLinearVelocity().add(position), VELOCITY_COLOR);
      }
    }
    if (drawAABBs) {
      drawAABB(fixture, transform);
    }
  }
}

代码示例来源:origin: dozingcat/Vector-Pinball

@Override public void createBodies(World world) {
  this.anchorBody = Box2DFactory.createCircle(world, this.cx, this.cy, 0.05f, true);
  // Joint angle is 0 when flipper is horizontal.
  // The flipper needs to be slightly extended past anchorBody to rotate correctly.
  float ext = (this.flipperLength > 0) ? -0.05f : +0.05f;
  // Width larger than 0.12 slows rotation?
  this.flipperBody = Box2DFactory.createWall(world, cx+ext, cy-0.12f, cx+flipperLength, cy+0.12f, 0f);
  flipperBody.setType(BodyDef.BodyType.DynamicBody);
  flipperBody.setBullet(true);
  flipperBody.getFixtureList().get(0).setDensity(5.0f);
  jointDef = new RevoluteJointDef();
  jointDef.initialize(anchorBody, flipperBody, new Vector2(this.cx, this.cy));
  jointDef.enableLimit = true;
  jointDef.enableMotor = true;
  // counterclockwise rotations are positive, so flip angles for flippers extending left
  jointDef.lowerAngle = (this.flipperLength>0) ? this.minangle : -this.maxangle;
  jointDef.upperAngle = (this.flipperLength>0) ? this.maxangle : -this.minangle;
  jointDef.maxMotorTorque = 1000f;
  this.joint = (RevoluteJoint)world.createJoint(jointDef);
  flipperBodySet = Collections.singletonList(flipperBody);
  this.setEffectiveMotorSpeed(-this.downspeed); // Force flipper to bottom when field is first created.
}

代码示例来源:origin: BrentAureli/SuperMario

public void die() {
  if (!isDead()) {
    MarioBros.manager.get("audio/music/mario_music.ogg", Music.class).stop();
    MarioBros.manager.get("audio/sounds/mariodie.wav", Sound.class).play();
    marioIsDead = true;
    Filter filter = new Filter();
    filter.maskBits = MarioBros.NOTHING_BIT;
    for (Fixture fixture : b2body.getFixtureList()) {
      fixture.setFilterData(filter);
    }
    b2body.applyLinearImpulse(new Vector2(0, 4f), b2body.getWorldCenter(), true);
  }
}

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

/** Destroy a rigid body given a definition. No reference to the definition is retained. This function is locked during
 * callbacks.
 * @warning This automatically deletes all associated shapes and joints.
 * @warning This function is locked during callbacks. */
public void destroyBody (Body body) {
  Array<JointEdge> jointList = body.getJointList();
  while (jointList.size > 0)
    destroyJoint(body.getJointList().get(0).joint);
  jniDestroyBody(addr, body.addr);
  body.setUserData(null);
  this.bodies.remove(body.addr);
  Array<Fixture> fixtureList = body.getFixtureList();
  while(fixtureList.size > 0) {
    Fixture fixtureToDelete = fixtureList.removeIndex(0);
     this.fixtures.remove(fixtureToDelete.addr).setUserData(null);
     freeFixtures.free(fixtureToDelete);
   }
  
  freeBodies.free(body);
}

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

for(Fixture f : b.getFixtureList()) {
  b.destroyFixture(f);

代码示例来源:origin: manuelbua/uracer-kotd

Array<Fixture> fs = body.getFixtureList();
for (Fixture f : fs) {
  f.setUserData(carType);

代码示例来源:origin: yichen0831/Bomberman_libGdx

Filter filter = body.getFixtureList().get(0).getFilterData();
  filter.maskBits = Player.invincibleMaskBit;
  body.getFixtureList().get(0).setFilterData(filter);
  renderer.setColor(new Color(1, 1, 1, 1.2f + MathUtils.sin(player.invincibleCountDown * 24)));
} else {
  Filter filter = body.getFixtureList().get(0).getFilterData();
  filter.maskBits = Player.defaultMaskBits;
  body.getFixtureList().get(0).setFilterData(filter);
  renderer.setColor(Color.WHITE);
  case DYING:
    state.setCurrentState("dying");
    Filter filter = body.getFixtureList().get(0).getFilterData();
    filter.maskBits = GameManager.NOTHING_BIT;
    body.getFixtureList().get(0).setFilterData(filter);

代码示例来源:origin: yichen0831/Bomberman_libGdx

case DYING:
  state.setCurrentState("dying");
  Filter filter = body.getFixtureList().get(0).getFilterData();
  filter.maskBits = GameManager.NOTHING_BIT;
  body.getFixtureList().get(0).setFilterData(filter);

代码示例来源:origin: yichen0831/Bomberman_libGdx

case DYING:
  state.setCurrentState("dying");
  Filter filter = body.getFixtureList().get(0).getFilterData();
  filter.maskBits = GameManager.NOTHING_BIT;
  body.getFixtureList().get(0).setFilterData(filter);

代码示例来源:origin: yichen0831/Bomberman_libGdx

case DYING:
  state.setCurrentState("dying");
  Filter filter = body.getFixtureList().get(0).getFilterData();
  filter.maskBits = GameManager.NOTHING_BIT;
  body.getFixtureList().get(0).setFilterData(filter);

相关文章