Search in sources :

Example 1 with Box2DDebugRenderer

use of com.badlogic.gdx.physics.box2d.Box2DDebugRenderer in project libgdx by libgdx.

the class Box2DCharacterControllerTest method create.

@Override
public void create() {
    world = new World(new Vector2(0, -40), true);
    renderer = new Box2DDebugRenderer();
    cam = new OrthographicCamera(28, 20);
    createWorld();
    Gdx.input.setInputProcessor(this);
    batch = new SpriteBatch();
    font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
}
Also used : Box2DDebugRenderer(com.badlogic.gdx.physics.box2d.Box2DDebugRenderer) Vector2(com.badlogic.gdx.math.Vector2) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) World(com.badlogic.gdx.physics.box2d.World) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Example 2 with Box2DDebugRenderer

use of com.badlogic.gdx.physics.box2d.Box2DDebugRenderer in project libgdx by libgdx.

the class Box2DTest method create.

@Override
public void create() {
    // setup the camera. In Box2D we operate on a
    // meter scale, pixels won't do it. So we use
    // an orthographic camera with a viewport of
    // 48 meters in width and 32 meters in height.
    // We also position the camera so that it
    // looks at (0,16) (that's where the middle of the
    // screen will be located).
    camera = new OrthographicCamera(48, 32);
    camera.position.set(0, 16, 0);
    // next we setup the immediate mode renderer
    renderer = new ShapeRenderer();
    // next we create the box2d debug renderer
    debugRenderer = new Box2DDebugRenderer();
    // next we create a SpriteBatch and a font
    batch = new SpriteBatch();
    font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
    font.setColor(Color.RED);
    textureRegion = new TextureRegion(new Texture(Gdx.files.internal("data/badlogicsmall.jpg")));
    // next we create out physics world.
    createPhysicsWorld();
    // register ourselfs as an InputProcessor
    Gdx.input.setInputProcessor(this);
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Box2DDebugRenderer(com.badlogic.gdx.physics.box2d.Box2DDebugRenderer) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer)

Example 3 with Box2DDebugRenderer

use of com.badlogic.gdx.physics.box2d.Box2DDebugRenderer in project libgdx by libgdx.

the class Box2DTest method create.

@Override
public void create() {
    // setup the camera. In Box2D we operate on a
    // meter scale, pixels won't do it. So we use
    // an orthographic camera with a viewport of
    // 48 meters in width and 32 meters in height.
    // We also position the camera so that it
    // looks at (0,16) (that's where the middle of the
    // screen will be located).
    camera = new OrthographicCamera(48, 32);
    camera.position.set(0, 15, 0);
    // create the debug renderer
    renderer = new Box2DDebugRenderer();
    // create the world
    world = new World(new Vector2(0, -10), true);
    // we also need an invisible zero size ground body
    // to which we can connect the mouse joint
    BodyDef bodyDef = new BodyDef();
    groundBody = world.createBody(bodyDef);
    // call abstract method to populate the world
    createWorld(world);
    batch = new SpriteBatch();
    font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
}
Also used : Box2DDebugRenderer(com.badlogic.gdx.physics.box2d.Box2DDebugRenderer) Vector2(com.badlogic.gdx.math.Vector2) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) World(com.badlogic.gdx.physics.box2d.World) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) BodyDef(com.badlogic.gdx.physics.box2d.BodyDef) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Example 4 with Box2DDebugRenderer

use of com.badlogic.gdx.physics.box2d.Box2DDebugRenderer in project libgdx by libgdx.

the class KinematicBodyTest method create.

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));
}
Also used : Box2DDebugRenderer(com.badlogic.gdx.physics.box2d.Box2DDebugRenderer) Vector2(com.badlogic.gdx.math.Vector2) CircleShape(com.badlogic.gdx.physics.box2d.CircleShape) MassData(com.badlogic.gdx.physics.box2d.MassData) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) World(com.badlogic.gdx.physics.box2d.World) Body(com.badlogic.gdx.physics.box2d.Body) BodyDef(com.badlogic.gdx.physics.box2d.BodyDef)

Example 5 with Box2DDebugRenderer

use of com.badlogic.gdx.physics.box2d.Box2DDebugRenderer in project libgdx-inGameConsole by StrongJoshua.

the class Box2DTest method create.

@Override
public void create() {
    float w = Gdx.graphics.getWidth();
    w *= 2;
    float h = Gdx.graphics.getHeight();
    h *= 2;
    ratio = h / w;
    Gdx.app.getGraphics().setWindowedMode((int) w, (int) h);
    mX = (float) WIDTH / w;
    mY = (float) HEIGHT / h;
    Box2D.init();
    world = new World(new Vector2(0, -9.81f), true);
    batch = new SpriteBatch();
    sprites = new Sprite[250];
    bodies = new Body[sprites.length];
    float k, j;
    for (int i = 0; i < sprites.length; i++) {
        if (i < 50) {
            k = 0;
            j = 1;
        } else if (i < 100) {
            k = 50 * sprites[i - 1].getWidth() + sprites[i - 1].getWidth() / 2;
            j = 2;
        } else if (i < 150) {
            k = 100 * sprites[i - 1].getWidth() + sprites[i - 1].getWidth() / 2;
            j = 3;
        } else if (i < 200) {
            k = 150 * sprites[i - 1].getWidth() + sprites[i - 1].getWidth() / 2;
            j = 4;
        } else {
            k = 200 * sprites[i - 1].getWidth() + sprites[i - 1].getWidth() / 2;
            j = 5;
        }
        sprites[i] = new Sprite(new Texture(Gdx.files.classpath("tests/badlogic.jpg")));
        sprites[i].setSize(2, 2);
        sprites[i].setOriginCenter();
        BodyDef bdef = new BodyDef();
        bdef.type = BodyDef.BodyType.DynamicBody;
        bdef.position.set(i * sprites[i].getWidth() + sprites[i].getWidth() / 2 - k, 15 * j);
        bodies[i] = world.createBody(bdef);
        PolygonShape poly = new PolygonShape();
        poly.setAsBox(sprites[i].getWidth() / 2, sprites[i].getHeight() / 2);
        FixtureDef fdef = new FixtureDef();
        fdef.shape = poly;
        fdef.restitution = .2f;
        fdef.density = 1f;
        bodies[i].createFixture(fdef);
        poly.dispose();
    }
    BodyDef bdef = new BodyDef();
    bdef.type = BodyDef.BodyType.StaticBody;
    bdef.position.set(WIDTH / 2, -5);
    Body b = world.createBody(bdef);
    PolygonShape poly = new PolygonShape();
    poly.setAsBox(50, 5);
    b.createFixture(poly, 0);
    bdef = new BodyDef();
    bdef.type = BodyDef.BodyType.StaticBody;
    bdef.position.set(-5, HEIGHT / 2);
    b = world.createBody(bdef);
    poly = new PolygonShape();
    poly.setAsBox(5, 50);
    b.createFixture(poly, 0);
    bdef = new BodyDef();
    bdef.type = BodyDef.BodyType.StaticBody;
    bdef.position.set(WIDTH + 5, (HEIGHT * ratio) / 2);
    b = world.createBody(bdef);
    poly = new PolygonShape();
    poly.setAsBox(5, 50);
    b.createFixture(poly, 0);
    bdef = new BodyDef();
    bdef.type = BodyDef.BodyType.StaticBody;
    bdef.position.set(WIDTH / 2, HEIGHT * ratio + 5);
    b = world.createBody(bdef);
    poly = new PolygonShape();
    poly.setAsBox(50, 5);
    b.createFixture(poly, 0);
    poly.dispose();
    c = new OrthographicCamera(WIDTH, HEIGHT * ratio);
    c.position.set(c.viewportWidth / 2, c.viewportHeight / 2, 0);
    c.update();
    batch.setProjectionMatrix(c.combined);
    debugRenderer = new Box2DDebugRenderer();
    console = new GUIConsole(false);
    cExec = new MyCommandExecutor();
    console.setCommandExecutor(cExec);
    // set to 'Z' to demonstrate that it works with binds other than the
    // default
    console.setDisplayKeyID(Input.Keys.Z);
    console.setVisible(true);
    // test multiple resets with nested multiplexers
    InputMultiplexer im1 = new InputMultiplexer();
    im1.addProcessor(new Stage());
    im1.addProcessor(new Stage());
    InputMultiplexer im2 = new InputMultiplexer();
    im2.addProcessor(new Stage());
    im2.addProcessor(new Stage());
    im1.addProcessor(im2);
    Gdx.input.setInputProcessor(im1);
    console.setMaxEntries(16);
    console.resetInputProcessing();
    // console already present, logged to consoles
    console.resetInputProcessing();
    console.setSizePercent(100, 33);
    console.setPositionPercent(0, 67);
}
Also used : GUIConsole(com.strongjoshua.console.GUIConsole) PolygonShape(com.badlogic.gdx.physics.box2d.PolygonShape) Sprite(com.badlogic.gdx.graphics.g2d.Sprite) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) World(com.badlogic.gdx.physics.box2d.World) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture) InputMultiplexer(com.badlogic.gdx.InputMultiplexer) Box2DDebugRenderer(com.badlogic.gdx.physics.box2d.Box2DDebugRenderer) Vector2(com.badlogic.gdx.math.Vector2) Stage(com.badlogic.gdx.scenes.scene2d.Stage) BodyDef(com.badlogic.gdx.physics.box2d.BodyDef) Body(com.badlogic.gdx.physics.box2d.Body) FixtureDef(com.badlogic.gdx.physics.box2d.FixtureDef)

Aggregations

OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)6 Box2DDebugRenderer (com.badlogic.gdx.physics.box2d.Box2DDebugRenderer)6 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)5 Vector2 (com.badlogic.gdx.math.Vector2)4 World (com.badlogic.gdx.physics.box2d.World)4 Texture (com.badlogic.gdx.graphics.Texture)3 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)3 Body (com.badlogic.gdx.physics.box2d.Body)3 BodyDef (com.badlogic.gdx.physics.box2d.BodyDef)3 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)2 PolygonShape (com.badlogic.gdx.physics.box2d.PolygonShape)2 InputMultiplexer (com.badlogic.gdx.InputMultiplexer)1 PolygonSpriteBatch (com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch)1 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)1 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)1 Vector3 (com.badlogic.gdx.math.Vector3)1 CircleShape (com.badlogic.gdx.physics.box2d.CircleShape)1 Fixture (com.badlogic.gdx.physics.box2d.Fixture)1 FixtureDef (com.badlogic.gdx.physics.box2d.FixtureDef)1 MassData (com.badlogic.gdx.physics.box2d.MassData)1