Java 类com.badlogic.gdx.physics.box2d.BodyDef 实例源码

项目:homescreenarcade    文件:FlipperElement.java   
@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.
}
项目:homescreenarcade    文件:Box2DFactory.java   
/** 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;
}
项目:homescreenarcade    文件:Box2DFactory.java   
/**
 * 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;
}
项目:feup-lpoo-armadillo    文件:B2DFactory.java   
/**
 * 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;
}
项目:feup-lpoo-armadillo    文件:B2DFactory.java   
/**
 * 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;
}
项目:feup-lpoo-armadillo    文件:WaterModel.java   
/**
 * 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()));

}
项目:GDX-Engine    文件:PhysicsManager.java   
/**
    * 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;
   }
项目:GDX-Engine    文件:PhysicsManager.java   
/**
    * 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;
   }
项目:GDX-Engine    文件:PhysicsManager.java   
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;
   }
项目:GDX-Engine    文件:Rope.java   
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;
}
项目:GDX-Engine    文件:PhysicsTiledScene.java   
/**
 * 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;
}
项目:GDX-Engine    文件:PhysicsTiledScene.java   
/**
 * 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 = tileMapRenderer.getMapHeightUnits() - 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;
}
项目:GDX-Engine    文件:PhysicsTiledScene.java   
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;
}
项目:water2d-libgdx    文件:GameMain.java   
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();
}
项目:summer17-android    文件:InteractiveTileObject.java   
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);
}
项目:FlappySpinner    文件:WorldUtils.java   
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;
}
项目:FlappySpinner    文件:WorldUtils.java   
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;
    }
项目:school-game    文件:BaseEntity.java   
/**
 * 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;
}
项目:school-game    文件:StoneBarrier.java   
/**
 * Inititalisiert den NPC.
 * Lädt alle Grafiken und Animationen.
 */
@Override
public void onInit()
{
    super.onInit();

    stoneAtlas = new TextureAtlas(Gdx.files.internal("data/graphics/packed/stone.atlas"));
    bigStone = stoneAtlas.findRegion("stone_big");

    if (rawObject instanceof RectangleMapObject)
    {
        RectangleMapObject rectObject = (RectangleMapObject) rawObject;
        Rectangle rect = rectObject.getRectangle();

        position = new Vector2(rect.getX() + rect.getWidth() / 2f, rect.getY());
        startPosition = new Vector2(rect.getX(), rect.getY());
        rectShape = Physics.createRectangle(rect.getWidth(), rect.getHeight(), new Vector2(rect.getWidth() / 2f, rect.getHeight() / 2f));

        if (activate)
            body = createEntityBody(startPosition, rectShape, BodyDef.BodyType.KinematicBody);

    } else {
        Gdx.app.log("WARNING", "Stone Barrier " + objectId + " must have an RectangleMapObject!");
        worldObjectManager.removeObject(this);
    }
}
项目:school-game    文件:StoneBarrier.java   
public void create()
{
    if (activate)
    {
        Gdx.app.log("WARNING", "Cannot create StoneBarrier " + objectId + ": already created.");
        return;
    }

    activate = true;

    Gdx.app.postRunnable(new Runnable()
    {
        @Override
        public void run()
        {
            body = createEntityBody(startPosition, rectShape, BodyDef.BodyType.KinematicBody);
        }
    });
}
项目:school-game    文件:InteractionHandler.java   
/**
 * Erzeugt automatisch aus einem MapObject einen statischen Trigger.
 *
 * @see InteractionHandler#createInteractionFixture(Body, Shape)
 *
 * @param mapObject das MapObject
 */
public void createStaticInteractionBody(MapObject mapObject)
{
    Shape shape = PhysicsTileMapBuilder.createShape(mapObject, PhysicsTileMapBuilder.TYPE_TRIGGER);

    if (shape == null)
    {
        Gdx.app.log("WARNING", "Unkown trigger type! The interaction object " + mapObject.getName() + " will be ignored!");
        return;
    }

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

    Body trigger = manager.getPhysicalWorld().createBody(triggerDef);

    createInteractionFixture(trigger, shape);

    shape.dispose();
}
项目:school-game    文件:AttackHandler.java   
/**
 * Erzeugt automatisch aus einem MapObject einen statischen Trigger.
 *
 * @see AttackHandler#createAttackFixture(Body, Shape)
 *
 * @param mapObject das MapObject
 */
public void createStaticAttackBody(MapObject mapObject)
{
    Shape shape = PhysicsTileMapBuilder.createShape(mapObject, PhysicsTileMapBuilder.TYPE_TRIGGER);

    if (shape == null)
    {
        Gdx.app.log("WARNING", "Unkown trigger type! The attack object " + mapObject.getName() + " will be ignored!");
        return;
    }

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

    Body trigger = manager.getPhysicalWorld().createBody(triggerDef);

    createAttackFixture(trigger, shape);

    shape.dispose();
}
项目:school-game    文件:AttackHandler.java   
/**
 * Erzeugt automatisch einen Kreis als statischen Trigger.
 *
 * @see AttackHandler#createAttackFixture(Body, Shape)
 *
 * @param position der Mittelpunkt des Kreises
 * @param radius der Radius des Kreises
 */
public void createStaticAttackBody(Vector2 position, float radius)
{
    CircleShape circle = new CircleShape();

    circle.setPosition(new Vector2(position.x, position.y).scl(Physics.MPP));
    circle.setRadius(radius * Physics.MPP);

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

    Body trigger = manager.getPhysicalWorld().createBody(triggerDef);

    createAttackFixture(trigger, circle);

    circle.dispose();
}
项目:libGdx-xiyou    文件:Tao.java   
private void init() {
    mRegion = MyGdxGame.assetManager.getTextureAtlas(Constant.PLAY_BLOOD).findRegion("hp");

    mBodyDef = new BodyDef();
    mFixtureDef = new FixtureDef();
    PolygonShape shape = new PolygonShape();

    //初始化刚体形状
    mBodyDef.type = BodyDef.BodyType.StaticBody;
    mBodyDef.position.set(x, y);

    shape.setAsBox(30 / Constant.RATE, 30 / Constant.RATE);
    mFixtureDef.shape = shape;
    mFixtureDef.isSensor = true;
    mFixtureDef.filter.categoryBits = Constant.TAO;
    mFixtureDef.filter.maskBits = Constant.PLAYER;

    mBody = mWorld.createBody(mBodyDef);
    mBody.createFixture(mFixtureDef).setUserData("tao");
}
项目:libGdx-xiyou    文件:Blue.java   
private void init() {
    mRegion = MyGdxGame.assetManager.getTextureAtlas(Constant.PLAY_BLOOD).findRegion("mp");

    mBodyDef = new BodyDef();
    mFixtureDef = new FixtureDef();
    PolygonShape shape = new PolygonShape();

    //初始化刚体形状
    mBodyDef.type = BodyDef.BodyType.StaticBody;
    mBodyDef.position.set(x, y);

    shape.setAsBox(30 / Constant.RATE, 30 / Constant.RATE);
    mFixtureDef.shape = shape;
    mFixtureDef.isSensor = true;
    mFixtureDef.filter.categoryBits = Constant.BLUE;
    mFixtureDef.filter.maskBits = Constant.PLAYER;

    mBody = mWorld.createBody(mBodyDef);
    mBody.createFixture(mFixtureDef).setUserData("blue");
}
项目:fluffybalance    文件:Balanceball.java   
private void initBall() {
    float radius = 26;

    mBall = new Circle(0.f, 0.f, radius);

    mBallTextureRegion = new TextureRegion(new Texture(Gdx.files.internal("ball.png")));

    // create physics body
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyDef.BodyType.DynamicBody;
    bodyDef.position.set(mBall.x, mBall.y);

    CircleShape ballShape = new CircleShape();
    ballShape.setRadius(mBall.radius - 2.f);

    mBallBody = mWorld.createBody(bodyDef);
    mBallBody.setUserData(new BodyUserDate(BODY_USER_DATA_TYPE_BALL));
    Fixture fixture = mBallBody.createFixture(ballShape, 0.5f);
    fixture.setFriction(BALL_FRICTION_BASE);
    fixture.setRestitution(0.4f);

    ballShape.dispose();
}
项目:QuackHack    文件:Box.java   
public Box(World world, MapObject object){
    super(Assets.getAtlas().findRegion("boxCrate_double"));
    Rectangle rect = ((RectangleMapObject) object).getRectangle();
    bdef.type = BodyDef.BodyType.DynamicBody;
    bdef.position.set((rect.getX()+rect.getWidth()/2)/ QuackHack.PPM, (rect.getY() + rect.getHeight()/2)/QuackHack.PPM); // I don't follow the math
    body = world.createBody(bdef);

    shape.setAsBox(rect.getWidth() / 2 / QuackHack.PPM, rect.getHeight() / 2 / QuackHack.PPM);
    fdef.shape = shape;
    fdef.friction = 0.4f;
    fdef.density = 0.1f;
    body.createFixture(fdef);

    boxRegion = new TextureRegion(getTexture(), 0, 0, 128, 128);
    setBounds(0,0, 128 / QuackHack.PPM, 128 / QuackHack.PPM);
    setRegion(boxRegion);
    setOrigin(getHeight()/2, getWidth()/2);
}
项目:QuackHack    文件:Player.java   
public void definePlayer(){
    BodyDef bdef = new BodyDef();
    bdef.position.set(100 / QuackHack.PPM, 1500 / QuackHack.PPM); // Mario start position
    bdef.type = BodyDef.BodyType.DynamicBody;
    b2body = world.createBody(bdef);

    FixtureDef fdef = new FixtureDef();
    CircleShape shape = new CircleShape();
    shape.setRadius(64 / QuackHack.PPM);

    fdef.filter.categoryBits = QuackHack.MARIO_BIT;
    fdef.filter.maskBits = QuackHack.DEFAULT_BIT;
    fdef.friction = 0;
    fdef.density = 0.1f;

    fdef.shape = shape;
    b2body.createFixture(fdef);
    b2body.createFixture(fdef).setUserData(this);
}
项目:Undertailor    文件:WorldObject.java   
public WorldObject() {
    this.id = nextId++;
    this.destroyed = false;
    this.boundingQueue = new ObjectSet<>();
    this.def = new BodyDef();
    this.persistent = false;
    this.visible = true;
    this.layer = 0;

    this.def.active = true;
    this.def.awake = true;
    this.def.fixedRotation = true;
    this.def.type = BodyType.DynamicBody;

    this.groupId = -1;
    this.canCollide = true;
    this.events = new EventHelper(this);
}
项目:joe    文件:Player.java   
@Override
protected Body createBody(EntityDefinition definition) {
    BodyDef bodyDef = definition.getBodyDef();
    bodyDef.position.set(definition.getCenter());
    Body body = Level.getInstance().getPhysicsWorld().createBody(bodyDef);

    FixtureDef fixtureDef = createFixtureDef();
    body.createFixture(fixtureDef);
    fixtureDef.shape.dispose();

    body.setBullet(true);
    attachFootSensor(body, definition.getSize().x);

    Filter filter = new Filter();
    filter.categoryBits = 0x0001;
    filter.maskBits = ~Player.COLLISION_MASK;
    body.getFixtureList().get(0).setFilterData(filter);

    return body;
}
项目:M-M    文件:Bonus.java   
@Override
protected Body createBody(final Box2DService box2d) {
    final BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyType.StaticBody;
    bodyDef.fixedRotation = true;

    final PolygonShape shape = new PolygonShape();
    shape.setAsBox(Block.HALF_SIZE, Block.HALF_SIZE);
    final FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.isSensor = true;
    fixtureDef.shape = shape;
    fixtureDef.filter.categoryBits = Box2DUtil.CAT_BLOCK;
    fixtureDef.filter.maskBits = Box2DUtil.MASK_BLOCK;
    final Body body = box2d.getWorld().createBody(bodyDef);
    body.createFixture(fixtureDef);
    shape.dispose();
    return body;
}
项目:M-M    文件:Block.java   
@Override
protected Body createBody(final Box2DService box2d) {
    final BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyType.StaticBody;
    bodyDef.fixedRotation = true;

    final PolygonShape shape = new PolygonShape();
    shape.setAsBox(HALF_SIZE, HALF_SIZE);
    final FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.restitution = 1f;
    fixtureDef.friction = 0f;
    fixtureDef.shape = shape;
    fixtureDef.filter.categoryBits = Box2DUtil.CAT_BLOCK;
    fixtureDef.filter.maskBits = Box2DUtil.MASK_BLOCK;
    final Body body = box2d.getWorld().createBody(bodyDef);
    body.createFixture(fixtureDef);
    shape.dispose();
    return body;
}
项目:M-M    文件:BoundsEntity.java   
@Override
protected Body createBody(final Box2DService box2d) {
    final BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyType.StaticBody;
    bodyDef.fixedRotation = true;

    final ChainShape shape = new ChainShape();
    final float w = Box2DUtil.WIDTH * 2f / 5f, h = Box2DUtil.HEIGHT * 2f / 5f;
    shape.createLoop(new float[] { -w, -h, -w, h, w, h, w, -h });
    final FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.restitution = 0.9f;
    fixtureDef.friction = 0.2f;
    fixtureDef.shape = shape;
    fixtureDef.filter.categoryBits = Box2DUtil.CAT_BOUNDS;
    fixtureDef.filter.maskBits = Box2DUtil.MASK_BLOCK;
    final Body body = box2d.getWorld().createBody(bodyDef);
    body.createFixture(fixtureDef);
    return body;
}
项目:advio    文件:Food.java   
public Food(World world, float x, float y, int size, float toGive) {
    super(x, y);
    color = new Color((float) Math.random(), (float) Math.random(), (float) Math.random(), 1);
    outline = Advio.instance.darker(color);
    BodyDef bd = new BodyDef();
    bd.type = BodyType.KinematicBody;
    bd.position.set(x, y);
    CircleShape shape = new CircleShape();
    shape.setRadius(size);
    FixtureDef fd = new FixtureDef();
    fd.density = 0.1f;
    fd.shape = shape;
    fd.friction = 0.1f;
    // fd.filter.groupIndex = Advio.GROUP_BEINGS;
    body = world.createBody(bd);
    body.createFixture(fd).setUserData(new UserData("food").add("toGive", toGive));
    shape.dispose();
}
项目:advio    文件:Block.java   
public Block(World world, float x, float f, BodyType type, boolean invisible) {
    BodyDef bd = new BodyDef();
    bd.type = type;
    bd.position.set(x, f);
    PolygonShape shape = new PolygonShape();
    shape.setAsBox(size / 2, size / 2);
    FixtureDef fd = new FixtureDef();
    fd.density = 0.1f;
    fd.shape = shape;
    fd.friction = 0.1f;
    fd.filter.groupIndex = Advio.GROUP_DONT_COLLIDE_WITH_PLAYER;
    // fd.filter.groupIndex = Advio.GROUP_SCENERY;
    body = world.createBody(bd);
    body.createFixture(fd).setUserData(new UserData("block"));
    this.invisible = invisible;
    shape.dispose();
}
项目:advio    文件:PressurePlate.java   
public PressurePlate(Level l, World world, float x, float y, float weight, Block[] blocks) {
    super(x, y);
    this.level = l;
    BodyDef bd = new BodyDef();
    bd.type = BodyType.KinematicBody;
    bd.position.set(x, y);
    PolygonShape shape = new PolygonShape();
    shape.setAsBox(Block.size / 2, Block.size / 2);
    FixtureDef fd = new FixtureDef();
    fd.density = 0.0f;
    fd.shape = shape;
    fd.friction = 0.1f;
    fd.isSensor = true;
    this.blocks = new ArrayList<Block>(Arrays.asList(blocks));
    body = world.createBody(bd);
    body.createFixture(fd).setUserData(new UserData("plate").add("pressed", false).add("weight", weight));
    shape.dispose();
    this.world = world;
}
项目:advio    文件:Player.java   
public Player(World world, float x, float y) {
    super(x, y);
    this.world = world;
    this.graphicsSize = 10;
    color = new Color((float) Math.random(), (float) Math.random(), (float) Math.random(), 1);
    outline = Advio.instance.darker(color);
    BodyDef bd = new BodyDef();
    bd.type = BodyType.DynamicBody;
    bd.position.set(x, y);
    CircleShape shape = new CircleShape();
    shape.setRadius(50);
    FixtureDef fd = new FixtureDef();
    fd.density = 0.0f;
    fd.shape = shape;
    fd.friction = 0.1f;
    body = world.createBody(bd);
    body.createFixture(fd).setUserData(new UserData("player"));
    shape.dispose();
    // size * 2.25f
}
项目:advio    文件:AgarLogic.java   
public AgarLogic(Level l, World world, float x, float y) {
    super(x, y);
    this.level = l;
    BodyDef bd = new BodyDef();
    bd.type = BodyType.KinematicBody;
    bd.position.set(x, y);
    PolygonShape shape = new PolygonShape();
    shape.setAsBox(Block.size / 2, Block.size / 2);
    FixtureDef fd = new FixtureDef();
    fd.density = 0.0f;
    fd.shape = shape;
    fd.friction = 0.1f;
    fd.isSensor = true;
    body = world.createBody(bd);
    body.createFixture(fd).setUserData(new UserData("agariologic"));
    shape.dispose();
    this.world = world;
}
项目:advio    文件:Enemy.java   
public Enemy(World world, float x, float y, int size) {
    super(x, y);
    this.world = world;
    this.graphicsSize = 0.1f;
    color = new Color((float) Math.random(), (float) Math.random(), (float) Math.random(), 1);
    outline = Advio.instance.darker(color);
    BodyDef bd = new BodyDef();
    bd.type = BodyType.DynamicBody;
    bd.position.set(x, y);
    CircleShape shape = new CircleShape();
    shape.setRadius(size);
    FixtureDef fd = new FixtureDef();
    fd.density = 0.0f;
    fd.shape = shape;
    fd.friction = 0.1f;
    body = world.createBody(bd);
    body.createFixture(fd).setUserData(new UserData("enemy").add("body", body));
    shape.dispose();
}
项目:advio    文件:Goal.java   
public Goal(World world, float x, float y) {
    super(x, y);
    BodyDef bd = new BodyDef();
    bd.type = BodyType.KinematicBody;
    bd.position.set(x, y);
    PolygonShape shape = new PolygonShape();
    shape.setAsBox(Block.size / 2, Block.size / 2);
    FixtureDef fd = new FixtureDef();
    fd.density = 0.1f;
    fd.shape = shape;
    fd.friction = 0.1f;
    fd.isSensor = true;
    // fd.filter.groupIndex = Advio.GROUP_SCENERY;
    body = world.createBody(bd);
    body.createFixture(fd).setUserData(new UserData("goal"));
    shape.dispose();
}