Advertisement
Guest User

Untitled

a guest
Jun 30th, 2017
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. public class MyGdxGame extends ApplicationAdapter {
  2. SpriteBatch batch;
  3. Sprite backg;
  4. Sprite board;
  5. OrthographicCamera camera;
  6. Viewport viewport;
  7. Viewport viewportBg;
  8. private final Texture bgt;
  9.  
  10. @Override
  11. public void create () {
  12. batch = new SpriteBatch();
  13.  
  14. bgt = new Texture(Gdx.files.internal("tmp/bg.png"));
  15. bgt.setWrap(Texture.TextureWrap.Repeat, Texture.TextureWrap.Repeat);
  16.  
  17. board = new Sprite(new Texture(Gdx.files.internal("tmp/br.png")));
  18. board.setPosition(100, 100);
  19. board.setSize(200, 200);
  20.  
  21. camera = new OrthographicCamera();
  22. viewportBg = new ScreenViewport(camera);
  23.  
  24. // viewport = new StretchViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), camera);
  25. viewport = new ExtendViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), camera);
  26. }
  27.  
  28. @Override
  29. public void render(float dt) {
  30. camera.update();
  31.  
  32. Gdx.gl.glClearColor(1, 0, 0, 1);
  33. Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  34.  
  35. batch.begin();
  36.  
  37. viewportBg.apply(true);
  38. batch.setProjectionMatrix(camera.combined);
  39. batch.draw(bgt, 0, 0, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
  40.  
  41. viewport.apply(true);
  42. batch.setProjectionMatrix(camera.combined);
  43. board.draw(batch);
  44.  
  45. batch.end();
  46. }
  47.  
  48. @Override
  49. public void dispose() {
  50. batch.dispose();
  51. }
  52.  
  53. @Override
  54. public void resize(int width, int height) {
  55. viewport.update(width, height);
  56. viewportBg.update(width, height);
  57. camera.position.set(width / 2, height / 2, 0);
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement