0
\$\begingroup\$

I'm currently developing an app Scene2D that involves a small number of screen switches. I am having a problem that after calling set screen there appears to be a pause of a second or two (I think it's the non UI logic is being performed in the new screen constructor to aid setting up UI actors), which is fine. But during that second pause. It appears my second screen is already running in the background but not being rendered. I think this is happening because of two problems:

  • Animations and Actions that are supposed to begin when the second screen loads are already one or two seconds in progress by the time the second screen loads.

  • During the pause before the second screen loads, the first screen is still rendered in freeze frame, but any user input is queued and processed in the second screen after it renders! Meaning that the user is effectively clicking on things that are not yet rendered which can cause some problems for their experience.

I already am setting the input processor in the show method but it show appears to be called before the screen is actually visible and rendering frames.

Is there something I have misunderstood about the life cycle? Or common pitfalls I may have fallen into? Only a problem on Android, Desktop is fine but possibly only because the loading times are too fast to notice either problem.

\$\endgroup\$
1
  • \$\begingroup\$ Like Sebastien said, just set a flag. When you're done loading the stage UI stuff, set that flag to true, and only then start updating/rendering. Sounds like you're loading stuff and starting them at the same time. \$\endgroup\$
    – Eric
    Commented Mar 6, 2017 at 18:26

2 Answers 2

0
\$\begingroup\$

Your suggestions are right.

You should try something like this :

// In init
boolean rendering = false;

And in your render method

// In render loop
if (!rendering)
{
    rendering = true;
    /* Do your stuff that should be on done on first rendering, 
    like setInputProcessor, add animations etc /*
}

The flag is just to do everything once. I think this might work, give it a try

\$\endgroup\$
0
\$\begingroup\$

Can you tell which screen should be drawn next? If you want to draw a pause menu, you should load it at the creation of you game screen as the pause menu could be pressed often and you dont want to load 1/2 seconds each time.

I think a better option than the mentioned above looks like this: You do create everything in the cunstructor and on the very end you add the logic than should only happen if you can actually see it (the 1/2 seconds after the start of the new screen)

This avoids checking a boolean each frame.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .