I am trying to make a game based on a TiledMap (with Camera and Viewport).
My game should be scaled that always the whole screen is filled (no black bars) [like in Banana Kong]. I found the ExtendViewport
which should solve this problem (I think).
After trying lots of things out I don't find the correct solutions for this. Always the map is scaled to small or/and at the wrong position. When I scale the Window on the Computer it should fill in the whole height with the Tiled Map and than fill the whole length of the screen with see drawable part of the TiledMap (with mentioning the Aspect Ratio).
This is my Code so far, how to make it work?
public class LoadingScreen implements Screen {
//Reference to MainGameClass
private MainGameClass game;
//Camera and Viewport
private OrthographicCamera gamecam;
private Viewport gamePort;
//Tiled MaP
private TmxMapLoader maploader;
private TiledMap map;
private OrthogonalTiledMapRenderer renderer;
public LoadingScreen(MainGameClass game) {
this.game = game;
//Camera and Viewport
gamecam = new OrthographicCamera();
gamePort = new ExtendViewport(MainGameClass.WIDTH, MainGameClass.HEIGHT, gamecam);
//Tiledmap
maploader = new TmxMapLoader();
map = maploader.load("MarioBros.tmx");
renderer = new OrthogonalTiledMapRenderer(map, 1);
gamecam.setToOrtho(false);
}
@Override
public void show() {
}
public void update(float dt) {
//gamecam.position.x += 1;
gamecam.update();
renderer.setView(gamecam);
}
@Override
public void render(float delta) {
update(delta);
//Clear Game Screen with black
Gdx.gl.glClearColor(0,0,0,1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
renderer.render();
//Begin GameBatch
game.batch.setProjectionMatrix(gamecam.combined);
}
@Override
public void resize(int width, int height) {
gamePort.update(width,height);
gamecam.setToOrtho(false);
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void hide() {
}
@Override
public void dispose() {
}
}
Hope someone can help
EDIT 1:
The height of the phone should always be filles with the whole level height. Then the length of the map that you see should also always fill the whole screen. So on mobile which are more stretched you can see more of the level, the height of the level is always as high as the phone.
Also when I manually scale the windows on Pc with the mouse the VIew should be updated!
MainGameClass.WIDTH
,HEIGHT
also value of map 'stileWidth
,tileHeight
and map size in tiles ? – Abhishek AryanMainGameClass.WIDTH
andHEIGHT
is constant value ? – Abhishek Aryan