LIBGDX - refresh the screen

Viewed 203

I create the code that when you press the buttons you jump to the website you put in the code. And I want to classify them like this screen is for school and the other one is for hobby. However when i run it, it automatically ends. I searched for solution and I find out that refresh the screen would be the solution. If possible can someone tell me the way to clear screen.

this is the first time I ask question in such website so I don't know that should i put the code with it or not whether it is so long...sorry

public PlayState(GameStateManager gsm) {
    super(gsm);
    button = new Buttons();
    font = new BitmapFont();
    img = new Texture("sq.jpg");

}

@Override
protected void handleInput() {
}

@Override
public void update(float dt) {
    handleInput();
    button.update();

}

@Override
public void render(SpriteBatch sb) {
    Gdx.gl.glClearColor(100f, 100f, 100f,1.0f);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    Buttons.setUp(sb, font, img, gsm);
    sb.draw(img, 170, 700, 180, 140);
    font.draw(sb, "to hobby", 225, 705);

}

@Override
public void dispose() {

}

}

@Override
public void create () {

}

public static void setUp(SpriteBatch sb, BitmapFont font, Texture img, GameStateManager gsm)
{
 sb.begin();
    sb.draw(img, -10, 700, 180, 140);
    font.draw(sb, "Math textbook", 35, 705);

    if(Gdx.input.isButtonJustPressed(Input.Buttons.LEFT)){
        if((Gdx.input.getX() > 17 && Gdx.input.getX() < 135) && (Gdx.input.getY() > 27 && Gdx.input.getY() < 113)){
            Gdx.net.openURI("https://www.pearsonactivelearn.com/app/library/ebook?id=OTEzNDY1fGJvb2t8MTE2fDA=");
        }
    }

    if(Gdx.input.isButtonJustPressed(Input.Buttons.LEFT)){
        if((Gdx.input.getX() > 197 && Gdx.input.getX() < 315) && (Gdx.input.getY() > 27 && Gdx.input.getY() < 113)){
            gsm.set(new SecoundPlayState(gsm));

        }
    }

    sb.draw(img, 350, 700, 180, 140);
    font.draw(sb, "Anime", 390, 705);
    if(Gdx.input.isButtonJustPressed(Input.Buttons.LEFT)){
        if((Gdx.input.getX() > 377 && Gdx.input.getX() < 495) && (Gdx.input.getY() > 27 && Gdx.input.getY() < 113)){
            Gdx.net.openURI("https://kissanime.nz/kissanime-home.html");
        }
    }

    sb.draw(img, -10, 550, 180, 140);
    font.draw(sb, "Google Classroom", 35, 555);
    if(Gdx.input.isButtonJustPressed(Input.Buttons.LEFT)){
        if((Gdx.input.getX() > 17 && Gdx.input.getX() < 135) && (Gdx.input.getY() > 179 && Gdx.input.getY() < 265)){
            Gdx.net.openURI("https://classroom.google.com/u/4/h");
        }
    }

    sb.draw(img, 170, 550, 180, 140);
    font.draw(sb, "Twitter", 225, 555);
    if(Gdx.input.isButtonJustPressed(Input.Buttons.LEFT)){
        if((Gdx.input.getX() > 197 && Gdx.input.getX() < 315) && (Gdx.input.getY() > 179 && Gdx.input.getY() < 265)){
            Gdx.net.openURI("https://twitter.com/home");
        }
    }
    sb.draw(img, 350, 550, 180, 140);
    font.draw(sb, "Manage Bac", 390, 555);
    if(Gdx.input.isButtonJustPressed(Input.Buttons.LEFT)){
        if((Gdx.input.getX() > 377 && Gdx.input.getX() < 495) && (Gdx.input.getY() > 179 && Gdx.input.getY() < 265)){
            Gdx.net.openURI("https://isaaugsburg.managebac.com/student");
        }
    }

    sb.draw(img, -10, 400, 180, 140);
    font.draw(sb, "Pamoja", 35, 405);
    if(Gdx.input.isButtonJustPressed(Input.Buttons.LEFT)){
        if((Gdx.input.getX() > 17 && Gdx.input.getX() < 135) && (Gdx.input.getY() > 331 && Gdx.input.getY() < 417)){
            Gdx.net.openURI("https://learn.pamojaeducation.com/");
        }
    }

    sb.draw(img, 170, 400, 180, 140);
    font.draw(sb, "HackerRank", 225, 405);

    if(Gdx.input.isButtonJustPressed(Input.Buttons.LEFT)){
        if((Gdx.input.getX() > 197 && Gdx.input.getX() < 315) && (Gdx.input.getY() > 331 && Gdx.input.getY() < 417)){
            Gdx.net.openURI("https://www.hackerrank.com/");
        }
    }

    sb.end();

}

@Override
public void render () {

}

@Override
public void dispose () {
    batch.dispose();
}

public void update() {
}

}

1 Answers

Your render method already does clear the screen (about 60 times per second):

@Override
public void render(SpriteBatch sb) {
    Gdx.gl.glClearColor(100f, 100f, 100f,1.0f);//sets the clear color to gray
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);// CLEARS THE SCREEN
    Buttons.setUp(sb, font, img, gsm);
    sb.draw(img, 170, 700, 180, 140);//draws the button again
    font.draw(sb, "to hobby", 225, 705);//draws the text on the button again

}

So the problem probably is something else. It's probably a good idea to create a new question to find the cause of the problem (include a description of what happens when "it automatically ends", exceptions or errors that are shown in the console output, and if possible a minimal reproducable example)

Related