Example usage for com.badlogic.gdx.utils.viewport Viewport getCamera

List of usage examples for com.badlogic.gdx.utils.viewport Viewport getCamera

Introduction

In this page you can find the example usage for com.badlogic.gdx.utils.viewport Viewport getCamera.

Prototype

public Camera getCamera() 

Source Link

Usage

From source file:com.gmail.emersonmx.tictactoe.BaseScreen.java

License:Open Source License

protected void setup() {
    Viewport viewport = new FitViewport(TicTacToe.WINDOW_WIDTH, TicTacToe.WINDOW_HEIGHT);
    OrthographicCamera camera = (OrthographicCamera) viewport.getCamera();
    camera.setToOrtho(false, TicTacToe.WINDOW_WIDTH, TicTacToe.WINDOW_HEIGHT);

    Gdx.gl.glClearColor(0, 0, 0, 1);//from   w  ww .j  ava2 s  .  com

    stage = new Stage(viewport);
    Gdx.input.setInputProcessor(stage);
}

From source file:com.jmolina.orb.elements.Element.java

License:Open Source License

/**
 * Sincroniza solo la posicion del actor con la del cuerpo
 *
 * @param viewport Viewport// ww  w .j  a  v a 2s .  c  o  m
 */
private void syncActorPosition(Viewport viewport) {
    float cameraX = viewport.getCamera().position.x;
    float cameraY = viewport.getCamera().position.y;
    float offsetX = viewport.getWorldWidth() * 0.5f;
    float offsetY = viewport.getWorldHeight() * 0.5f;
    float bodyPositionX = getBody().getPosition().x;
    float bodyPositionY = getBody().getPosition().y;
    float actorWidth = actor.getWidth();
    float actorHeight = actor.getHeight();

    float actorPositionX = getPPM() * (bodyPositionX - cameraX + offsetX) - 0.5f * actorWidth;
    float actorPositionY = getPPM() * (bodyPositionY - cameraY + offsetY) - 0.5f * actorHeight;

    actor.setPosition(actorPositionX, actorPositionY);
}

From source file:com.jmolina.orb.elements.Element.java

License:Open Source License

/**
 * Sincroniza solo la posicion del cuerpo con la del actor
 *
 * @param viewport Viewport//from  w  w w .j  av  a 2  s. c om
 */
private void syncBodyPosition(Viewport viewport) {
    float actorPositionX = actor.getX() + actor.getOriginX();
    float actorPositionY = actor.getY() + actor.getOriginY();
    float cameraX = viewport.getCamera().position.x;
    float cameraY = viewport.getCamera().position.y;
    float offsetX = 0.5f * Var.SCREEN_WIDTH;
    float offsetY = 0.5f * Var.SCREEN_HEIGHT;

    float bodyPositionX = (actorPositionX - offsetX) / getPPM() + cameraX;
    float bodyPositionY = (actorPositionY - offsetY) / getPPM() + cameraY;

    getBody().setTransform(bodyPositionX, bodyPositionY, getBody().getAngle());
}