Example usage for com.badlogic.gdx.graphics OrthographicCamera update

List of usage examples for com.badlogic.gdx.graphics OrthographicCamera update

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics OrthographicCamera update.

Prototype

@Override
    public void update() 

Source Link

Usage

From source file:be.ac.ucl.lfsab1509.bouboule.game.util.CameraHelper.java

License:Open Source License

public static OrthographicCamera getCamera(final float virtualWidth, final float virtualHeight) {
    float viewportWidth = virtualWidth;
    float viewportHeight = virtualHeight;
    float physicalWidth = Gdx.graphics.getWidth();
    float physicalHeight = Gdx.graphics.getHeight();
    float aspect = virtualWidth / virtualHeight;
    float aspectPhysical = physicalWidth / physicalHeight;

    // This is to maintain the aspect ratio.
    // If the virtual aspect ration does not match with the aspect ratio
    // of the hardware screen then the viewport would scaled to
    // meet the size of one dimension and other would not cover full
    // dimension/*  w  ww  . ja  v  a 2s  .  c  om*/
    // If we stretch it to meet the screen aspect ratio then textures will
    // get distorted either become fatter or elongated
    if (aspectPhysical >= aspect) {
        // Letterbox left and right.
        viewportHeight = virtualHeight;
        viewportWidth = viewportHeight * aspectPhysical;

        GlobalSettings.SHIFT_BG_WIDTH = -(virtualHeight - virtualWidth) / 2; // ok in HD and NHD

    } else {
        // Letterbox above and below.
        viewportWidth = virtualWidth;
        viewportHeight = viewportWidth * (1 / aspectPhysical);
        GlobalSettings.SCALE = viewportHeight / virtualHeight;
        Gdx.app.log("SCREEN", "SCALE : " + physicalHeight + "/" + viewportHeight);
        Gdx.app.log("SCREEN", "SCALE : " + GlobalSettings.SCALE);

        GlobalSettings.SHIFT_BG_WIDTH = -(viewportHeight - virtualWidth) / 2;
        GlobalSettings.SHIFT_BG_HEIGHT = -(viewportHeight - virtualHeight) / 2;

    }

    OrthographicCamera camera = new OrthographicCamera(viewportWidth, viewportHeight);
    camera.position.set(virtualWidth / 2, virtualHeight / 2, 0);
    camera.update();
    return camera;
}

From source file:com.alma42.mapgen.utils.CameraHelper.java

License:Apache License

public void applyTo(final OrthographicCamera camera) {
    camera.position.x = this.position.x;
    camera.position.y = this.position.y;
    camera.zoom = this.zoom;
    camera.update();
}

From source file:com.android.ringfly.common.CameraHelper.java

License:Apache License

/** Creates an orthographic camera where the "play area" has the given viewport size. The viewport will either be stretched to
 * fill the entire window, or it will be scaled to maintain the aspect ratio.
 * // www .jav  a 2  s  . c  om
 * @param isStretched true if the "play area" is stretched to fill the entire window.
 * @param virtualWidth the width of the game screen in virtual pixels.
 * @param virtualHeight the height of the game screen in virtual pixels.
 * @return the new camera. */
public static OrthographicCamera createCamera(boolean isStretched, float virtualWidth, float virtualHeight) {
    // Get the viewport size.
    Vector2 viewportSize = viewportSize(isStretched, virtualWidth, virtualHeight);
    float viewportWidth = viewportSize.x;
    float viewportHeight = viewportSize.y;

    // Create the camera, placing the origin at the bottom left of the viewport.
    OrthographicCamera camera = new OrthographicCamera(viewportWidth, viewportHeight);
    float xOrg = (viewportWidth - virtualWidth) / 2;
    float yOrg = (viewportHeight - virtualHeight) / 2;
    camera.position.set(viewportWidth / 2 - xOrg, viewportHeight / 2 - yOrg, 0);
    camera.update();
    return camera;
}

From source file:com.android.ringfly.common.CameraHelper.java

License:Apache License

public static OrthographicCamera createCamera2(ViewportMode viewportMode, float virtualWidth,
        float virtualHeight, float density) {
    // Get the viewport size.
    Vector2 viewportSize = sizeToDensity(viewportMode, virtualWidth, virtualHeight, density);
    float viewportWidth = viewportSize.x;
    float viewportHeight = viewportSize.y;

    // Create the camera, placing the origin at the bottom left of the viewport.
    OrthographicCamera camera = new OrthographicCamera(viewportWidth, viewportHeight);
    float xOrg = (viewportWidth - virtualWidth) / 2;
    float yOrg = (viewportHeight - virtualHeight) / 2;
    camera.position.set(viewportWidth / 2 - xOrg, viewportHeight / 2 - yOrg, 0);
    camera.update();
    return camera;
}

From source file:com.anhld.util.CameraHelper.java

License:Apache License

public void applyTo(OrthographicCamera camera) {
    camera.position.x = position.x;
    camera.position.y = position.y;
    camera.zoom = zoom;
    camera.update();
}

From source file:com.iLoong.launcher.Desktop3D.iLoongShapeRenderer.java

License:Open Source License

public iLoongShapeRenderer(int maxVertices) {
    if (Gdx.graphics.isGL20Available())
        renderer = new ImmediateModeRenderer20(maxVertices, false, true, 0);
    else//from w w w  .j  a va2s . c  o  m
        renderer = new ImmediateModeRenderer10(maxVertices);
    projView.setToOrtho2D(0, 0, Utils3D.getScreenWidth(), Utils3D.getScreenHeight());
    //projView.setToOrtho2D(-Utils3D.getScreenWidth()/2, -Utils3D.getScreenHeight()/2, Utils3D.getScreenWidth()/2, Utils3D.getScreenHeight()/2);
    OrthographicCamera camera = new OrthographicCamera(Utils3D.getScreenWidth(), Utils3D.getScreenHeight());
    camera.position.set(Utils3D.getScreenWidth() / 2, Utils3D.getScreenHeight() / 2, 0);
    camera.update();
    setProjectionMatrix(camera.combined);
}

From source file:com.kotcrab.vis.runtime.system.CameraManager.java

License:Apache License

private CameraSet createCamera(SceneViewport viewportType, float width, float height, float pixelsPerUnit) {
    OrthographicCamera camera = new OrthographicCamera(width, height);
    camera.position.x = width / 2;/*from w  ww  .  j  av  a2s  .  c  om*/
    camera.position.y = height / 2;
    camera.update();

    Viewport viewport = null;

    switch (viewportType) {
    case STRETCH:
        viewport = new StretchViewport(width, height, camera);
        break;
    case FIT:
        viewport = new FitViewport(width, height, camera);
        break;
    case FILL:
        viewport = new FillViewport(width, height, camera);
        break;
    case SCREEN:
        viewport = new ScreenViewport(camera);
        ((ScreenViewport) viewport).setUnitsPerPixel(1f / pixelsPerUnit);
        break;
    case EXTEND:
        viewport = new ExtendViewport(width, height, camera);
        break;
    }

    return new CameraSet(camera, viewport);
}

From source file:com.majalis.screens.CreditsScreen.java

License:Creative Commons License

@Override
public void render(float delta) {
    super.render(delta);
    OrthographicCamera camera = (OrthographicCamera) getCamera();
    batch.setTransformMatrix(camera.view);
    camera.update();
    batch.begin();/*from   w ww .  ja v a2 s . c o  m*/
    font.setColor(Color.BLACK);
    font.draw(batch, credits, 1100, 1300);
    batch.end();

    if (Gdx.input.isKeyJustPressed(Keys.ESCAPE)) {
        exitScreen();
    }
}

From source file:com.strategames.catchdastars.screens.editor.LevelEditorScreen.java

License:Open Source License

/**
 * Positions camera to make room for menu
 *///www  .j  av a  2 s  .  c om
private void zoomCamera(OrthographicCamera camera) {
    camera.position.set(camera.viewportWidth / 2f, camera.viewportHeight / 2f, 0f);
    this.cameraZoomInitial = camera.zoom;

    Vector2 maxObjectSize = getMaxObjectSize();
    //Add screenborder Wall as this is placed halfway the actual screenborder
    maxObjectSize.x += 0.6 * Wall.WIDTH;
    maxObjectSize.y += 0.6 * Wall.HEIGHT;

    boolean screenOK = false;
    while (!screenOK) {
        Vector3 screenSize = new Vector3(0f, 0f, 0f);
        camera.unproject(screenSize);

        /**
         * We always set menu at the right as on Android the action bar will
         * trigger when trying to pick a game object
         */
        if (Math.abs(screenSize.x) > maxObjectSize.x) {
            screenOK = true;
        } else if (camera.zoom > 3) {
            screenOK = true;
            //Print error
        } else {
            camera.zoom += 0.02;
            camera.update();
        }
    }
}

From source file:com.wotf.game.GameStage.java

/**
 * Handles all the keyDown inputs for the stage
 *
 * @param keyCode Entry from Keys enum//from  w  ww.ja v  a  2 s  . c  o  m
 * @return True if the key was handled
 */
@Override
public boolean keyDown(int keyCode) {

    OrthographicCamera cam = (OrthographicCamera) getCamera();

    // Always allow these controls (camera controls)
    switch (keyCode) {
    // Camera controls (position)
    case Keys.NUMPAD_2:
        cam.translate(new Vector2(0, -50f));
        focusedActor = null;
        break;
    case Keys.NUMPAD_4:
        cam.translate(new Vector2(-50f, 0));
        focusedActor = null;
        break;
    case Keys.NUMPAD_8:
        cam.translate(new Vector2(0, 50f));
        focusedActor = null;
        break;
    case Keys.NUMPAD_6:
        cam.translate(new Vector2(50f, 0));
        focusedActor = null;
        break;
    // Camera controls (zoom)
    case Keys.PLUS:
        cam.zoom -= 0.05f;
        break;
    case Keys.MINUS:
        cam.zoom += 0.05f;
        break;
    case Keys.ENTER:
        cam.zoom = 1;
        break;
    default:
        break;
    }

    // Only allow these controls for the current playing player
    if (game.getPlayingPlayer().getId() == game.getActiveTeam().getPlayer().getId()) {
        switch (keyCode) {
        // Unit selection
        case Keys.TAB:
            if (game.getTurnLogic().getState() == TurnState.PLAYING) {
                NetworkMessage switchUnitMsg = new NetworkMessage(Command.SWITCHUNIT);
                networkingUtil.sendToHost(switchUnitMsg);
            }
            break;
        // Debug key for killing current unit
        case Keys.G:
            game.getActiveTeam().getActiveUnit().decreaseHealth(100);
            game.getTurnLogic().endTurn();
            break;
        case Keys.F4:
            showDebug = !showDebug;
            break;
        case Keys.RIGHT:
            if (game.getActiveTeam().getActiveUnit() != null) {
                NetworkMessage moveMsg = new NetworkMessage(Command.MOVE);
                moveMsg.addParameter("direction", "right");
                networkingUtil.sendToHost(moveMsg);
            }
            break;
        case Keys.LEFT:
            if (game.getActiveTeam().getActiveUnit() != null) {
                NetworkMessage moveMsg = new NetworkMessage(Command.MOVE);
                moveMsg.addParameter("direction", "left");
                networkingUtil.sendToHost(moveMsg);
            }
            break;
        case Keys.NUM_0:
            sendSelectWeapon(0);
            break;
        case Keys.NUM_1:
            sendSelectWeapon(1);
            break;
        case Keys.NUM_2:
            sendSelectWeapon(2);
            break;
        case Keys.NUM_3:
            sendSelectWeapon(3);
            break;
        case Keys.NUM_4:
            sendSelectWeapon(4);
            break;
        }
    }

    clampCamera();
    cam.update();

    return super.keyDown(keyCode);
}