List of usage examples for com.badlogic.gdx.scenes.scene2d Stage hit
public Actor hit(float stageX, float stageY, boolean touchable)
From source file:com.vlaaad.common.tutorial.tasks.ArrowForceClick.java
License:Open Source License
protected void addListener(final Stage stage, final Actor target, final Image arrow, final Table message, final Callback callback) { stage.addCaptureListener(new InputListener() { @Override//w w w .j a v a 2 s .co m public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { Actor result = stage.hit(event.getStageX(), event.getStageY(), true); if (!result.isDescendantOf(target)) { event.cancel(); return false; } return true; } @Override public void touchUp(InputEvent event, float x, float y, int pointer, int button) { Actor result = stage.hit(event.getStageX(), event.getStageY(), true); if (!result.isDescendantOf(target)) { event.cancel(); return; } stage.removeCaptureListener(this); arrow.remove(); message.remove(); callback.taskEnded(); } }); }
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 www . j a v a2 s.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; }