Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void render(float delta) {
- update();
- //В .show я указал цвет очистки
- Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
- batch.begin();
- camera.translate(hero, batch);
- joystick.render(batch);
- hero.render(batch);
- batch.end();
- }
- public void translate(Hero hero, SpriteBatch batch){
- // x translate
- if (hero.getVector().x - (int) camera.viewportWidth / 2 < 0) {
- // x = 0;
- } else if (hero.getVector().x + (int) camera.viewportWidth / 2 > mapWidth) {
- // x = mapWidth - (int) camera.viewportWidth;
- } else {
- x = (int) hero.getVector().x - (int) camera.viewportWidth / 2;
- for (int i = 0; i < collisionLoader.length; i++) {
- if (hero.speed < 0){
- collisionLoader[i].setOffsetX(collisionLoader[i].getOffsetX() - ((collisionLoader.length - i) * (Math.abs(hero.speed) / collisionLoader.length)));
- }else if (hero.speed > 0){
- collisionLoader[i].setOffsetX(collisionLoader[i].getOffsetX() + (collisionLoader.length - i) * (hero.speed / collisionLoader.length));
- }
- }
- }
- // y translate
- if (hero.getVector().y - (int) camera.viewportHeight / 2 < 0) {
- y = 0;
- } else if (hero.getVector().y + (int) camera.viewportHeight / 2 > mapHeight) {
- y = mapHeight - (int) camera.viewportHeight;
- } else {
- y = (int) hero.getVector().y - (int) camera.viewportHeight / 2;
- }
- // camera update
- camera.update();
- batch.setProjectionMatrix(camera.combined);
- // camera position translate
- camera.position.set(new Vector3(-x, -y, 0));
- camera.position.set(new Vector3(camera.viewportWidth - camera.position.x,
- camera.viewportHeight / 2 -
- camera.position.y,
- 0));
- // tiled render
- renderer.setView(camera);
- renderer.render();
- }
- public Camera(int mapWidth, int mapHeight, TiledMap map,
- OrthogonalTiledMapRenderer renderer,
- TiledMapTileLayer[] collisionLoader) {
- camera = new OrthographicCamera(512, 288);
- this.map = map;
- this.renderer = renderer;
- this.mapWidth = mapWidth;
- this.mapHeight = mapHeight;
- this.collisionLoader = collisionLoader;
- for (int i = 0; i < collisionLoader.length; i++){
- collisionLoader[i] = (TiledMapTileLayer) map.getLayers().get(i);
- this.collisionLoader[i] = collisionLoader[i];
- }
- }
Add Comment
Please, Sign In to add comment