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


Java Body.createFixture方法代码示例

本文整理汇总了Java中com.badlogic.gdx.physics.box2d.Body.createFixture方法的典型用法代码示例。如果您正苦于以下问题:Java Body.createFixture方法的具体用法?Java Body.createFixture怎么用?Java Body.createFixture使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.badlogic.gdx.physics.box2d.Body的用法示例。


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

示例1: createCircle

import com.badlogic.gdx.physics.box2d.Body; //导入方法依赖的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.Body; //导入方法依赖的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.Body; //导入方法依赖的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.Body; //导入方法依赖的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: createStaticBoxBody

import com.badlogic.gdx.physics.box2d.Body; //导入方法依赖的package包/类
/**
    * Create static body from a TiledObject Refer the box2d manual to
    * understand the static body
    * 
    * @param o
    *            TiledObject
    */
   public Body createStaticBoxBody(float x, float y, float width, float height) {
BodyDef groundBodyDef = new BodyDef();
groundBodyDef.type = BodyType.StaticBody;

// transform into box2d
x = x * WORLD_TO_BOX;

// get position-y from map
y = Gdx.graphics.getHeight() - y;
// transform into box2d
y = y * WORLD_TO_BOX;

groundBodyDef.position.set(x, y);
Body groundBody = world.createBody(groundBodyDef);
PolygonShape polygon = new PolygonShape();
((PolygonShape) polygon).setAsBox(width * WORLD_TO_BOX / 2, height
	* WORLD_TO_BOX / 2);
groundBody.createFixture(polygon, 0.0f);
groundBody.setUserData("static");
return groundBody;
   }
 
开发者ID:game-libgdx-unity,项目名称:GDX-Engine,代码行数:29,代码来源:PhysicsManager.java

示例6: createStaticCircleBody

import com.badlogic.gdx.physics.box2d.Body; //导入方法依赖的package包/类
/**
    * Create static body from a TiledObject Refer the box2d manual to
    * understand the static body
    * 
    * @param o
    *            TiledObject
    */
   public Body createStaticCircleBody(float x, float y, float radius) {
BodyDef groundBodyDef = new BodyDef();
groundBodyDef.type = BodyType.StaticBody;
// transform into box2d
x = x * WORLD_TO_BOX;
// get position-y of object from map
y = Gdx.graphics.getHeight() - y;
// transform into box2d
y = y * WORLD_TO_BOX;

groundBodyDef.position.set(x, y);
Body groundBody = world.createBody(groundBodyDef);
CircleShape shape = new CircleShape();
((CircleShape) shape).setRadius(radius * WORLD_TO_BOX / 2);
groundBody.createFixture(shape, 0.0f);
groundBody.setUserData("static");
return groundBody;
   }
 
开发者ID:game-libgdx-unity,项目名称:GDX-Engine,代码行数:26,代码来源:PhysicsManager.java

示例7: createRopeTipBody

import com.badlogic.gdx.physics.box2d.Body; //导入方法依赖的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

示例8: createStaticBoxBody

import com.badlogic.gdx.physics.box2d.Body; //导入方法依赖的package包/类
/**
 * Create static body from a TiledObject Refer the box2d manual to
 * understand the static body
 * 
 * @param o
 *            TiledObject
 */
public Body createStaticBoxBody(float x, float y, float width, float height) {
	BodyDef groundBodyDef = new BodyDef();
	groundBodyDef.type = BodyType.StaticBody;

	// transform into box2d
	x = x * WORLD_TO_BOX;

	// get position-y from map
	y = tileMapRenderer.getMapHeightUnits() - y;
	// transform into box2d
	y = y * WORLD_TO_BOX;

	groundBodyDef.position.set(x, y);
	Body groundBody = world.createBody(groundBodyDef);
	PolygonShape polygon = new PolygonShape();
	((PolygonShape) polygon).setAsBox(width * WORLD_TO_BOX / 2, height
			* WORLD_TO_BOX / 2);
	groundBody.createFixture(polygon, 0.0f);
	groundBody.setUserData("static");
	return groundBody;
}
 
开发者ID:game-libgdx-unity,项目名称:GDX-Engine,代码行数:29,代码来源:PhysicsTiledScene.java

示例9: createTempBody

import com.badlogic.gdx.physics.box2d.Body; //导入方法依赖的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

示例10: createBody

import com.badlogic.gdx.physics.box2d.Body; //导入方法依赖的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

示例11: createSpinner

import com.badlogic.gdx.physics.box2d.Body; //导入方法依赖的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

示例12: createTopTube

import com.badlogic.gdx.physics.box2d.Body; //导入方法依赖的package包/类
public static Array<Body> createTopTube(World world, float posX) {

        float posY = generateTubePosition();

        BodyDef bodyDef = new BodyDef();
        bodyDef.type = BodyDef.BodyType.KinematicBody;
        bodyDef.position.set(posX, posY);
        PolygonShape shape = new PolygonShape();
        shape.setAsBox(Constants.TUBE_WIDTH / 2, Constants.TUBE_HEIGHT / 2);
        Body bodyTop = world.createBody(bodyDef);
        bodyTop.createFixture(shape, 0f);
        bodyTop.resetMassData();
        shape.dispose();
        bodyTop.setLinearVelocity(Constants.TUBE_SPEED, 0.0f);
        Array<Body> bodies = new Array<Body>();
        bodies.add(bodyTop);
        bodies.add(createBottomTube(world, posX, posY));
        return bodies;
    }
 
开发者ID:ZephyrVentum,项目名称:FlappySpinner,代码行数:20,代码来源:WorldUtils.java

示例13: createBottomTube

import com.badlogic.gdx.physics.box2d.Body; //导入方法依赖的package包/类
public static Body createBottomTube(World world, float posX, float posY) {

        BodyDef bodyDef = new BodyDef();
        bodyDef.type = BodyDef.BodyType.KinematicBody;
        bodyDef.position.set(posX, posY - Constants.TUBE_SPACING - 30);
        PolygonShape shape = new PolygonShape();
        shape.setAsBox(Constants.TUBE_WIDTH / 2, Constants.TUBE_HEIGHT / 2);
        Body body = world.createBody(bodyDef);
        body.createFixture(shape, 0f);
        body.resetMassData();
        shape.dispose();
        body.setLinearVelocity(Constants.TUBE_SPEED, 0.0f);
        return body;
    }
 
开发者ID:ZephyrVentum,项目名称:FlappySpinner,代码行数:15,代码来源:WorldUtils.java

示例14: buildBodiesFromLayer

import com.badlogic.gdx.physics.box2d.Body; //导入方法依赖的package包/类
/**
 * Erzeugt aus einem ObjectLayer Box2D Körper.
 *
 * @param layer die Ebene
 * @param world die Box2D Welt
 */
public static void buildBodiesFromLayer(MapLayer layer, World world)
{
    for(MapObject tileObject : layer.getObjects())
    {
        if (
                tileObject instanceof TextureMapObject ||
                tileObject instanceof CircleMapObject ||
                tileObject instanceof EllipseMapObject)
            continue;

        Shape shape = createShape(tileObject, TYPE_COLLISION);

        if (shape == null)
            continue;

        BodyDef bodyDef = new BodyDef();
        bodyDef.type = BodyDef.BodyType.StaticBody;

        Body body = world.createBody(bodyDef);

        FixtureDef fixture = new FixtureDef();
        fixture.shape = shape;
        fixture.filter.categoryBits = Physics.CATEGORY_WORLD;
        fixture.filter.maskBits = Physics.MASK_WORLD;

        body.createFixture(fixture);

        shape.dispose();
    }
}
 
开发者ID:Entwicklerpages,项目名称:school-game,代码行数:37,代码来源:PhysicsTileMapBuilder.java

示例15: createGround

import com.badlogic.gdx.physics.box2d.Body; //导入方法依赖的package包/类
public static Array<Body> createGround(World world) {
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyDef.BodyType.StaticBody;
    bodyDef.position.set(0, 0);
    Body bodyGround = world.createBody(bodyDef);
    PolygonShape shape = new PolygonShape();
    shape.setAsBox(Constants.GROUND_SIZE.x, Constants.GROUND_SIZE.y);
    bodyGround.createFixture(shape, 0f);
    shape.dispose();

    Array<Body> bodies = new Array<Body>();
    bodies.add(bodyGround);
    bodies.add(createSky(world));
    return bodies;
}
 
开发者ID:ZephyrVentum,项目名称:FlappySpinner,代码行数:16,代码来源:WorldUtils.java


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