当前位置: 首页>>代码示例>>Java>>正文


Java FixtureDef类代码示例

本文整理汇总了Java中com.badlogic.gdx.physics.box2d.FixtureDef的典型用法代码示例。如果您正苦于以下问题:Java FixtureDef类的具体用法?Java FixtureDef怎么用?Java FixtureDef使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FixtureDef类属于com.badlogic.gdx.physics.box2d包,在下文中一共展示了FixtureDef类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createCircle

import com.badlogic.gdx.physics.box2d.FixtureDef; //导入依赖的package包/类
/** 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;
}
 
开发者ID:StringMon,项目名称:homescreenarcade,代码行数:25,代码来源:Box2DFactory.java

示例2: createWall

import com.badlogic.gdx.physics.box2d.FixtureDef; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:StringMon,项目名称:homescreenarcade,代码行数:29,代码来源:Box2DFactory.java

示例3: makePolygonGround

import com.badlogic.gdx.physics.box2d.FixtureDef; //导入依赖的package包/类
/**
 * Creates polygon ground from the given object, at the given world.
 *
 * @param world  The world were the ground will be.
 * @param object The object used to initialize the ground.
 * @return The body of the created ground.
 */
static Body makePolygonGround(World world, PolygonMapObject object) {
    Polygon polygon = object.getPolygon();

    // Body and Fixture variables
    BodyDef bdef = new BodyDef();
    FixtureDef fdef = new FixtureDef();
    PolygonShape shape = new PolygonShape();

    bdef.type = BodyDef.BodyType.StaticBody;
    bdef.position.set(PIXEL_TO_METER * polygon.getX(), PIXEL_TO_METER * polygon.getY());

    Body body = world.createBody(bdef);

    float[] new_vertices = polygon.getVertices().clone();
    for (int i = 0; i < new_vertices.length; i++)
        new_vertices[i] *= PIXEL_TO_METER;

    shape.set(new_vertices);
    fdef.shape = shape;
    fdef.filter.categoryBits = GROUND_BIT;
    body.createFixture(fdef);

    return body;
}
 
开发者ID:AndreFCruz,项目名称:feup-lpoo-armadillo,代码行数:32,代码来源:B2DFactory.java

示例4: makeRectGround

import com.badlogic.gdx.physics.box2d.FixtureDef; //导入依赖的package包/类
/**
 * Creates rectangular ground from the given object, at the given world.
 *
 * @param world  The world were the ground will be.
 * @param object The object used to initialize the ground.
 * @return The body of the created ground.
 */
static Body makeRectGround(World world, RectangleMapObject object) {
    Rectangle rect = object.getRectangle();

    // Body and Fixture variables
    BodyDef bdef = new BodyDef();
    FixtureDef fdef = new FixtureDef();
    PolygonShape shape = new PolygonShape();

    bdef.type = BodyDef.BodyType.StaticBody;
    bdef.position.set(PIXEL_TO_METER * (rect.getX() + rect.getWidth() / 2), PIXEL_TO_METER * (rect.getY() + rect.getHeight() / 2));

    Body body = world.createBody(bdef);

    shape.setAsBox((rect.getWidth() / 2) * PIXEL_TO_METER, (rect.getHeight() / 2) * PIXEL_TO_METER);
    fdef.shape = shape;
    fdef.filter.categoryBits = GROUND_BIT;
    body.createFixture(fdef);

    return body;
}
 
开发者ID:AndreFCruz,项目名称:feup-lpoo-armadillo,代码行数:28,代码来源:B2DFactory.java

示例5: WaterModel

import com.badlogic.gdx.physics.box2d.FixtureDef; //导入依赖的package包/类
/**
 * Water Model's constructor.
 * Creates a water model from the given object, into the given world.
 *
 * @param world The world the water model will be in.
 * @param rect  The rectangle to create the water model with.
 */
public WaterModel(World world, Rectangle rect) {
    // Body and Fixture variables
    BodyDef bdef = new BodyDef();
    FixtureDef fdef = new FixtureDef();
    PolygonShape shape = new PolygonShape();

    bdef.type = BodyDef.BodyType.StaticBody;
    bdef.position.set(PIXEL_TO_METER * (rect.getX() + rect.getWidth() / 2), PIXEL_TO_METER * (rect.getY() + rect.getHeight() / 2));

    this.body = world.createBody(bdef);

    shape.setAsBox((rect.getWidth() / 2) * PIXEL_TO_METER, (rect.getHeight() / 2) * PIXEL_TO_METER);
    fdef.shape = shape;
    fdef.filter.categoryBits = FLUID_BIT;
    fdef.isSensor = true;
    fdef.density = 1f;
    fdef.friction = 0.1f;
    fdef.restitution = 0f;
    body.createFixture(fdef);

    body.setUserData(new BuoyancyController(world, body.getFixtureList().first()));

}
 
开发者ID:AndreFCruz,项目名称:feup-lpoo-armadillo,代码行数:31,代码来源:WaterModel.java

示例6: createFixture

import com.badlogic.gdx.physics.box2d.FixtureDef; //导入依赖的package包/类
/**
 * Creates a Fixture with the given Fixture Properties.
 *
 * @param fixtureProperties Fixture properties used to generate the fixture
 */
final void createFixture(FixtureProperties fixtureProperties) {
    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = fixtureProperties.getShape();

    fixtureDef.density = fixtureProperties.getDensity();
    fixtureDef.friction = fixtureProperties.getFriction();
    fixtureDef.restitution = fixtureProperties.getRestitution();
    fixtureDef.filter.categoryBits = fixtureProperties.getCategory();
    fixtureDef.filter.maskBits = fixtureProperties.getMask();
    fixtureDef.isSensor = fixtureProperties.isSensor();

    body.createFixture(fixtureDef);

    fixtureProperties.getShape().dispose();
}
 
开发者ID:AndreFCruz,项目名称:feup-lpoo-armadillo,代码行数:21,代码来源:EntityModel.java

示例7: createTempBodyDistanceJoint

import com.badlogic.gdx.physics.box2d.FixtureDef; //导入依赖的package包/类
public Body createTempBodyDistanceJoint(Body bodyA, Body bodyB,
    Vector2 localA, Vector2 localB, int length) {
DistanceJointDef dJoint = new DistanceJointDef();
FixtureDef fixtureDef = createFixtureDef(1f, 0.5f, 0.2f, (short) 0x0004);
IPhysicsObject sprite = (IPhysicsObject) bodyA.getUserData();
Body temp = createTempBody(sprite.getX(), sprite.getY(), fixtureDef);
createRevoluteJoint(bodyA, temp, localA, Vector2.Zero);
dJoint.bodyA = temp;
dJoint.bodyB = bodyB;
dJoint.localAnchorA.set(localA.x * WORLD_TO_BOX, localA.y
	* WORLD_TO_BOX);
dJoint.localAnchorB.set(localB.x * WORLD_TO_BOX, localB.y
	* WORLD_TO_BOX);
dJoint.length = length * WORLD_TO_BOX;
world.createJoint(dJoint);
return temp;
   }
 
开发者ID:game-libgdx-unity,项目名称:GDX-Engine,代码行数:18,代码来源:PhysicsManager.java

示例8: createTempBody

import com.badlogic.gdx.physics.box2d.FixtureDef; //导入依赖的package包/类
public Body createTempBody(float x, float y, FixtureDef fixtureDef) {
// Dynamic Body
BodyDef bodyDef = new BodyDef();
if (box2dDebug)
    bodyDef.type = BodyType.StaticBody;
else
    bodyDef.type = BodyType.DynamicBody;

// transform into box2d
x = x * WORLD_TO_BOX;
y = y * WORLD_TO_BOX;

bodyDef.position.set(x, y);

Body body = world.createBody(bodyDef);

Shape shape = new CircleShape();
((CircleShape) shape).setRadius(1 * WORLD_TO_BOX);

if (fixtureDef == null)
    throw new GdxRuntimeException("fixtureDef cannot be null!");
fixtureDef.shape = shape;
body.createFixture(fixtureDef);
return body;
   }
 
开发者ID:game-libgdx-unity,项目名称:GDX-Engine,代码行数:26,代码来源:PhysicsManager.java

示例9: createRopeTipBody

import com.badlogic.gdx.physics.box2d.FixtureDef; //导入依赖的package包/类
private Body createRopeTipBody()
{
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyType.DynamicBody;
    bodyDef.linearDamping = 0.5f;
    Body body = world.createBody(bodyDef);
    
    FixtureDef circleDef = new FixtureDef();
    CircleShape circle = new CircleShape();
    circle.setRadius(1.0f/PTM_RATIO);
    circleDef.shape = circle;
    circleDef.density = 10.0f;
    
    // Since these tips don't have to collide with anything
    // set the mask bits to zero
    circleDef.filter.maskBits = 0x01; //0;
    body.createFixture(circleDef);
    
    return body;
}
 
开发者ID:game-libgdx-unity,项目名称:GDX-Engine,代码行数:21,代码来源:Rope.java

示例10: createTempBodyDistanceJoint

import com.badlogic.gdx.physics.box2d.FixtureDef; //导入依赖的package包/类
public Body createTempBodyDistanceJoint(Body bodyA, Body bodyB,
		Vector2 localA, Vector2 localB, int length) {
	DistanceJointDef dJoint = new DistanceJointDef();
	FixtureDef fixtureDef = createFixtureDef(1f, 0.5f, 0.2f, (short) 0x0004);
	IPhysicsObject sprite = (IPhysicsObject) bodyA.getUserData();
	Body temp = createTempBody(sprite.getX(), sprite.getY(), fixtureDef);
	createRevoluteJoint(bodyA, temp, localA, Vector2.Zero);
	dJoint.bodyA = temp;
	dJoint.bodyB = bodyB;
	dJoint.localAnchorA.set(localA.x * WORLD_TO_BOX, localA.y
			* WORLD_TO_BOX);
	dJoint.localAnchorB.set(localB.x * WORLD_TO_BOX, localB.y
			* WORLD_TO_BOX);
	dJoint.length = length * WORLD_TO_BOX;
	world.createJoint(dJoint);
	return temp;
}
 
开发者ID:game-libgdx-unity,项目名称:GDX-Engine,代码行数:18,代码来源:PhysicsTiledScene.java

示例11: createTempBody

import com.badlogic.gdx.physics.box2d.FixtureDef; //导入依赖的package包/类
public Body createTempBody(float x, float y, FixtureDef fixtureDef) {
	// Dynamic Body
	BodyDef bodyDef = new BodyDef();
	if (box2dDebug)
		bodyDef.type = BodyType.StaticBody;
	else
		bodyDef.type = BodyType.DynamicBody;

	// transform into box2d
	x = x * WORLD_TO_BOX;
	y = y * WORLD_TO_BOX;

	bodyDef.position.set(x, y);

	Body body = world.createBody(bodyDef);

	Shape shape = new CircleShape();
	((CircleShape) shape).setRadius(1 * WORLD_TO_BOX);

	if (fixtureDef == null)
		throw new GdxRuntimeException("fixtureDef cannot be null!");
	fixtureDef.shape = shape;
	body.createFixture(fixtureDef);
	return body;
}
 
开发者ID:game-libgdx-unity,项目名称:GDX-Engine,代码行数:26,代码来源:PhysicsTiledScene.java

示例12: createBody

import com.badlogic.gdx.physics.box2d.FixtureDef; //导入依赖的package包/类
private void createBody() {
	BodyDef bodyDef = new BodyDef();
	bodyDef.type = BodyType.DynamicBody;
	
	// Set our body's starting position in the world
	bodyDef.position.set(Gdx.input.getX() / 100f, camera.viewportHeight - Gdx.input.getY() / 100f);
	
	// Create our body in the world using our body definition
	Body body = world.createBody(bodyDef);

	// Create a circle shape and set its radius to 6
	PolygonShape square = new PolygonShape();
	square.setAsBox(0.3f, 0.3f);

	// Create a fixture definition to apply our shape to
	FixtureDef fixtureDef = new FixtureDef();
	fixtureDef.shape = square;
	fixtureDef.density = 0.5f;
	fixtureDef.friction = 0.5f;
	fixtureDef.restitution = 0.5f;

	// Create our fixture and attach it to the body
	body.createFixture(fixtureDef);

	square.dispose();
}
 
开发者ID:jocasolo,项目名称:water2d-libgdx,代码行数:27,代码来源:GameMain.java

示例13: InteractiveTileObject

import com.badlogic.gdx.physics.box2d.FixtureDef; //导入依赖的package包/类
public InteractiveTileObject(World world, TiledMap map, Rectangle bounds){
    this.world = world;
    this.map = map;
    this.bounds = bounds;

    BodyDef bdef = new BodyDef();
    FixtureDef fdef = new FixtureDef();
    PolygonShape shape = new PolygonShape();

    bdef.type = BodyDef.BodyType.StaticBody;
    bdef.position.set((bounds.getX() + bounds.getWidth() / 2) / NoObjectionGame.PPM, (bounds.getY() + bounds.getHeight() / 2 )/ NoObjectionGame.PPM);

    body = world.createBody(bdef);
    shape.setAsBox(bounds.getWidth() / 2 / NoObjectionGame.PPM, bounds.getHeight() / 2 / NoObjectionGame.PPM);
    fdef.shape = shape;
    fixture = body.createFixture(fdef);
}
 
开发者ID:MissionBit,项目名称:summer17-android,代码行数:18,代码来源:InteractiveTileObject.java

示例14: createSpinner

import com.badlogic.gdx.physics.box2d.FixtureDef; //导入依赖的package包/类
public static Body createSpinner(World world) {
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyDef.BodyType.DynamicBody;
    bodyDef.position.set(Constants.SPINNER_POSITIONS);
    Body body = world.createBody(bodyDef);
    CircleShape circle = new CircleShape();
    circle.setRadius(Constants.SPINNER_SIZE);
    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = circle;
    fixtureDef.density = Constants.SPENNER_DENSITY;
    fixtureDef.friction = 0f;
    fixtureDef.restitution = 0.45f;
    body.createFixture(fixtureDef);
    circle.dispose();
    return body;
}
 
开发者ID:ZephyrVentum,项目名称:FlappySpinner,代码行数:17,代码来源:WorldUtils.java

示例15: createEntityBody

import com.badlogic.gdx.physics.box2d.FixtureDef; //导入依赖的package包/类
/**
 * Erlaubt es den Unterklassen möglichst einfach einen beliebigen Box2D Körper zu erstellen.
 *
 * @param position die Startposition des Body
 * @param shape die Form, die für dne Body verwendet werden soll
 * @param type der Typ des Körpers
 * @return ein Box2D Körper
 */
protected Body createEntityBody(Vector2 position, Shape shape, BodyDef.BodyType type)
{
    position.scl(Physics.MPP);

    BodyDef bodyDef = new BodyDef();
    bodyDef.type = type;
    bodyDef.position.set(position);
    bodyDef.fixedRotation = true;

    Body body = worldObjectManager.getPhysicalWorld().createBody(bodyDef);
    body.setUserData(this);

    FixtureDef fixture = new FixtureDef();
    fixture.shape = shape;
    fixture.filter.categoryBits = Physics.CATEGORY_ENTITIES;
    fixture.filter.maskBits = Physics.MASK_ENTITIES;

    body.createFixture(fixture).setUserData(this);

    shape.dispose();

    return body;
}
 
开发者ID:Entwicklerpages,项目名称:school-game,代码行数:32,代码来源:BaseEntity.java


注:本文中的com.badlogic.gdx.physics.box2d.FixtureDef类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。