Search code examples
javaopengllibgdxwindows-10

LibGDX issue setting black screen and showing white text


I'm having an issue with LibGDX.

I followed their guide on GitHub and then i went ahead modifying the game. (Ref: https://github.com/libgdx/libgdx/wiki/A-simple-game)

I wanted to create a game over screen when the drop touched the ground 3 times. When it touches the ground for the 3rd time, i set lost to true, and at the start of the render() method i check if lost is true.

This is the contenent:

        if(lost){
        bucket.dispose();
        lostSound.play();
        sprite.setProjectionMatrix(camera.combined);
        Gdx.gl.glClearColor(0,0,0,0);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        drop.dispose();
        font.setColor(Color.WHITE);
        GlyphLayout layout = new GlyphLayout(font, "Game Over!");
        int fontX = 800 + 64 / 2;
        int fontY = 480 / 2;
        sprite.begin();
        font.draw(sprite, layout, fontX, fontY);
        sprite.end();
        return;
    }

The lostSound is sorta bugged, it repeats his start at the infinite, and i get a black screen without any Game Over text.

EDIT: If i run via command line i don't get any exceptions


Solution

  • If I'm not wrong every loop you are entering in lost condition, so the sound is playing every loop, add a flag like gameover=true for not entering again in the main loop. Also, which is your game resolution? If you want half of 864 (if is maximum resolution), center of X, you must do fontX= (800+64)/2 (432) instead of fontX= 800+64 /2 (832)

    Hope it helps