本文整理了Java中com.badlogic.gdx.physics.box2d.Body.setType()
方法的一些代码示例,展示了Body.setType()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Body.setType()
方法的具体详情如下:
包路径:com.badlogic.gdx.physics.box2d.Body
类名称:Body
方法名:setType
[英]Set the type of this body. This may alter the mass and velocity.
[中]设置此实体的类型。这可能会改变质量和速度。
代码示例来源:origin: libgdx/libgdx
@Override
public boolean keyDown (int keyCode) {
if (keyCode == Keys.D) m_platform.setType(BodyType.DynamicBody);
if (keyCode == Keys.S) m_platform.setType(BodyType.StaticBody);
if (keyCode == Keys.K) {
m_platform.setType(BodyType.KinematicBody);
m_platform.setLinearVelocity(tmp.set(-m_speed, 0));
m_platform.setAngularVelocity(0);
}
return false;
}
代码示例来源: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: dozingcat/Vector-Pinball
/** Creates a circle object with the given position and radius. Resitution defaults to 0.6. */
public static Body createCircle(World world, float x, float y, float radius, boolean isStatic) {
CircleShape sd = new CircleShape();
sd.setRadius(radius);
FixtureDef fdef = new FixtureDef();
fdef.shape = sd;
fdef.density = 1.0f;
fdef.friction = 0.3f;
fdef.restitution = 0.6f;
BodyDef bd = new BodyDef();
bd.allowSleep = true;
bd.position.set(x, y);
Body body = world.createBody(bd);
body.createFixture(fdef);
if (isStatic) {
body.setType(BodyDef.BodyType.StaticBody);
}
else {
body.setType(BodyDef.BodyType.DynamicBody);
}
return body;
}
代码示例来源:origin: narfman0/GDXWorld
@Override public CompletionEnum execute(float dt) {
PrismaticJoint joint = (PrismaticJoint)executor.getPhysicsJoint(this.joint);
joint.enableMotor(true);
joint.setMaxMotorForce(maxMotorForceB);
joint.setMotorSpeed(motorSpeedB);
executor.getPhysicsObject(name).setType(BodyType.DynamicBody);
return CompletionEnum.EXECUTING;
}
代码示例来源:origin: narfman0/GDXWorld
@Override public CompletionEnum tick(float dt){
PrismaticJoint joint = (PrismaticJoint)executor.getPhysicsJoint(this.joint);
if(joint.isMotorEnabled() && towardA && executor.getPhysicsObject(name).getWorldCenter().dst(pointA) < TURN_DISTANCE){
towardA = false;
joint.setMaxMotorForce(maxMotorForceB);
joint.setMotorSpeed(motorSpeedB);
joint.enableMotor(false);
executor.getPhysicsObject(name).setType(BodyType.StaticBody);
timeChangeDirection = System.currentTimeMillis() + waitDuration;
}else if(joint.isMotorEnabled() && !towardA && executor.getPhysicsObject(name).getWorldCenter().dst(pointB) < TURN_DISTANCE){
towardA = true;
joint.setMaxMotorForce(maxMotorForceA);
joint.setMotorSpeed(motorSpeedA);
joint.enableMotor(false);
executor.getPhysicsObject(name).setType(BodyType.StaticBody);
timeChangeDirection = System.currentTimeMillis() + waitDuration;
}else if(!joint.isMotorEnabled() && System.currentTimeMillis() > timeChangeDirection){
joint.enableMotor(true);
executor.getPhysicsObject(name).setType(BodyType.DynamicBody);
}
return CompletionEnum.EXECUTING;
}
代码示例来源:origin: dozingcat/Vector-Pinball
/**
* Creates a wall by constructing a rectangle whose corners are (xmin,ymin) and (xmax,ymax),
* and rotating the box counterclockwise through the given angle, with specified restitution.
*/
public static Body createWall(World world, float xmin, float ymin, float xmax, float ymax,
float angle, float restitution) {
float cx = (xmin + xmax) / 2;
float cy = (ymin + ymax) / 2;
float hx = Math.abs((xmax - xmin) / 2);
float hy = Math.abs((ymax - ymin) / 2);
PolygonShape wallshape = new PolygonShape();
// Don't set the angle here; instead call setTransform on the body below. This allows future
// calls to setTransform to adjust the rotation as expected.
wallshape.setAsBox(hx, hy, new Vector2(0f, 0f), 0f);
FixtureDef fdef = new FixtureDef();
fdef.shape = wallshape;
fdef.density = 1.0f;
if (restitution>0) fdef.restitution = restitution;
BodyDef bd = new BodyDef();
bd.position.set(cx, cy);
Body wall = world.createBody(bd);
wall.createFixture(fdef);
wall.setType(BodyDef.BodyType.StaticBody);
wall.setTransform(cx, cy, angle);
return wall;
}
代码示例来源: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: manuelbua/uracer-kotd
Body wall = world.createBody(bd);
wall.createFixture(fdef);
wall.setType(BodyDef.BodyType.StaticBody);
return wall;
内容来源于网络,如有侵权,请联系作者删除!