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

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

Introduction

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

Prototype

public void translate(Vector2 vec) 

Source Link

Document

Moves the camera by the given vector.

Usage

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

/**
 * Handles all the keyDown inputs for the stage
 *
 * @param keyCode Entry from Keys enum//www. 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);
}

From source file:kyle.game.besiege.panels.PanelLocation.java

License:Open Source License

public void centerCamera() {
    OrthographicCamera camera = panel.getKingdom().getMapScreen().getCamera();
    camera.translate(
            new Vector2(location.getCenterX() - camera.position.x, location.getCenterY() - camera.position.y));
}

From source file:kyle.game.besiege.panels.PanelParty.java

License:Open Source License

public void centerCamera() {
    OrthographicCamera camera = panel.getKingdom().getMapScreen().getCamera();
    camera.translate(new Vector2(army.getCenterX() - camera.position.x, army.getCenterY() - camera.position.y));
}