本文整理汇总了Java中com.badlogic.gdx.physics.box2d.MassData类的典型用法代码示例。如果您正苦于以下问题:Java MassData类的具体用法?Java MassData怎么用?Java MassData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MassData类属于com.badlogic.gdx.physics.box2d包,在下文中一共展示了MassData类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: createCircle
import com.badlogic.gdx.physics.box2d.MassData; //导入依赖的package包/类
public static Body createCircle() {
if (!BodyFactory.initialized) {
throw new IllegalStateException("You must initialize BodyFactory before using its functions");
}
final BodyDef testBodyDef2 = new BodyDef();
testBodyDef2.position.set(2, 3);
testBodyDef2.type = BodyDef.BodyType.DynamicBody;
testBodyDef2.fixedRotation = true;
final Body body2 = BodyFactory.world.createBody(testBodyDef2);
final CircleShape testShape2 = new CircleShape();
testShape2.setRadius(1f);
final FixtureDef testFixtureDef2 = new FixtureDef();
testFixtureDef2.shape = testShape2;
testFixtureDef2.density = 25f;
testFixtureDef2.friction = 1f;
testFixtureDef2.restitution = 0;
body2.createFixture(testFixtureDef2);
final MassData md = body2.getMassData();
md.mass = 80; // kg
body2.setMassData(md);
// System.out.println("circle - mass: " + body2.getMassData().mass + " density: " + body2.getFixtureList().get(0).getDensity());
testShape2.dispose();
return body2;
}
开发者ID:TheElk205,项目名称:KillTheNerd,代码行数:25,代码来源:BodyFactory.java
示例2: create
import com.badlogic.gdx.physics.box2d.MassData; //导入依赖的package包/类
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));
}
开发者ID:basherone,项目名称:libgdxcn,代码行数:20,代码来源:KinematicBodyTest.java
示例3: createPlayerPlatformerBody2
import com.badlogic.gdx.physics.box2d.MassData; //导入依赖的package包/类
/**
* @param position
* @return Body
*/
public static Body createPlayerPlatformerBody2(final Vector2 position) {
if (!BodyFactory.initialized) {
throw new IllegalStateException("You must initialize BodyFactory before using its functions");
}
final BodyDef bodyDef = new BodyDef();
bodyDef.position.set(position.x, position.y);
bodyDef.type = BodyDef.BodyType.DynamicBody;
bodyDef.fixedRotation = true;
// create body with world
final Body b2Body = BodyFactory.world.createBody(bodyDef);
// create shape
final PolygonShape boxShape = new PolygonShape();
boxShape.setAsBox(0.4f / 2f, 1.6f / 2f); // width: 50cm, heigth: 1,8meters ... div 2, because setAsBox(...) calcs in half sizes
// create fixture to attach shape to body
final FixtureDef fixtureDef = new FixtureDef();
fixtureDef.shape = boxShape;
fixtureDef.density = 20f; // BMI of human?
fixtureDef.friction = 0.5f;
fixtureDef.restitution = 0.1f;
b2Body.createFixture(fixtureDef);
final MassData md = b2Body.getMassData();
md.mass = 60; // kg
b2Body.setMassData(md);
boxShape.dispose(); // clean up!!
return b2Body;
}
开发者ID:TheElk205,项目名称:KillTheNerd,代码行数:34,代码来源:BodyFactory.java
示例4: createCircleBody
import com.badlogic.gdx.physics.box2d.MassData; //导入依赖的package包/类
/**
* Genera un cuerpo con forma circular
* @param world El mundo
* @param x posici�n X
* @param y posicion Y
* @return El cuerpo creado
*/
public static Body createCircleBody(World world, float x, float y) {
// Masa (en kg)
MassData mass = new MassData();
mass.mass = 100f;
// Define un cuerpo f�sico din�mico con posici�n en el mundo 2D
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.DynamicBody;
bodyDef.position.set(x, y);
Body body = world.createBody(bodyDef);
// Define una forma circular de 6 unidades de di�metro
CircleShape circle = new CircleShape();
circle.setRadius(6f);
// Define un elemento f�sico y sus propiedades y le asigna la forma circular
FixtureDef fixtureDef = new FixtureDef();
// Forma del elemento f�sico
fixtureDef.shape = circle;
// Densidad (kg/m^2)
fixtureDef.density = DENSITY;
// Coeficiente de fricci�n (0 - 1)
fixtureDef.friction = FRICTION;
// Elasticidad (0 - 1)
fixtureDef.restitution = RESTITUTION;
// A�ade el elemento f�sico al cuerpo del mundo 2D
Fixture fixture = body.createFixture(fixtureDef);
// Definir la masa del cuerpo modifica las propiedades (FixtureDef) y viceversa (densidad)
body.setMassData(mass);
circle.dispose();
return body;
}
开发者ID:sfaci,项目名称:libgdx,代码行数:44,代码来源:WorldGenerator.java
示例5: createBoxBody
import com.badlogic.gdx.physics.box2d.MassData; //导入依赖的package包/类
/**
* Genera un cuerpo con forma de caja
* @param world El mundo
* @param x Posici�n x
* @param y Posici�n y
* @return El cuerpo creado
*/
public static Body createBoxBody(World world, float x, float y) {
// Masa (en kg)
MassData mass = new MassData();
mass.mass = 100f;
// Define un cuerpo f�sico din�mico con posici�n en el mundo 2D
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.DynamicBody;
bodyDef.position.set(x, y);
Body body = world.createBody(bodyDef);
// Define una forma circular de 6 unidades de di�metro
PolygonShape box = new PolygonShape();
box.setAsBox(10f, 10f);
// Define un elemento f�sico y sus propiedades y le asigna la forma circular
FixtureDef fixtureDef = new FixtureDef();
// Forma del elemento f�sico
fixtureDef.shape = box;
// Densidad (kg/m^2)
fixtureDef.density = 10f;
// Coeficiente de fricci�n (0 - 1)
fixtureDef.friction = 0.4f;
// Elasticidad (0 - 1)
fixtureDef.restitution = 0.1f;
// A�ade el elemento f�sico al cuerpo del mundo 2D
Fixture fixture = body.createFixture(fixtureDef);
// Definir la masa del cuerpo modifica las propiedades (FixtureDef) y viceversa (densidad)
body.setMassData(mass);
box.dispose();
return body;
}
开发者ID:sfaci,项目名称:libgdx,代码行数:44,代码来源:WorldGenerator.java
示例6: Player
import com.badlogic.gdx.physics.box2d.MassData; //导入依赖的package包/类
public Player(World world, float x, float y, float width) {
super(Assets.getTexture("cage"), new CircleShape(), world, x, y, width);
this.body.setLinearDamping(2);
MassData massData = body.getMassData();
massData.mass = 1;
this.body.setMassData(massData);
addController();
}
开发者ID:AnthonyOstrich,项目名称:NicolasRage,代码行数:9,代码来源:Player.java
示例7: setMass
import com.badlogic.gdx.physics.box2d.MassData; //导入依赖的package包/类
private void setMass() {
MassData masa = new MassData();
masa.center.set(getWidth()/2, getHeight()/2);
masa.mass = 25; // Pesa 5 kilogr�mos.
getBody().setMassData(masa);
getBody().resetMassData();
}
开发者ID:costular,项目名称:crabox,代码行数:9,代码来源:Player.java
示例8: getMassData
import com.badlogic.gdx.physics.box2d.MassData; //导入依赖的package包/类
public MassData getMassData() {
return massData;
}
开发者ID:saltares,项目名称:libgdxjam,代码行数:4,代码来源:PhysicsData.java
示例9: setMassData
import com.badlogic.gdx.physics.box2d.MassData; //导入依赖的package包/类
public void setMassData(MassData massData) {
body.setMassData(massData);
}
开发者ID:GameDevWeek,项目名称:CodeBase,代码行数:4,代码来源:PhysixBodyComponent.java
示例10: MeshData
import com.badlogic.gdx.physics.box2d.MassData; //导入依赖的package包/类
public MeshData(BodyDef bodyDef, MassData massData, FixtureDef[] fixtureDefs) {
this.bodyDef = bodyDef;
this.massData = massData;
this.fixtureDefs = fixtureDefs;
}
开发者ID:ALPSquid,项目名称:0Bit-Engine,代码行数:6,代码来源:MeshData.java
示例11: read
import com.badlogic.gdx.physics.box2d.MassData; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Body read(Json json, JsonValue jsonData, Class type)
{
if(world == null)
return null;
BodyDef defaults = RubeDefaults.Body.definition;
int bodyType = json.readValue("type", int.class, defaults.type.getValue(), jsonData);
if(bodyType == BodyType.DynamicBody.getValue())
def.type = BodyType.DynamicBody;
else if(bodyType == BodyType.KinematicBody.getValue())
def.type = BodyType.KinematicBody;
else
def.type = BodyType.StaticBody;
def.position.set( json.readValue("position", Vector2.class, defaults.position, jsonData));
def.linearVelocity.set( json.readValue("linearVelocity", Vector2.class, defaults.linearVelocity, jsonData));
def.angle = json.readValue("angle", float.class, defaults.angle, jsonData);
def.angularVelocity = json.readValue("angularVelocity", float.class, defaults.angularVelocity, jsonData);
def.linearDamping = json.readValue("linearDamping", float.class, defaults.linearDamping, jsonData);
def.angularDamping = json.readValue("angularDamping", float.class, defaults.angularDamping, jsonData);
def.gravityScale = json.readValue("gravityScale", float.class, defaults.gravityScale, jsonData);
def.allowSleep = json.readValue("allowSleep", boolean.class, defaults.allowSleep, jsonData);
def.awake = json.readValue("awake", boolean.class, defaults.awake, jsonData);
def.fixedRotation = json.readValue("fixedRotation", boolean.class, defaults.fixedRotation, jsonData);
def.bullet = json.readValue("bullet", boolean.class, defaults.bullet, jsonData);
def.active = json.readValue("active", boolean.class, defaults.active, jsonData);
Body body = world.createBody(def);
if(def.type == BodyType.DynamicBody)
{
Vector2 center = json.readValue("massData-center", Vector2.class, jsonData);
float mass = json.readValue("massData-mass", float.class, 0.0f, jsonData);
float I = json.readValue("massData-I", float.class, 0.0f, jsonData);
if(center != null)
{
MassData massData = new MassData();
massData.center.set(center);
massData.mass = mass;
massData.I = I;
if(massData.mass != 0.0f || massData.I != 0.0f || massData.center.x != 0.0f || massData.center.y != 0.0f)
body.setMassData(massData);
}
}
scene.parseCustomProperties(json, body, jsonData);
String name = json.readValue("name", String.class, jsonData);
if (name != null)
{
scene.putNamed(name, body);
}
fixtureSerializer.setBody(body);
scene.addFixtures(json.readValue("fixture", Array.class, Fixture.class, jsonData));
return body;
}
开发者ID:tescott,项目名称:RubeLoader,代码行数:67,代码来源:BodySerializer.java
注:本文中的com.badlogic.gdx.physics.box2d.MassData类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论