Ok I can't figure this out for the life of me. I have a game class
public class MyKoalabr8 extends Game {
@Override
public void create () {
setScreen(new MainMenuScreen(this));
}
}
this sets the mainmenuscreen
public class MainMenuScreen implements Screen {
private Viewport viewport;
private Stage stage;
private MyKoalabr8 game;
public MainMenuScreen(MyKoalabr8 game){
this.game = game;
viewport = new FitViewport(MyKoalabr8.V_WIDTH, MyKoalabr8.V_HEIGHT, new OrthographicCamera());
stage = new Stage(viewport, (game).batch);
Label.LabelStyle font = new Label.LabelStyle(new BitmapFont(), Color.WHITE);
Table table = new Table();
table.center();
table.setFillParent(true);
Label gameOverLabel = new Label("Play", font);
table.add(gameOverLabel).expandX();
table.row();
stage.addActor(table);
}
@Override
public void render(float delta) {
if(Gdx.input.justTouched()) {
System.out.println("changing screen");
game.setScreen(new GameScreen(game));
dispose();
}
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.draw();
}
}
All this class does is when a user click it will set the screen to GameScreen However in my gamescreen I have a TMX map and for some reason it doesn't render the map unless I resize the window
public GameScreen(MyKoalabr8 game) {
this.game = game;
camera = new OrthographicCamera();
gamePort = new FitViewport((MyKoalabr8.V_WIDTH / MyKoalabr8.PPM), (MyKoalabr8.V_HEIGHT / MyKoalabr8.PPM), camera);
gamePort.setWorldSize((MyKoalabr8.V_WIDTH / MyKoalabr8.PPM), (MyKoalabr8.V_HEIGHT / MyKoalabr8.PPM));
gamePort.apply();
maploader = new TmxMapLoader();
map = maploader.load("level1.tmx");
renderer = new OrthogonalTiledMapRenderer(map, 1 / MyKoalabr8.PPM);
camera.position.set(gamePort.getWorldWidth() / 2, gamePort.getWorldHeight() / 2, 0);
world = new World(new Vector2(0, 0), true);
new B2WorldCreator(world, map);
}
public void update(float dt) {
world.step(1 / 60f, 6, 2);
camera.update();
renderer.setView(camera);
}
@Override
public void render(float delta) {
update(delta);
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
renderer.render();
game.batch.setProjectionMatrix(camera.combined);
game.batch.begin();
game.batch.end();
}
https://gyazo.com/19089bfeb7ee8a1b483a819ac9d2283c Please help I have no clue why this is broken
Another solution that works is if I outright set the GameScreen as the screen
public class MyKoalabr8 extends Game {
@Override
public void create () {
setScreen(new GameScreen(this));
}
}
If I do this it works fine.