How to display geometry for few seconds?

I have attached a few geometries to a node that I wish to display on the GUI. I have gotten it to display, except when I try to make it disappear after a few seconds I run into issues.


    StopWatch displayTime = new StopWatch();
    displayTime.start(); //Start the prompt timer.
    while (displayTime.getElapsedTimeSecs() < displayTimeSec) {}  //Default 2 seconds
    displayTime.stop();  //Stop the clock.
    app.getGuiNode().detachAllChildren();   //Clear prompt from display


The objects will display if I only use the first two lines. The StopWatch class just keeps track of time, and I know that works fine because the program does pause for the set time. If I removed the last line, the objects would display after the rest of the code is executed. This is not what I want. I want the objects to appear, have the stopwatch count until the time is up, then the objects to disappear.

Is there a better/easier way for doing this?


Are you doing that in another thread? else your whole app will just freeze in that empty while loop for 2 seconds.

Easiest way is to use the update loop. Something like:

private float counter = 0;
private float isShown = true;

public void update (float tpf) {

counter += tpf;

if (counter >= 2 && isShown) {
isShown = false;

Bonus points if you use an appstate/control and remove it when its not needed anymore.