Advertisement
VeslaGames

[Libgdx] Viewport example

May 19th, 2015
611
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.31 KB | None | 0 0
  1. public class Main extends Game {
  2.         public static final int V_WIDTH = 1920;
  3.         public static final int V_HEIGHT = 1080;
  4.  
  5.         OrthographicCamera cam;
  6.         Stage stage;
  7.  
  8.         TextureAtlas atlas;
  9.         Image Logo;
  10.        
  11.         @Override
  12.         public void create () {
  13.                 cam = new OrthographicCamera();
  14.                 cam.setToOrtho(false, 800, 600);
  15.  
  16.                 stage = new Stage(new FitViewport(V_WIDTH, V_HEIGHT, cam));
  17.  
  18.                 atlas = new TextureAtlas("LoadingScreen.pack");
  19.                 Logo = new Image(atlas.findRegion("Logo1"));
  20.  
  21.                 Logo.setX(stage.getWidth() / 2 - Logo.getWidth() / 2);
  22.                 Logo.setY(stage.getHeight() / 2 - Logo.getHeight() / 2);
  23.                 stage.addActor(Logo);
  24.         }
  25.  
  26.         @Override
  27.         public void resize(int width, int height) {
  28.                 stage.getViewport().update(width, height, false);
  29.         }
  30.  
  31.         @Override
  32.         public void render () {
  33.                 Gdx.gl.glClearColor(1, 0, 0, 1);
  34.                 Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  35.  
  36.                 stage.act();
  37.                 stage.draw();
  38.         }
  39.  
  40.         @Override
  41.         public void dispose() {
  42.                 atlas.dispose();
  43.                 stage.dispose();
  44.         }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement