List of usage examples for com.badlogic.gdx.scenes.scene2d Stage getCamera
public Camera getCamera()
From source file:com.kotcrab.vis.ui.util.ActorUtils.java
License:Apache License
/** * Makes sures that actor will be fully visible in stage. If it's necessary actor position will be changed to fit it * on screen./* ww w .jav a 2s . c o m*/ */ public static void keepWithinStage(Stage stage, Actor actor) { //taken from scene2d.ui Window Camera camera = stage.getCamera(); if (camera instanceof OrthographicCamera) { OrthographicCamera orthographicCamera = (OrthographicCamera) camera; float parentWidth = stage.getWidth(); float parentHeight = stage.getHeight(); if (actor.getX(Align.right) - camera.position.x > parentWidth / 2 / orthographicCamera.zoom) actor.setPosition(camera.position.x + parentWidth / 2 / orthographicCamera.zoom, actor.getY(Align.right), Align.right); if (actor.getX(Align.left) - camera.position.x < -parentWidth / 2 / orthographicCamera.zoom) actor.setPosition(camera.position.x - parentWidth / 2 / orthographicCamera.zoom, actor.getY(Align.left), Align.left); if (actor.getY(Align.top) - camera.position.y > parentHeight / 2 / orthographicCamera.zoom) actor.setPosition(actor.getX(Align.top), camera.position.y + parentHeight / 2 / orthographicCamera.zoom, Align.top); if (actor.getY(Align.bottom) - camera.position.y < -parentHeight / 2 / orthographicCamera.zoom) actor.setPosition(actor.getX(Align.bottom), camera.position.y - parentHeight / 2 / orthographicCamera.zoom, Align.bottom); } else if (actor.getParent() == stage.getRoot()) { float parentWidth = stage.getWidth(); float parentHeight = stage.getHeight(); if (actor.getX() < 0) actor.setX(0); if (actor.getRight() > parentWidth) actor.setX(parentWidth - actor.getWidth()); if (actor.getY() < 0) actor.setY(0); if (actor.getTop() > parentHeight) actor.setY(parentHeight - actor.getHeight()); } }
From source file:com.strategames.ui.helpers.FilledRectangleImage.java
License:Open Source License
@Override protected void setStage(Stage stage) { super.setStage(stage); if (stage != null) { this.shapeRenderer.setProjectionMatrix(stage.getCamera().combined); }//from ww w. j a va2s . c o m }
From source file:com.vlaaad.common.GdxHelper.java
License:Open Source License
public static void showStageEvents(final Stage stage) { EventListener listener = new EventListener() { private final Vector2 tmp = new Vector2(); private Actor actor = new Actor() { @Override//w w w.ja v a 2s . co m public void draw(Batch batch, float parentAlpha) { if (target == null) return; batch.end(); Config.shapeRenderer.begin(ShapeRenderer.ShapeType.Line); Config.shapeRenderer.setProjectionMatrix(stage.getCamera().combined); Gdx.gl.glLineWidth(6); Config.shapeRenderer.setColor(Color.ORANGE); Vector2 pos = target.localToStageCoordinates(tmp.set(0, 0)); float x = pos.x, y = pos.y; Vector2 top = target.localToStageCoordinates(tmp.set(target.getWidth(), target.getHeight())); float maxX = top.x, maxY = top.y; Config.shapeRenderer.rect(x, y, maxX - x, maxY - y); Config.shapeRenderer.end(); batch.begin(); } }; { stage.addActor(actor); } public Actor target; @Override public boolean handle(Event event) { target = event.getTarget(); return false; } }; stage.addListener(listener); }
From source file:de.r2soft.empires.client.graphics.R2Overlay.java
License:Open Source License
public R2Overlay(Stage stage) { this.stage = stage; renderer = new ShapeRenderer(); this.camera = (OrthographicCamera) stage.getCamera(); }
From source file:io.lonelyrobot.empires.client.graphics.R2Overlay.java
License:Open Source License
/** * Preferred constructor for an overlay. It initialises itself with a stage and also a default UI skin to be used for * the table parent./*w w w. java2 s. c o m*/ * * @param stage * Stage to hold children. Can be passed down from Screen. * @param uiskin * Default UI skin for {@link #main} Table to hold. */ public R2Overlay(Stage stage, Skin uiskin) { this.stage = stage; main = new Table(uiskin); main.setFillParent(true); // Just check this. It makes sense in 99% of cases. stage.addActor(main); renderer = new ShapeRenderer(); this.camera = (OrthographicCamera) stage.getCamera(); }