0 votes

I've been struggling for a while with setting up a loading screen for when the game is running a somewhat heavy algorithm. I know that this algorithm can take upwards of 10 seconds, and I decided to put a loading screen there.

It's something like this:

var loading = preload("path to loading scene")

func game():
    loading_scene = loading.instance
    #yield(get_tree().create_timer(0.5), "timeout")

As it is now, the loading will happen without the loading screen ever appearing. If I uncomment the yield line, the loading screen appears. I think what is happening here is the scene is only updated once the script completes, unless there is some sort of break (yield) mid way.

This workaround, though not ideal, should have worked, if not for the fact that it will also interrupt any animation. My loading screen consists of a rotating icon, if I uncomment the animation line, the animation will play for the time it takes for yield to finish. When it hits the algorithm, the animation freezes. The game progresses as normal once the algorithm completes, but I have no idea how I can just have the loading animation play while an algorithm is occurring in the background.

in Engine by (251 points)

1 Answer

0 votes

Not sure about how well it will work, but do the heavy calculation on a different thread, not on the main one, that way you can do a lot of calculations without affecting the main loop too much

Threading in Godot:

by (1,193 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.