Example usage for com.badlogic.gdx.physics.box2d Body getLocalCenter

List of usage examples for com.badlogic.gdx.physics.box2d Body getLocalCenter

Introduction

In this page you can find the example usage for com.badlogic.gdx.physics.box2d Body getLocalCenter.

Prototype

public Vector2 getLocalCenter() 

Source Link

Usage

From source file:com.agateau.pixelwheels.bonus.Mine.java

License:Open Source License

private void initJoint() {
    Body vehicleBody = mOwner.getVehicle().getBody();
    mJointDef.bodyA = mOwner.getVehicle().getBody();
    mJointDef.bodyB = mBody;//from  w w w.jav a2 s .  c o m
    mJointDef.localAnchorA.set(vehicleBody.getLocalCenter().add(-mOwner.getVehicle().getWidth(), 0));
    mJointDef.localAnchorB.set(mBody.getLocalCenter());
    mJoint = mGameWorld.getBox2DWorld().createJoint(mJointDef);
}

From source file:com.agateau.pixelwheels.bonus.Missile.java

License:Open Source License

private void initJoint() {
    Vehicle vehicle = mShooter.getVehicle();
    Body vehicleBody = vehicle.getBody();
    mJointDef.bodyA = vehicleBody;//from   w w  w.  j  av a 2s .  com
    mJointDef.bodyB = mBody;
    mJointDef.localAnchorA.set(vehicleBody.getLocalCenter());
    mJointDef.localAnchorB.set(mBody.getLocalCenter());
    mJoint = mGameWorld.getBox2DWorld().createJoint(mJointDef);
}

From source file:com.strategames.engine.gameobject.types.Balloon.java

License:Open Source License

@Override
protected void setupBody(Body body) {

    /**//from  w  ww . jav a2  s .  c  o m
     * TODO do we really need a separate loader for each object? Replace with static?
     */
    BodyEditorLoader loader = new BodyEditorLoader(Gdx.files.internal("fixtures/balloon.json"));
    loader.setupVertices("Balloon", WIDTH);

    //Balloon body
    body.setAngularDamping(1f);
    body.setLinearDamping(1f);

    FixtureDef fixtureBalloon = new FixtureDef();
    fixtureBalloon.density = 0.1786f; // Helium density 0.1786 g/l == 0.1786 kg/m3
    fixtureBalloon.friction = 0.6f;
    fixtureBalloon.restitution = 0.4f; // Make it bounce a little bit
    loader.attachFixture(body, "Balloon", 0, fixtureBalloon);

    this.upwardLiftPosition = body.getLocalCenter();
    this.upwardLiftPosition.y += 0.1f;

    this.upwardLift = -body.getMass() * this.liftFactor;
}

From source file:Helper.WorldUtils.java

public static Body createPinguin(World world) {
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyDef.BodyType.DynamicBody;
    bodyDef.position.set(new Vector2(Constants.RUNNER_X, Constants.RUNNER_Y));
    Body body = world.createBody(bodyDef);
    body.setGravityScale(Constants.RUNNER_GRAVITY_SCALE);
    body.setFixedRotation(false);//from w  w  w  . j  a v  a  2 s.  c  om
    PolygonShape box = new PolygonShape();
    box.setAsBox(Constants.RUNNER_WIDTH / 2, Constants.RUNNER_HEIGHT / 2, body.getLocalCenter(), 0);
    FixtureDef fixtureDef = new FixtureDef();
    fixtureDef.shape = box;
    fixtureDef.density = 0.0f;
    fixtureDef.friction = BuffsInfo.getFrictionBuff().getPower();
    fixtureDef.restitution = 0.35f;
    body.createFixture(fixtureDef);
    //body.resetMassData();
    body.getFixtureList().get(0).setUserData("PINGUIN");
    box.dispose();
    return body;
}

From source file:org.matheusdev.ror.view.EntityView.java

License:Open Source License

public void draw(SpriteBatch batch, Entity e, Sprite sprite, float width, float xoffset, float yoffset) {
    Body body = e.getBody();
    // Super-Duper important Box2D-Magic code:
    // This should be / is in almost every Box2D project
    // It takes the Body and the associated sprite and
    // renders the sprite properly, using the body's
    // position, rotation and origin.
    final float worldToSprite = sprite.getWidth() / width;
    final float spriteToWorld = width / sprite.getWidth();
    // Get body position:
    final float bodyX = e.getX();
    final float bodyY = e.getY();
    // Get body center:
    final Vector2 center = body.getLocalCenter();
    final Vector2 massCenter = body.getMassData().center;
    center.sub(massCenter).add(xoffset, yoffset);
    // Compute sprite-space center:
    final Vector2 spriteCenter = new Vector2(sprite.getWidth() / 2, sprite.getHeight() / 2)
            .sub((center.cpy().scl(worldToSprite)));
    // Upload to sprite:
    sprite.setScale(1f * spriteToWorld);
    sprite.setRotation(e.getRotation() * MathUtils.radiansToDegrees);
    sprite.setOrigin(spriteCenter.x, spriteCenter.y);
    sprite.setPosition(bodyX - spriteCenter.x, bodyY - spriteCenter.y);
    // Draw Sprite:
    sprite.draw(batch);//  w w  w .  j a  v a2s .  co m
}