Search in sources :

Example 46 with OrthographicCamera

use of com.badlogic.gdx.graphics.OrthographicCamera in project libgdx by libgdx.

the class PolygonSpriteTest method create.

@Override
public void create() {
    texture = new Texture(Gdx.files.internal("data/tree.png"));
    PolygonRegionLoader loader = new PolygonRegionLoader();
    region = loader.load(new TextureRegion(texture), Gdx.files.internal("data/tree.psh"));
    renderer = new ShapeRenderer();
    camera = new OrthographicCamera(480, 320);
    camera.position.x = 240;
    camera.position.y = 160;
    camera.update();
    batch = new PolygonSpriteBatch();
    for (int i = 0; i < 50; i++) {
        PolygonSprite sprite = new PolygonSprite(region);
        sprite.setPosition(MathUtils.random(-30, 440), MathUtils.random(-30, 290));
        sprite.setColor(MathUtils.random(), MathUtils.random(), MathUtils.random(), 1.0f);
        sprite.setScale(MathUtils.random(0.5f, 1.5f), MathUtils.random(0.5f, 1.5f));
        sprites.add(sprite);
    }
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) PolygonRegionLoader(com.badlogic.gdx.graphics.g2d.PolygonRegionLoader) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) PolygonSprite(com.badlogic.gdx.graphics.g2d.PolygonSprite) Texture(com.badlogic.gdx.graphics.Texture) PolygonSpriteBatch(com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer)

Example 47 with OrthographicCamera

use of com.badlogic.gdx.graphics.OrthographicCamera 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)

Example 48 with OrthographicCamera

use of com.badlogic.gdx.graphics.OrthographicCamera in project Alkahest-Coffee by AlkahestDev.

the class CoffeeServer method create.

@Override
public void create() {
    batch = new SpriteBatch();
    camView = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    camView.translate(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);
    camView.update();
    batch.setProjectionMatrix(camView.combined);
    manager = new AssetManager();
    shapeRenderer = new ShapeRenderer();
    loadingMenu = new LoadingMenu(fonts, manager, camView);
    readyLoadingBackground();
    manager.load("tuzki.png", Texture.class);
    manager.load("volcano-30238.png", Texture.class);
    manager.load("4k-image-santiago.jpg", Texture.class);
    manager.load("4914003-galaxy-wallpaper-png.png", Texture.class);
    manager.load("pixmapTest.png", Texture.class);
    manager.load("pixmapVisual.png", Texture.class);
    BitmapFont dagger30 = new BitmapFont(Gdx.files.internal("fonts/dagger30.fnt"));
    dagger30.getData().markupEnabled = true;
    serverInfo = new ServerInfoMenu(fonts, manager, camView);
    serverRunningMenu = new ServerRunningGameMenu(fonts, manager, camView);
    fonts.add(new BitmapFontCache(dagger30));
}
Also used : AssetManager(com.badlogic.gdx.assets.AssetManager) ServerInfoMenu(me.dumfing.menus.ServerInfoMenu) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) ServerRunningGameMenu(me.dumfing.menus.ServerRunningGameMenu) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer) BitmapFontCache(com.badlogic.gdx.graphics.g2d.BitmapFontCache) LoadingMenu(me.dumfing.menus.LoadingMenu)

Example 49 with OrthographicCamera

use of com.badlogic.gdx.graphics.OrthographicCamera in project RubeLoader by tescott.

the class RubeLoaderTest method create.

@Override
public void create() {
    float w = Gdx.graphics.getWidth();
    float h = Gdx.graphics.getHeight();
    Gdx.input.setInputProcessor(this);
    mB2Controllers = new Array<B2Controller>();
    mCamPos = new Vector3();
    mCurrentPos = new Vector3();
    camera = new OrthographicCamera(100, 100 * h / w);
    camera.position.set(50, 50, 0);
    camera.zoom = 1.8f;
    camera.update();
    loader = new RubeSceneLoader();
    scene = loader.loadScene(Gdx.files.internal("data/palmcontrollers.json"));
    debugRender = new Box2DDebugRenderer();
    batch = new SpriteBatch();
    polygonBatch = new PolygonSpriteBatch();
    textureMap = new HashMap<String, Texture>();
    textureRegionMap = new HashMap<Texture, TextureRegion>();
    createSpatialsFromRubeImages(scene);
    createPolySpatialsFromRubeFixtures(scene);
    mWorld = scene.getWorld();
    // configure simulation settings
    mVelocityIter = scene.velocityIterations;
    mPositionIter = scene.positionIterations;
    if (scene.stepsPerSecond != 0) {
        mSecondsPerStep = 1f / scene.stepsPerSecond;
    }
    mWorld.setContactListener(this);
    //
    // example of custom property handling
    //
    Array<Body> bodies = scene.getBodies();
    if ((bodies != null) && (bodies.size > 0)) {
        for (int i = 0; i < bodies.size; i++) {
            Body body = bodies.get(i);
            String gameInfo = (String) scene.getCustom(body, "GameInfo", null);
            if (gameInfo != null) {
                System.out.println("GameInfo custom property: " + gameInfo);
            }
        }
    }
    // Instantiate any controllers that are in the scene
    Array<Fixture> fixtures = scene.getFixtures();
    if ((fixtures != null) && (fixtures.size > 0)) {
        for (int i = 0; i < fixtures.size; i++) {
            Fixture fixture = fixtures.get(i);
            int controllerType = (Integer) scene.getCustom(fixture, "ControllerType", 0);
            switch(controllerType) {
                case B2Controller.BUOYANCY_CONTROLLER:
                    // only allow polygon buoyancy controllers for now..
                    if (fixture.getShape().getType() == Shape.Type.Polygon) {
                        float bodyHeight = fixture.getBody().getPosition().y;
                        // B2BuoyancyController b2c = new B2BuoyancyController();
                        // need to calculate the fluid surface height for the buoyancy controller
                        PolygonShape shape = (PolygonShape) fixture.getShape();
                        shape.getVertex(0, mTmp);
                        // initialize the height, transforming to 'world'
                        float maxHeight = mTmp.y + bodyHeight;
                        // find the maxHeight
                        for (int j = 1; j < shape.getVertexCount(); j++) {
                            shape.getVertex(j, mTmp);
                            // transform to world coordinates
                            maxHeight = Math.max(maxHeight, mTmp.y + bodyHeight);
                        }
                        B2BuoyancyController b2c = new B2BuoyancyController(// assume up
                        B2BuoyancyController.DEFAULT_SURFACE_NORMAL, (Vector2) scene.getCustom(fixture, "ControllerVelocity", B2BuoyancyController.DEFAULT_FLUID_VELOCITY), mWorld.getGravity(), maxHeight, fixture.getDensity(), (Float) scene.getCustom(fixture, "LinearDrag", B2BuoyancyController.DEFAULT_LINEAR_DRAG), (Float) scene.getCustom(fixture, "AngularDrag", B2BuoyancyController.DEFAULT_ANGULAR_DRAG));
                        // reference back to the controller from the fixture (see
                        fixture.setUserData(b2c);
                        // beginContact/endContact)
                        // add it to the list so it can be stepped later
                        mB2Controllers.add(b2c);
                    }
                    break;
                case B2Controller.GRAVITY_CONTROLLER:
                    {
                        B2GravityController b2c = new B2GravityController();
                        b2c = new B2GravityController((Vector2) scene.getCustom(fixture, "ControllerVelocity", B2GravityController.DEFAULT_GRAVITY));
                        fixture.setUserData(b2c);
                        mB2Controllers.add(b2c);
                    }
                    break;
            }
        }
    }
    scene.printStats();
    // no longer need any scene references
    scene.clear();
}
Also used : PolygonShape(com.badlogic.gdx.physics.box2d.PolygonShape) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) B2BuoyancyController(com.gushikustudios.box2d.controllers.B2BuoyancyController) Vector3(com.badlogic.gdx.math.Vector3) B2Controller(com.gushikustudios.box2d.controllers.B2Controller) PolygonSpriteBatch(com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) PolygonSpriteBatch(com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch) Texture(com.badlogic.gdx.graphics.Texture) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Box2DDebugRenderer(com.badlogic.gdx.physics.box2d.Box2DDebugRenderer) RubeSceneLoader(com.gushikustudios.rube.loader.RubeSceneLoader) B2GravityController(com.gushikustudios.box2d.controllers.B2GravityController) Fixture(com.badlogic.gdx.physics.box2d.Fixture) Body(com.badlogic.gdx.physics.box2d.Body)

Example 50 with OrthographicCamera

use of com.badlogic.gdx.graphics.OrthographicCamera in project nhglib by VoidZombie.

the class CameraComponentJson method parse.

@Override
public void parse(JsonValue jsonValue) {
    CameraComponent cameraComponent = entities.createComponent(entity, CameraComponent.class);
    Camera camera;
    float nearPlane = jsonValue.getFloat("nearPlane");
    float farPlane = jsonValue.getFloat("farPlane");
    CameraComponent.Type type = CameraComponent.Type.fromString(jsonValue.getString("cameraType"));
    switch(type) {
        default:
        case PERSPECTIVE:
            float fieldOfView = jsonValue.getFloat("fieldOfView");
            camera = new PerspectiveCamera(fieldOfView, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
            break;
        case ORTHOGRAPHIC:
            camera = new OrthographicCamera();
            break;
    }
    camera.near = nearPlane;
    camera.far = farPlane;
    cameraComponent.camera = camera;
    cameraComponent.type = type;
    output = cameraComponent;
}
Also used : OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) CameraComponent(io.github.voidzombie.nhglib.runtime.ecs.components.graphics.CameraComponent) Camera(com.badlogic.gdx.graphics.Camera) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera)

Aggregations

OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)50 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)32 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)21 Texture (com.badlogic.gdx.graphics.Texture)20 OrthoCamController (com.badlogic.gdx.tests.utils.OrthoCamController)15 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)10 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)10 OrthogonalTiledMapRenderer (com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer)7 TmxMapLoader (com.badlogic.gdx.maps.tiled.TmxMapLoader)6 Box2DDebugRenderer (com.badlogic.gdx.physics.box2d.Box2DDebugRenderer)6 AssetManager (com.badlogic.gdx.assets.AssetManager)5 InternalFileHandleResolver (com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver)4 Pixmap (com.badlogic.gdx.graphics.Pixmap)4 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)3 PolygonSpriteBatch (com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch)3 Vector2 (com.badlogic.gdx.math.Vector2)3 World (com.badlogic.gdx.physics.box2d.World)3 Stage (com.badlogic.gdx.scenes.scene2d.Stage)3 InputAdapter (com.badlogic.gdx.InputAdapter)2 InputMultiplexer (com.badlogic.gdx.InputMultiplexer)2