Advertisement
Guest User

Untitled

a guest
Jun 26th, 2015
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. package com.darichey.libgdxtest;
  2.  
  3. import com.badlogic.gdx.*;
  4. import com.badlogic.gdx.graphics.GL20;
  5. import com.badlogic.gdx.graphics.OrthographicCamera;
  6. import com.badlogic.gdx.graphics.Texture;
  7. import com.badlogic.gdx.graphics.g2d.SpriteBatch;
  8. import com.badlogic.gdx.utils.viewport.FitViewport;
  9. import com.badlogic.gdx.utils.viewport.Viewport;
  10.  
  11. public class LibGDXTest extends ApplicationAdapter
  12. {
  13. SpriteBatch batch;
  14. Texture wall;
  15. OrthographicCamera camera;
  16.  
  17. int CAM_WIDTH = 50;
  18. int CAM_HEIGHT = 30;
  19.  
  20. @Override
  21. public void create ()
  22. {
  23. batch = new SpriteBatch();
  24. wall = new Texture("wall.png");
  25.  
  26. camera = new OrthographicCamera(CAM_WIDTH, CAM_HEIGHT);
  27. camera.position.set(CAM_WIDTH / 2, CAM_HEIGHT / 2, 0);
  28. }
  29.  
  30. @Override
  31. public void render ()
  32. {
  33. Gdx.gl.glClearColor(0f, 10f, 200f, 0f);
  34. Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  35. camera.update();
  36.  
  37. batch.setProjectionMatrix(camera.combined);
  38. batch.begin();
  39. batch.draw(wall, 0, 0);
  40. batch.end();
  41.  
  42. // Input stuff
  43. if(Gdx.input.isKeyPressed(Input.Keys.RIGHT))
  44. camera.translate(1f,0f);
  45. if(Gdx.input.isKeyPressed(Input.Keys.LEFT))
  46. camera.translate(-1f,0f);
  47. if(Gdx.input.isKeyPressed(Input.Keys.UP))
  48. camera.translate(0f,1f);
  49. if(Gdx.input.isKeyPressed(Input.Keys.DOWN))
  50. camera.translate(0f,-1f);
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement