Guest User

Untitled

a guest
Jan 20th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. public void render(float delta) {
  2. update();
  3.  
  4. //В .show я указал цвет очистки
  5. Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  6.  
  7. batch.begin();
  8. camera.translate(hero, batch);
  9.  
  10. joystick.render(batch);
  11. hero.render(batch);
  12. batch.end();
  13. }
  14.  
  15. public void translate(Hero hero, SpriteBatch batch){
  16.  
  17. // x translate
  18. if (hero.getVector().x - (int) camera.viewportWidth / 2 < 0) {
  19. // x = 0;
  20. } else if (hero.getVector().x + (int) camera.viewportWidth / 2 > mapWidth) {
  21. // x = mapWidth - (int) camera.viewportWidth;
  22. } else {
  23. x = (int) hero.getVector().x - (int) camera.viewportWidth / 2;
  24.  
  25. for (int i = 0; i < collisionLoader.length; i++) {
  26. if (hero.speed < 0){
  27. collisionLoader[i].setOffsetX(collisionLoader[i].getOffsetX() - ((collisionLoader.length - i) * (Math.abs(hero.speed) / collisionLoader.length)));
  28. }else if (hero.speed > 0){
  29. collisionLoader[i].setOffsetX(collisionLoader[i].getOffsetX() + (collisionLoader.length - i) * (hero.speed / collisionLoader.length));
  30. }
  31.  
  32. }
  33. }
  34.  
  35. // y translate
  36. if (hero.getVector().y - (int) camera.viewportHeight / 2 < 0) {
  37. y = 0;
  38. } else if (hero.getVector().y + (int) camera.viewportHeight / 2 > mapHeight) {
  39. y = mapHeight - (int) camera.viewportHeight;
  40. } else {
  41. y = (int) hero.getVector().y - (int) camera.viewportHeight / 2;
  42. }
  43.  
  44.  
  45. // camera update
  46. camera.update();
  47. batch.setProjectionMatrix(camera.combined);
  48.  
  49. // camera position translate
  50. camera.position.set(new Vector3(-x, -y, 0));
  51. camera.position.set(new Vector3(camera.viewportWidth - camera.position.x,
  52. camera.viewportHeight / 2 -
  53. camera.position.y,
  54. 0));
  55.  
  56. // tiled render
  57. renderer.setView(camera);
  58. renderer.render();
  59. }
  60.  
  61. public Camera(int mapWidth, int mapHeight, TiledMap map,
  62. OrthogonalTiledMapRenderer renderer,
  63. TiledMapTileLayer[] collisionLoader) {
  64. camera = new OrthographicCamera(512, 288);
  65.  
  66. this.map = map;
  67. this.renderer = renderer;
  68.  
  69. this.mapWidth = mapWidth;
  70. this.mapHeight = mapHeight;
  71.  
  72. this.collisionLoader = collisionLoader;
  73. for (int i = 0; i < collisionLoader.length; i++){
  74. collisionLoader[i] = (TiledMapTileLayer) map.getLayers().get(i);
  75. this.collisionLoader[i] = collisionLoader[i];
  76. }
  77. }
Add Comment
Please, Sign In to add comment