Oebele

ScreenViewport issue

Jun 30th, 2014
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.77 KB | None | 0 0
  1. package atotb;
  2.  
  3. import com.badlogic.gdx.Game;
  4. import com.badlogic.gdx.Screen;
  5. import com.badlogic.gdx.graphics.Texture;
  6. import com.badlogic.gdx.graphics.g2d.SpriteBatch;
  7.  
  8. public class TwoBrothersGame extends Game {
  9.     SpriteBatch batch;
  10.     Texture img;
  11.     Screen gameScreen;
  12.    
  13.     @Override
  14.     public void create () {
  15.         batch = new SpriteBatch();
  16.         img = new Texture("badlogic.jpg");
  17.         gameScreen = new GameScreen(this);
  18.         setScreen(gameScreen);
  19.     }
  20.    
  21.     @Override
  22.     public void dispose() {
  23.         batch.dispose();
  24.         img.dispose();
  25.         gameScreen.dispose();
  26.     }
  27. }
  28.  
  29. ------------------------------------------------------------------------------------------------------------------------
  30.  
  31. package atotb;
  32.  
  33. import com.badlogic.gdx.Gdx;
  34. import com.badlogic.gdx.Screen;
  35. import com.badlogic.gdx.graphics.GL20;
  36. import com.badlogic.gdx.graphics.OrthographicCamera;
  37. import com.badlogic.gdx.utils.viewport.ScreenViewport;
  38. import com.badlogic.gdx.utils.viewport.Viewport;
  39.  
  40. class GameScreen implements Screen {
  41.     TwoBrothersGame game;
  42.     OrthographicCamera camera;
  43.     Viewport viewport;
  44.  
  45.     public GameScreen(TwoBrothersGame game) {
  46.         this.game = game;
  47.         camera = new OrthographicCamera();
  48.         viewport = new ScreenViewport(camera);
  49.     }
  50.  
  51.     @Override
  52.     public void render(float dt) {
  53.         camera.update();
  54.         Gdx.gl.glClearColor(1, 0, 0, 1);
  55.         Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  56.         game.batch.begin();
  57.         game.batch.draw(game.img, 0, 0);
  58.         game.batch.end();
  59.     }
  60.  
  61.     @Override
  62.     public void resize(int width, int height) {
  63.         viewport.update(width, height);
  64.     }
  65.  
  66.     @Override
  67.     public void show() {
  68.     }
  69.  
  70.     @Override
  71.     public void hide() {
  72.     }
  73.  
  74.     @Override
  75.     public void pause() {
  76.     }
  77.  
  78.     @Override
  79.     public void resume() {
  80.     }
  81.  
  82.     @Override
  83.     public void dispose() {
  84.     }  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment