0
\$\begingroup\$

I have a problem with black screen when switching back to main menu and when opening a screen.

When the game starts, the screen is set to MainMenuScreen. That works. When I select the first menu entry, the screen is set to LoginScreen. Works, too. When I want to go back to MainMenuScreen, the screen becomes black. When I want to switch from LoginScreen to LobbyScreen via Control (see code), the screen remains as it is; the InputProcessor still reacts to LoginScreen, and it doesn't get discarded. When I want to go from MainMenuScreen to LobbyScreen, the screen becomes black.

All screens have the same background with different elements in top of it.

The second problem is, that my font looks absolutely pixelated. Plus, I get problems when starting the program on a different resolution (which means that SCREENWIDTH and SCREENHEIGHT start with different values. Although I place my elements relative to the the screendimension, they get messed up a little. Resizing is no problem though.

For the code, I left out everything that cannot be responsible for causing the problem.

This is the MainMenuScreen

public class MainMenuScreen extends AbstractScreen {

    public MainMenuScreen(FantasticFeastsGame game) {
        super(game);
    }

    void drawAssets() {
        batch.begin();
        batch.draw(assets.background, 0, 0, SCREENWIDTH, SCREENHEIGHT);
        ...
        batch.end();
    }

    void handleInput() {
        ... either 
        game.setScreen(new LoginScreen(game));
        dispose();

        ... or
        game.setScreen(new LobbyScreen(game));
        dispose();
    }
}

This is the LoginScreen

public class LoginScreen extends AbstractScreen {

    private Stage loginStage;

    LoginScreen(FantasticFeastsGame game) {
        super(game);
        loginStage = new Stage();

        loginStage.addActor(new TextField("", assets.skin););
        ....
    }



    @Override
    void drawAssets() {
        batch.begin();
        batch.draw(assets.background, 0, 0, SCREENWIDTH, SCREENHEIGHT);
        font.draw(batch, "Server-IP:", SCREENWIDTH * 0.3f, SCREENHEIGHT * 0.71f);
        ....
        batch.end();

    }

    @Override
    void handleInput() {
        either...
        game.startControl(...);

        or...
        game.setScreen(new MainMenuScreen(game));
        dispose();
    }
}

LobbyScreen:

public class LobbyScreen extends AbstractScreen {

    public LobbyScreen(FantasticFeastsGame _game) {
        super(_game);
    }

    @Override
    void drawAssets() {
        batch.begin();
        batch.draw(assets.background, 0, 0, SCREENWIDTH, SCREENHEIGHT);
        ...
        batch.end();
    }
}

This is the Control:

public class Control implements Runnable{
    ...

    private void isDefinitelyCalledICheckedThat(){
        game.getScreen().dispose();
        game.setScreen(new LobbyScreen(game));
    }
}

void handleInput() {
    ... either 
    game.setScreen(new LoginScreen(game));
    dispose();

    ... or
    game.setScreen(new LobbyScreen(game));
    dispose();
}
\$\endgroup\$
0
\$\begingroup\$

I found part of the solution, one problem was within the Runnable. It crashed silently with java.lang.RuntimeException: No OpenGL context found in the current thread, which could be solved by replacing

private void isDefinitelyCalledICheckedThat(){
    game.getScreen().dispose();
    game.setScreen(new LobbyScreen(game));
}

with

private void isDefinitelyCalledICheckedThat(){
    game.getScreen().setFlag();
}

and letting the recent screen change the context. I figured out, that a call to game.setScreen() cannot be done from non-Libgdx-Classes, at least not from Runnables.

This does not explain though why this piece of code reacts differently.

void handleInput() {
    ... either 
    game.setScreen(new LoginScreen(game));
    dispose();

    ... or
    game.setScreen(new LobbyScreen(game));
    dispose();
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.