@Override public void create () { // create a stage and a camera controller so we can pan the view. stage = new Stage();; camController = new OrthoCamController((OrthographicCamera)stage.getCamera()); // we know it's an ortho cam at this point! Gdx.input.setInputProcessor(camController); // load a dummy texture texture = new Texture(Gdx.files.internal("data/badlogicsmall.jpg")); // populate the stage with some actors and groups. for (int i = 0; i < 5000; i++) { Actor img = new CullableActor("img" + i, texture, (OrthographicCamera)stage.getCamera()); img.setX((float)Math.random() * 480 * 10); img.setY((float)Math.random() * 320 * 10); stage.addActor(img); } // we also want to output the number of visible actors, so we need a SpriteBatch and a BitmapFont batch = new SpriteBatch(); font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false); }
Camera cam = stage.getCamera(); batch.setProjectionMatrix(cam.combined); batch.begin();
float heightAbove = stage.getCamera().viewportHeight - screenPosition.y - selectBox.getHeight(); boolean below = true; if (height > heightBelow) {
float heightAbove = stage.getCamera().viewportHeight - screenPosition.y - selectBox.getHeight(); boolean below = true; if (height > heightBelow) {
public void keepWithinStage () { if (!keepWithinStage) return; Stage stage = getStage(); if (stage == null) return; Camera camera = stage.getCamera(); if (camera instanceof OrthographicCamera) { OrthographicCamera orthographicCamera = (OrthographicCamera)camera; float parentWidth = stage.getWidth(); float parentHeight = stage.getHeight(); if (getX(Align.right) - camera.position.x > parentWidth / 2 / orthographicCamera.zoom) setPosition(camera.position.x + parentWidth / 2 / orthographicCamera.zoom, getY(Align.right), Align.right); if (getX(Align.left) - camera.position.x < -parentWidth / 2 / orthographicCamera.zoom) setPosition(camera.position.x - parentWidth / 2 / orthographicCamera.zoom, getY(Align.left), Align.left); if (getY(Align.top) - camera.position.y > parentHeight / 2 / orthographicCamera.zoom) setPosition(getX(Align.top), camera.position.y + parentHeight / 2 / orthographicCamera.zoom, Align.top); if (getY(Align.bottom) - camera.position.y < -parentHeight / 2 / orthographicCamera.zoom) setPosition(getX(Align.bottom), camera.position.y - parentHeight / 2 / orthographicCamera.zoom, Align.bottom); } else if (getParent() == stage.getRoot()) { float parentWidth = stage.getWidth(); float parentHeight = stage.getHeight(); if (getX() < 0) setX(0); if (getRight() > parentWidth) setX(parentWidth - getWidth()); if (getY() < 0) setY(0); if (getTop() > parentHeight) setY(parentHeight - getHeight()); } }
public void keepWithinStage () { if (!keepWithinStage) return; Stage stage = getStage(); if (stage == null) return; Camera camera = stage.getCamera(); if (camera instanceof OrthographicCamera) { OrthographicCamera orthographicCamera = (OrthographicCamera)camera; float parentWidth = stage.getWidth(); float parentHeight = stage.getHeight(); if (getX(Align.right) - camera.position.x > parentWidth / 2 / orthographicCamera.zoom) setPosition(camera.position.x + parentWidth / 2 / orthographicCamera.zoom, getY(Align.right), Align.right); if (getX(Align.left) - camera.position.x < -parentWidth / 2 / orthographicCamera.zoom) setPosition(camera.position.x - parentWidth / 2 / orthographicCamera.zoom, getY(Align.left), Align.left); if (getY(Align.top) - camera.position.y > parentHeight / 2 / orthographicCamera.zoom) setPosition(getX(Align.top), camera.position.y + parentHeight / 2 / orthographicCamera.zoom, Align.top); if (getY(Align.bottom) - camera.position.y < -parentHeight / 2 / orthographicCamera.zoom) setPosition(getX(Align.bottom), camera.position.y - parentHeight / 2 / orthographicCamera.zoom, Align.bottom); } else if (getParent() == stage.getRoot()) { float parentWidth = stage.getWidth(); float parentHeight = stage.getHeight(); if (getX() < 0) setX(0); if (getRight() > parentWidth) setX(parentWidth - getWidth()); if (getY() < 0) setY(0); if (getTop() > parentHeight) setY(parentHeight - getHeight()); } }
public void create () { stage = new Stage(); Skin skin = new Skin(Gdx.files.internal("data/uiskin.json")); label = new Label("", skin); Table root = new Table(skin); root.setFillParent(true); root.setBackground(skin.getDrawable("default-pane")); root.debug().defaults().space(6); root.add(new TextButton("Button 1", skin)); root.add(new TextButton("Button 2", skin)).row(); root.add("Press spacebar to change the viewport:").colspan(2).row(); root.add(label).colspan(2); stage.addActor(root); viewports = getViewports(stage.getCamera()); names = getViewportNames(); stage.setViewport(viewports.first()); label.setText(names.first()); Gdx.input.setInputProcessor(new InputMultiplexer(new InputAdapter() { public boolean keyDown (int keycode) { if (keycode == Input.Keys.SPACE) { int index = (viewports.indexOf(stage.getViewport(), true) + 1) % viewports.size; label.setText(names.get(index)); Viewport viewport = viewports.get(index); stage.setViewport(viewport); resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); } return false; } }, stage)); }
stage1.getCamera().position.set(100, 100, 0);
@Override public void render(float delta) { super.render(delta); debugRenderer.setProjectionMatrix(stage.getCamera().combined); debugRenderer.begin(ShapeRenderer.ShapeType.Line); debugRenderer.setColor(Color.YELLOW); Vector2 gameAreaBounds = game.getResolutionHelper().getGameAreaBounds(); Vector2 gameAreaPosition= game.getResolutionHelper().getGameAreaPosition(); debugRenderer.rect(gameAreaPosition.x, gameAreaPosition.y, gameAreaBounds.x, gameAreaBounds.y); debugRenderer.rect(gameAreaPosition.x+1, gameAreaPosition.y+1, gameAreaBounds.x-2, gameAreaBounds.y-2); debugRenderer.end(); }
stage.getCamera().position.set(AppSettings.SCREEN_W / 2, AppSettings.SCREEN_H / 2, 0);
float heightAbove = stage.getCamera().viewportHeight - screenPosition.y - selectBox.getHeight(); boolean below = true; if (height > heightBelow) {
@Override public void render(float delta) { //separate our update logic from render update(delta); //Clear the game screen with Black Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); //render our game map renderer.render(); //renderer our Box2DDebugLines b2dr.render(world, gamecam.combined); game.batch.setProjectionMatrix(gamecam.combined); game.batch.begin(); player.draw(game.batch); for (Enemy enemy : creator.getEnemies()) enemy.draw(game.batch); for (Item item : items) item.draw(game.batch); game.batch.end(); //Set our batch to now draw what the Hud camera sees. game.batch.setProjectionMatrix(hud.stage.getCamera().combined); hud.stage.draw(); if(gameOver()){ game.setScreen(new GameOverScreen(game)); dispose(); } }
float heightAbove = stage.getCamera().viewportHeight - screenPosition.y - selectBox.getHeight(); boolean below = true; if (height > heightBelow) {
public void keepWithinStage () { if (!keepWithinStage) return; Stage stage = getStage(); if (stage == null) return; Camera camera = stage.getCamera(); if (camera instanceof OrthographicCamera) { OrthographicCamera orthographicCamera = (OrthographicCamera)camera; float parentWidth = stage.getWidth(); float parentHeight = stage.getHeight(); if (getX(Align.right) - camera.position.x > parentWidth / 2 / orthographicCamera.zoom) setPosition(camera.position.x + parentWidth / 2 / orthographicCamera.zoom, getY(Align.right), Align.right); if (getX(Align.left) - camera.position.x < -parentWidth / 2 / orthographicCamera.zoom) setPosition(camera.position.x - parentWidth / 2 / orthographicCamera.zoom, getY(Align.left), Align.left); if (getY(Align.top) - camera.position.y > parentHeight / 2 / orthographicCamera.zoom) setPosition(getX(Align.top), camera.position.y + parentHeight / 2 / orthographicCamera.zoom, Align.top); if (getY(Align.bottom) - camera.position.y < -parentHeight / 2 / orthographicCamera.zoom) setPosition(getX(Align.bottom), camera.position.y - parentHeight / 2 / orthographicCamera.zoom, Align.bottom); } else if (getParent() == stage.getRoot()) { float parentWidth = stage.getWidth(); float parentHeight = stage.getHeight(); if (getX() < 0) setX(0); if (getRight() > parentWidth) setX(parentWidth - getWidth()); if (getY() < 0) setY(0); if (getTop() > parentHeight) setY(parentHeight - getHeight()); } }
void keepWithinStage () { if (!keepWithinStage) return; Stage stage = getStage(); Camera camera = stage.getCamera(); if (camera instanceof OrthographicCamera) { OrthographicCamera orthographicCamera = (OrthographicCamera)camera; float parentWidth = stage.getWidth(); float parentHeight = stage.getHeight(); if (getX(Align.right) - camera.position.x > parentWidth / 2 / orthographicCamera.zoom) setPosition(camera.position.x + parentWidth / 2 / orthographicCamera.zoom, getY(Align.right), Align.right); if (getX(Align.left) - camera.position.x < -parentWidth / 2 / orthographicCamera.zoom) setPosition(camera.position.x - parentWidth / 2 / orthographicCamera.zoom, getY(Align.left), Align.left); if (getY(Align.top) - camera.position.y > parentHeight / 2 / orthographicCamera.zoom) setPosition(getX(Align.top), camera.position.y + parentHeight / 2 / orthographicCamera.zoom, Align.top); if (getY(Align.bottom) - camera.position.y < -parentHeight / 2 / orthographicCamera.zoom) setPosition(getX(Align.bottom), camera.position.y - parentHeight / 2 / orthographicCamera.zoom, Align.bottom); } else if (getParent() == stage.getRoot()) { float parentWidth = stage.getWidth(); float parentHeight = stage.getHeight(); if (getX() < 0) setX(0); if (getRight() > parentWidth) setX(parentWidth - getWidth()); if (getY() < 0) setY(0); if (getTop() > parentHeight) setY(parentHeight - getHeight()); } }
/** * Makes sures that actor will be fully visible in stage. If it's necessary actor position will be changed to fit it * on screen. */ 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()); } } }
Camera camera = stage.getCamera(); if (camera instanceof OrthographicCamera) { OrthographicCamera orthographicCamera = (OrthographicCamera) camera;