When resizing the window, viewport scales to right size now

This commit is contained in:
Allexit 2015-04-09 00:12:07 +03:00
parent ff859b6501
commit 7907eb348d
2 changed files with 17 additions and 1 deletions

View File

@ -54,6 +54,17 @@ public class GladiatorBrawler extends ApplicationAdapter {
engine.update(Gdx.graphics.getDeltaTime()); 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() { public void initializePlayer() {
player = new Entity(); player = new Entity();

View File

@ -20,6 +20,7 @@ public class RenderingSystem extends EntitySystem {
private SpriteBatch batch; private SpriteBatch batch;
private OrthographicCamera camera; private OrthographicCamera camera;
public final int VPHEIGHT_CONST = 252;
@Override @Override
public void addedToEngine(Engine engine) { public void addedToEngine(Engine engine) {
@ -27,7 +28,11 @@ public class RenderingSystem extends EntitySystem {
batch = new SpriteBatch(); batch = new SpriteBatch();
camera = new OrthographicCamera(); 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 @Override