0
\$\begingroup\$

I have successfully developed a 2D game. I display sequential introduction images then load the start screen after that of course I load the game level in a single thread, it is a basic functional game. however the game lacks the loading screen and I lack the experience and idea to create one. I made a research in this and found several different approaches.

From my web searches I deduced that I should implement another thread to display the loading screen until the game thread finishes loading its content.

What are the best practices?

\$\endgroup\$
4
  • \$\begingroup\$ It sounds like you understand what you need to do. What step are you stuck on at present? \$\endgroup\$
    – DMGregory
    Commented Oct 26, 2021 at 1:20
  • \$\begingroup\$ @DMGregory nothing yet really, I am at the planning stage as of now. I will implement the loading screen on my next game project. \$\endgroup\$
    – D.elp
    Commented Oct 26, 2021 at 10:44
  • 1
    \$\begingroup\$ You should generally wait until you've made an attempt at a feature or at least a rough test before asking here. That experience will help you focus your question on the parts you need help with, so we don't waste time telling you stuff you can already figure out just fine. \$\endgroup\$
    – DMGregory
    Commented Oct 26, 2021 at 11:46
  • \$\begingroup\$ @DMGregory Thank you. Next time I will make sure to follow your advice :) \$\endgroup\$
    – D.elp
    Commented Oct 26, 2021 at 18:14

1 Answer 1

2
\$\begingroup\$

Although in some contexts it is nice to have have another thread for this, you do not need a second thread.

You can get away with using only one thread:

  1. create some kind of graphical animation looping mechanism, based on "time" (e.g. the looping "loading" animation has 8 frames, make this loop 2 times per second, this will make it 16 fps, )
  2. allow this looping mechanism to fire the rendering of the screen
  3. when you start loading, cover up the screen with whatever "loading" image you want, and display your "looping/loading" animation
  4. then periodically, when you load stuff, poke the "looping/loading" animation mechanism; if the previous poke occurred in the last 1/16th of a second, no need to re-render, if it occurred earlier than this, check how long it's been and display the appropriate animation frame.

This method has the advantage that, well, it's single threaded, so you know exactly what happens when it happens, but it has the inconvenience that the loading/looping animation may not be as smooth as it could be as it could sometimes skip frames, and you have to change the code that loads stuff to allow the poking.

\$\endgroup\$
3
  • \$\begingroup\$ I am a fan of original resident evil series. I noticed that the remake of resident evil has a problematic loading screens on PS4, the loading screen percentage lingers at 10 percent until just prior starting the game it reaches to 100 percent and the game starts, why do you think this could happen, could this be because of a single threaded loading screen? \$\endgroup\$
    – D.elp
    Commented Oct 26, 2021 at 10:57
  • 1
    \$\begingroup\$ I don't remember how it was done in the original Resident Evil series. If you want to know how to reproduce exactly just that, then you should probably edit your question and detail what you're after. Keep this in mind though: often, games were released only on one type of console, and the game being on a console, the developers used very specific hardware, and so it was much easier to achieve a "constant" progression because they knew exactly how long each operation would take, and so it was easier for them to make sure that not more than X amount of work was done per frame. \$\endgroup\$
    – Vaillancourt
    Commented Oct 26, 2021 at 12:14
  • \$\begingroup\$ Not really, After reading your answer I thought of that example from resident evil. \$\endgroup\$
    – D.elp
    Commented Oct 26, 2021 at 18:17

You must log in to answer this question.

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