Guest User

Untitled

a guest
Jul 21st, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. cam.position.x = clamp(cam.position.x, Gdx.graphics.getWidth()-cam.viewportWidth, 0);
  2. cam.position.y = clamp(cam.position.y, Gdx.graphics.getHeight()-cam.viewportHeight, 0);
  3. cam.update();
  4.  
  5. public float clamp(float var, float max, float min) {
  6.  
  7.  
  8. if (var > min) {
  9. if (var < max) {
  10. return var;
  11. } else return max;
  12. } else return min;
  13. }
  14.  
  15. orthomap = new OrthogonalTiledMapRenderer(tileMap);
  16.  
  17. orthomap = new OrthogonalTiledMapRenderer(tileMap);
  18.  
  19.  
  20.  
  21. //setup Box2D Cam
  22.  
  23.  
  24. OrthographicCamera B2DCAM=new OrthographicCamera(Gdx.graphics.getWidth()/PPM,Gdx.graphics.getHeight()/PPM);
  25.  
  26. OrthographicCamera cam=new OrthographicCamera(Gdx.graphics.getWidth()/4,Gdx.graphics.getHeight()/4);
  27.  
  28. public void render(float delta) {
  29.  
  30. //clear screen
  31. update(delta);
  32.  
  33. Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT);
  34. cam.position.x = clamp(cam.position.x, Gdx.graphics.getWidth()-cam.viewportWidth, 0);
  35. cam.position.y = clamp(cam.position.y, Gdx.graphics.getHeight()-cam.viewportHeight, 0);
  36. cam.update();
  37.  
  38.  
  39. // cam.position.x += (player.getPosition().x + delta - cam.position.x) * 0.3 * delta;
  40. // cam.update();
  41. // cam.position.set(cam.position.x,3.5f,0);
  42. // cam.update();
  43. cam.position.set(player.getPosition().x*PPM ,player.getPosition().y*PPM ,0);
  44. // B2DCAM.position.set(player.getPosition().x*PPM ,player.getPosition().y*PPM ,0);
  45. // B2DCAM.position.set(cam.position.x,3.5f,0);
  46. // B2DCAM.update();
  47.  
  48. // B2DCAM.update();
  49. cam.update();
  50. // hud.update();
  51.  
  52.  
  53. if (sb == null) {
  54. System.out.println("Sb is null");
  55. }
  56. // cam.position.set(player.getPosition().x,player.getPosition().y,0 );
  57. sb.setProjectionMatrix(cam.combined);
  58.  
  59.  
  60. for(int i=0;i<diamondsArray.size;i++){
  61. diamondsArray.get(i).render(sb);
  62. }
  63.  
  64.  
  65.  
  66. //draw tile map
  67. orthomap.setView(cam);
  68. orthomap.render();
  69. //draw player
  70. sb.setProjectionMatrix(cam.combined);
  71.  
  72. player.render(sb);
  73.  
  74. b2d.render(world,B2DCAM.combined);
  75.  
  76.  
  77.  
  78.  
  79. }
Add Comment
Please, Sign In to add comment