Advertisement
Guest User

Untitled

a guest
Apr 28th, 2015
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. boolean change = false;
  2. if (Gdx.input.isKeyPressed(Input.Keys.A)) {
  3. cam.zoom += 0.02;
  4. change = true;
  5. }
  6. if (Gdx.input.isKeyPressed(Input.Keys.Q)) {
  7. cam.zoom -= 0.02;
  8. change = true;
  9. }
  10. if (Gdx.input.isKeyPressed(Input.Keys.LEFT)) {
  11. cam.translate(-3, 0, 0);
  12. change = true;
  13. }
  14. if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)) {
  15. cam.translate(3, 0, 0);
  16. change = true;
  17. }
  18. if (Gdx.input.isKeyPressed(Input.Keys.DOWN)) {
  19. cam.translate(0, -3, 0);
  20. change = true;
  21. }
  22. if (Gdx.input.isKeyPressed(Input.Keys.UP)) {
  23. cam.translate(0, 3, 0);
  24. change = true;
  25. }
  26. if (Gdx.input.isKeyPressed(Input.Keys.W)) {
  27. cam.rotate(-rotationSpeed, 0, 0, 1);
  28. change = true;
  29. }
  30. if (Gdx.input.isKeyPressed(Input.Keys.E)) {
  31. cam.rotate(rotationSpeed, 0, 0, 1);
  32. change = true;
  33. }
  34.  
  35. if(change) {
  36. cam.zoom = MathUtils.clamp(cam.zoom, 0.1f, 100 / cam.viewportWidth);
  37.  
  38. float effectiveViewportWidth = cam.viewportWidth * cam.zoom;
  39. float effectiveViewportHeight = cam.viewportHeight * cam.zoom;
  40.  
  41. cam.position.x = MathUtils.clamp(cam.position.x, effectiveViewportWidth / 2f, 100 - effectiveViewportWidth / 2f);
  42. cam.position.y = MathUtils.clamp(cam.position.y, effectiveViewportHeight / 2f, 100 - effectiveViewportHeight / 2f);
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement