本文整理了Java中com.badlogic.gdx.physics.box2d.Body.resetMassData()
方法的一些代码示例,展示了Body.resetMassData()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Body.resetMassData()
方法的具体详情如下:
包路径:com.badlogic.gdx.physics.box2d.Body
类名称:Body
方法名:resetMassData
[英]This resets the mass properties to the sum of the mass properties of the fixtures. This normally does not need to be called unless you called SetMassData to override the mass and you later want to reset the mass.
[中]这会将质量特性重置为装置的质量特性之和。除非调用SetMassData以覆盖体量,并且以后要重置体量,否则通常不需要调用此函数。
代码示例来源: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: danialgoodwin/dev
public static Body createRunner(World world) {
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyDef.BodyType.DynamicBody;
bodyDef.position.set(new Vector2(Constants.RUNNER_X, Constants.RUNNER_Y));
PolygonShape shape = new PolygonShape();
shape.setAsBox(Constants.RUNNER_WIDTH / 2, Constants.RUNNER_HEIGHT / 2);
Body body = world.createBody(bodyDef);
body.setGravityScale(Constants.RUNNER_GRAVITY_SCALE);
body.createFixture(shape, Constants.RUNNER_DENSITY);
body.resetMassData();
body.setUserData(new RunnerUserData(Constants.RUNNER_WIDTH, Constants.RUNNER_HEIGHT));
shape.dispose();
return body;
}
代码示例来源:origin: danialgoodwin/dev
public static Body createEnemy(World world) {
EnemyType enemyType = RandomUtils.getRandomEnemyType();
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyDef.BodyType.KinematicBody;
bodyDef.position.set(new Vector2(enemyType.getX(), enemyType.getY()));
PolygonShape shape = new PolygonShape();
shape.setAsBox(enemyType.getWidth() / 2, enemyType.getHeight() / 2);
Body body = world.createBody(bodyDef);
body.createFixture(shape, enemyType.getDensity());
body.resetMassData();
EnemyUserData userData = new EnemyUserData(enemyType.getWidth(), enemyType.getHeight(), enemyType.getRegions());
body.setUserData(userData);
shape.dispose();
return body;
}
内容来源于网络,如有侵权,请联系作者删除!