Example usage for com.badlogic.gdx.scenes.scene2d Stage screenToStageCoordinates

List of usage examples for com.badlogic.gdx.scenes.scene2d Stage screenToStageCoordinates

Introduction

In this page you can find the example usage for com.badlogic.gdx.scenes.scene2d Stage screenToStageCoordinates.

Prototype

public Vector2 screenToStageCoordinates(Vector2 screenCoords) 

Source Link

Document

Transforms the screen coordinates to stage coordinates.

Usage

From source file:com.blastedstudios.gdxworld.util.ui.Scene2DUtils.java

License:Apache License

/** @param stage the Stage which coordinate system should be used
 *  @param pointer the pointer which position to return
 *  @return the position of the given pointer in stage coordinates */
public static Vector2 pointerPosition(Stage stage, int pointer) {
    tmp.set(Gdx.input.getX(pointer), Gdx.input.getY(pointer));
    stage.screenToStageCoordinates(tmp);
    return tmp;/*from   w  w  w  .  j ava  2  s .c o  m*/
}

From source file:com.strategames.ui.helpers.Screen.java

License:Open Source License

/**
 * Returns the full screen coordinates for the given stage
 * @param stage stage in which the coordinates should be calculated for full screen
 * @param start vector that will hold the left-bottom corner in stage coordinates
 * @param end vector that will hold the top-right corner in stage coordinates
 *///from   w ww .j a va 2 s .  c  o m
static public void getFullScreenCoordinates(Stage stage, Vector2 start, Vector2 end) {
    start.x = -1;
    start.y = Gdx.graphics.getHeight() + 1;
    end.x = Gdx.graphics.getWidth() + 1;
    end.y = -1;

    stage.screenToStageCoordinates(start);
    stage.screenToStageCoordinates(end);

    end.x += Math.abs(start.x);
    end.y += Math.abs(start.y);
}

From source file:es.eucm.ead.engine.debugger.CommandInterpreter.java

License:Open Source License

public String interpret(String command) {
    String result = "Invalid command.";
    try {/*from w  ww . j  av a 2s.co  m*/
        command = command.trim();
        if (command.equals(Commands.NOTIFY)) {
            waiting--;
            result = "Notified.";
        } else if (command.equals(Commands.WAIT)) {
            waiting++;
            result = "Waiting.";
        } else if (command.equals(Commands.PASS)) {
            result = "OK.";
        } else if (command.equals("scene")) {
            result = game.getGUI().getScene().getElement().getId();
        } else if (command.startsWith(Commands.GO_CHAPTER)) {
            String[] parts = command.split(" ");
            game.addEffect(new ChangeChapterEf(parts[1]));
        } else if (command.equals(Commands.CHAPTER)) {
            result = gameLoader.getCurrentChapterId();
        } else if (command.startsWith(Commands.GO)) {
            String[] parts = command.split(" ");
            game.addEffect(new ChangeSceneEf(new BasicElement(parts[1])));
            result = "OK.";
        } else if (command.startsWith(Commands.LIST)) {
            String[] parts = command.split(" ");
            if (parts[1].equals("scenes")) {
                Manifest m = gameLoader.loadManifest();
                result = m.getChaptersScenes().get(gameLoader.getCurrentChapterId()).toString();
            } else if (parts[1].equals("chapters")) {
                Manifest m = gameLoader.loadManifest();
                result = m.getChaptersScenes().keySet().toString();
            } else if (parts[1].equals("elements")) {
                SceneGO scene = game.getGUI().getScene();
                result = addGroup(scene);
            } else if (parts[1].equals("variables")) {
                Map<String, Object> vars = game.getGameState().getElementVars(parts[2]);
                result = vars == null ? "[]" : vars.toString();
            }
        } else if (command.startsWith(Commands.LOAD)) {
            String[] parts = command.split(" ");
            result = runCommands(parts[1]);
        } else if (command.startsWith(Commands.SET)) {
            String[] parts = command.split(" ");
            String[] field = parts[1].split("\\.");
            Object value = parseValue(parts[2]);
            game.getGameState().setValue(field[0], field[1], value);
            result = "OK.";
        } else if (command.startsWith(Commands.GET)) {
            String[] parts = command.split(" ");
            String[] field = parts[1].split("\\.");
            result = game.getGameState().getValue(field[0], field[1], null) + "";
        } else if (command.startsWith(Commands.PING)) {
            String[] parts = command.split(" ");
            ping(parts[1]);
            result = "OK.";
        } else if (command.startsWith(Commands.SOUND)) {
            game.addEffect(new ToggleSoundEf());
            result = "OK.";
        } else if (command.startsWith(Commands.WATCHING)) {
            String[] parts = command.split(" ");
            result = game.getGameState().countWatchers(parts[1]) + " watchers.";
        } else if (command.startsWith(Commands.WHOIS)) {
            result = game.getGUI().getGameObjectUnderPointer() + "";
        } else if (command.startsWith("is")) {
            String[] parts = command.split(" ");
            result = game.getGUI().getScene().findActor(parts[1]) == null ? "false" : "true";
        } else if (command.startsWith(Commands.MOVE)) {
            String[] parts = command.split(" ");
            int x = Integer.parseInt(parts[1]);
            int y = Integer.parseInt(parts[2]);
            Gdx.input.setCursorPosition(x, Gdx.graphics.getHeight() - y);
            result = "OK.";
        } else if (command.startsWith(Commands.WHERE)) {
            result = "(" + Gdx.input.getX() + ", " + (Gdx.graphics.getHeight() - Gdx.input.getY()) + ")";
        } else if (command.startsWith(Commands.CLICK)) {
            String[] parts = command.split(" ");
            int x = Integer.parseInt(parts[1]);
            int y = Integer.parseInt(parts[2]);
            Gdx.input.setCursorPosition(x, Gdx.graphics.getHeight() - y);
            Stage s = gameLoader.getEngine().getStage();
            aux.set(x, y);
            aux = s.screenToStageCoordinates(aux);
            Actor a = s.hit(aux.x, aux.y, true);
            gameLoader.getEngine().getStage().touchDown(x, y, 0, Input.Buttons.LEFT);
            result = a == null ? "" : a.getName();
        } else if (command.startsWith(Commands.EXIT)) {
            Gdx.app.exit();
        } else if (command.startsWith(Commands.LOG)) {
            logger.debug(command.substring(Math.max(0, command.indexOf(' '))));
            result = "OK.";
        } else if (command.startsWith(Commands.WAIT_EFFECTS)) {
            String[] parts = command.split(" ");
            for (int i = 1; i < parts.length; i++) {
                effects.add(parts[i]);
            }
            result = effects.size + " effects waiting";
        } else if (command.startsWith(Commands.CLEAR_EFFECTS)) {
            result = effects.size + " effects cleared.";
            effects.clear();
        } else if (command.startsWith(Commands.EFFECTS)) {
            result = effects.toString();
        }
    } catch (Exception e)

    {
        logger.error("{}", e);
        result = "Wrong parameters";
    }

    return result;
}