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

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

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

Body.setMassData介绍

[英]Set the mass properties to override the mass properties of the fixtures. Note that this changes the center of mass position. Note that creating or destroying fixtures can also alter the mass. This function has no effect if the body isn't dynamic.
[中]设置体量特性以替代装置的体量特性。请注意,这会更改质心位置。请注意,创建或销毁装置也可以改变质量。如果主体不是动态的,则此功能无效。

代码示例

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

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

body.setMassData(mdata);

相关文章