From 7907eb348d58665e559be0bb8bda559d9d4ae6fc Mon Sep 17 00:00:00 2001 From: Allexit Date: Thu, 9 Apr 2015 00:12:07 +0300 Subject: [PATCH] When resizing the window, viewport scales to right size now --- .../src/com/saltosion/gladiator/GladiatorBrawler.java | 11 +++++++++++ .../saltosion/gladiator/systems/RenderingSystem.java | 7 ++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/core/src/com/saltosion/gladiator/GladiatorBrawler.java b/core/src/com/saltosion/gladiator/GladiatorBrawler.java index af3d223..9f75754 100644 --- a/core/src/com/saltosion/gladiator/GladiatorBrawler.java +++ b/core/src/com/saltosion/gladiator/GladiatorBrawler.java @@ -54,6 +54,17 @@ public class GladiatorBrawler extends ApplicationAdapter { engine.update(Gdx.graphics.getDeltaTime()); } + @Override + public void resize(int width, int height) { + super.resize(width, height); + RenderingSystem rs = engine.getSystem(RenderingSystem.class); + float aspectratio = ((float)width)/((float)height); + rs.setViewport((int)(rs.VPHEIGHT_CONST*aspectratio), rs.VPHEIGHT_CONST); + System.out.println(width + "x" + height); + System.out.println(aspectratio); + System.out.println(rs.VPHEIGHT_CONST + "x" + rs.VPHEIGHT_CONST*aspectratio); + } + public void initializePlayer() { player = new Entity(); diff --git a/core/src/com/saltosion/gladiator/systems/RenderingSystem.java b/core/src/com/saltosion/gladiator/systems/RenderingSystem.java index cdeac41..12987ea 100644 --- a/core/src/com/saltosion/gladiator/systems/RenderingSystem.java +++ b/core/src/com/saltosion/gladiator/systems/RenderingSystem.java @@ -20,6 +20,7 @@ public class RenderingSystem extends EntitySystem { private SpriteBatch batch; private OrthographicCamera camera; + public final int VPHEIGHT_CONST = 252; @Override public void addedToEngine(Engine engine) { @@ -27,7 +28,11 @@ public class RenderingSystem extends EntitySystem { batch = new SpriteBatch(); camera = new OrthographicCamera(); - camera.setToOrtho(false, 384, 216); + camera.setToOrtho(false, 448, 252); + } + + public void setViewport(int width, int height) { + camera.setToOrtho(false, width, height); } @Override