/** Configures this viewport's screen bounds using the specified screen size and calls {@link #apply(boolean)}. Typically called * from {@link ApplicationListener#resize(int, int)} or {@link Screen#resize(int, int)}. * <p> * The default implementation only calls {@link #apply(boolean)}. */ public void update (int screenWidth, int screenHeight, boolean centerCamera) { apply(centerCamera); }
/** Configures this viewport's screen bounds using the specified screen size and calls {@link #apply(boolean)}. Typically called * from {@link ApplicationListener#resize(int, int)} or {@link Screen#resize(int, int)}. * <p> * The default implementation only calls {@link #apply(boolean)}. */ public void update (int screenWidth, int screenHeight, boolean centerCamera) { apply(centerCamera); }
/** Calls {@link #apply(boolean)} with false. */ public void apply () { apply(false); }
/** Calls {@link #apply(boolean)} with false. */ public void apply () { apply(false); }
@Override public void render () { Gdx.gl.glClearColor(0, 0, 0, 1f); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); viewport.apply(); mapRenderer.setView(cam); mapRenderer.render(); if (Gdx.input.isKeyPressed(Keys.ESCAPE)) { if (DELETE_DELETEME_FOLDER_ON_EXIT) { FileHandle deleteMeHandle = Gdx.files.local(MAP_PATH); deleteMeHandle.deleteDirectory(); } dispose(); Gdx.app.exit(); } }
@Override public void render () { Gdx.gl.glClearColor(0, 0, 0, 1f); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); viewport.apply(); mapRenderer.setView(cam); mapRenderer.render(); if (Gdx.input.isKeyPressed(Keys.ESCAPE)) { if (DELETE_DELETEME_FOLDER_ON_EXIT) { FileHandle deleteMeHandle = Gdx.files.local(MAP_PATH); deleteMeHandle.deleteDirectory(); } dispose(); Gdx.app.exit(); } }
/** Configures this viewport's screen bounds using the specified screen size and calls {@link #apply(boolean)}. Typically called * from {@link ApplicationListener#resize(int, int)} or {@link Screen#resize(int, int)}. * <p> * The default implementation only calls {@link #apply(boolean)}. */ public void update (int screenWidth, int screenHeight, boolean centerCamera) { apply(centerCamera); }
/** Calls {@link #apply(boolean)} with false. */ public void apply () { apply(false); }
public class EmptyScreen implements Screen { OrthographicCamera cam; Viewport viewport; SpriteBatch batch; MyGame game; public EmptyScreen(SpriteBatch batch, MyGame game) { this.game = game; cam = new OrthographicCamera(); viewport = new StretchViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), cam); viewport.apply(); this.batch = batch; } @Override public void show() { } @Override public void render(float delta) { game.setScreen(new LoadingScreen(game, batch)); }
private void setup2D() { orthoCamera.update(); graphics.setProjectionMatrix(orthoCamera.combined); viewport.apply(); }
Viewport vp = new FitViewport(); vp.setScreenBounds(worldWidth / 2, worldHeight / 2, worldWidth, worldHeight); vp.apply();
public void show() { if(initialized) { stage.getViewport().apply(true); stage.draw(); stage.act(); } } }
@Override public void create() { orthoCamera = new OrthographicCamera(); viewport = new FitViewport(w, h, orthoCamera); viewport.apply(); orthoCamera.position.set(orthoCamera.viewportWidth / 2, orthoCamera.viewportHeight / 2, 0); init(); }
/** * Not a complete drawing solution; so much of the logic related to drawing is specific to each game, like * FOV being used to make certain things not render if they are out of sight, that this doesn't even try to * guess at what a particular game needs for its rendering code. You should probably draw any AnimatedEntity * objects, like what {@link SquidLayers#animateActor(int, int, char, Color)} returns, separately and after * calling this method. The recommended way to draw those objects is with {@link #drawEntity(AnimatedEntity)}, * which must be called between SpriteBatch's begin() and end() methods, while this method cannot be called * between those SpriteBatch methods. The solution, usually, is to call this method, then call * {@link SpriteBatch#begin()}, do any logic to determine what AnimatedEntity objects need to be shown (are * they in FOV, are they alive, etc.), draw the ones that should be shown with drawEntity(), and finally * call {@link SpriteBatch#end()} when no more AnimatedEntity objects need to be drawn. Note that this * method renders all of {@link #stage}, which may include other GUI elements using scene2d.ui, but the * AnimatedEntity objects in a SquidLayers aren't part of any Stage to allow them to be rendered as special * cases for visibility. * <br> * Specifically, this applies the current viewport to the stage, draws the stage, and makes any actions or * events related to the stage take effect. Should not be called inside a {@link SpriteBatch#begin()} block, * since this calls it itself by drawing the stage, and also calls {@link SpriteBatch#end()} afterwards. */ public void draw() { stage.getViewport().apply(true); stage.draw(); stage.act(); }
/** * Renders the registered GUIs * @param rw The render width * @param rh The render height */ public static void render(int rw, int rh) { synchronized (guirenderlock) { for (int i = 0; i < guis.size; i++) { guis.get(i).getGuiStage().getViewport().apply(); guis.get(i).render(rw, rh); } } }
public void render(SpriteBatch batch) { viewport.apply(); batch.setProjectionMatrix(viewport.getCamera().combined); batch.begin(); for (Explosion explosion : explosions){ explosion.render(batch); } font.draw(batch, Constants.VICTORY_MESSAGE, viewport.getWorldWidth() / 2, viewport.getWorldHeight() / 2.5f, 0, Align.center, false); batch.end(); } }
@Override public void render () { Gdx.gl.glClearColor(0, 0, 0, 1f); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); viewport.apply(); mapRenderer.setView(cam); mapRenderer.render(); if (Gdx.input.isKeyPressed(Keys.ESCAPE)) { if (DELETE_DELETEME_FOLDER_ON_EXIT) { FileHandle deleteMeHandle = Gdx.files.local(MAP_PATH); deleteMeHandle.deleteDirectory(); } dispose(); Gdx.app.exit(); } }
/** * When using a viewport, instead of calling camera.update(), we just call viewport.apply() */ @Override public void render() { Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); viewport.apply(); renderer.setProjectionMatrix(camera.combined); renderer.begin(ShapeType.Filled); renderer.setColor(Color.GREEN); renderer.rect(-10, -10, WORLD_WIDTH + 20, WORLD_HEIGHT + 20); renderWorld(); renderer.end(); }
public void render(SpriteBatch batch) { viewport.apply(); batch.setProjectionMatrix(viewport.getCamera().combined); batch.begin(); float timeElapsed = Utils.secondsSince(startTime); int enemiesToShow = (int) (Constants.ENEMY_COUNT * (timeElapsed / Constants.LEVEL_END_DURATION)); for (int i = 0; i < enemiesToShow; i++) { Enemy enemy = enemies.get(i); enemy.update(0); enemy.render(batch); } font.draw(batch, Constants.GAME_OVER_MESSAGE, viewport.getWorldWidth() / 2, viewport.getWorldHeight() / 2.5f, 0, Align.center, false); batch.end(); } }
@Override public void draw(Batch batch, float parentAlpha) { if (renderer == null || cam == null) return; // render part of the ui & pause rest batch.end(); vec.set(getOriginX(), getOriginY()); vec = localToStageCoordinates(vec); final int width = (int) getWidth(); final int height = (int) getHeight(); // apply widget viewport viewport.setScreenBounds((int) vec.x, (int) vec.y, width, height); viewport.setWorldSize(width * viewport.getUnitsPerPixel(), height * viewport.getUnitsPerPixel()); viewport.apply(); // render 3d scene renderer.render(cam); // re-apply stage viewport UI.INSTANCE.getViewport().apply(); // proceed ui rendering batch.begin(); }