Can someone show me an example code for a background loader please

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Newby

i have been asking for an answer but they just keep telling me to go to the docs.godotengine for the tutorial but i dont really undrstand it. i know how to switch scenes but i dont know how to make the loading screen wait till the scene switching is done is it the poll that tells when the loading is finished or ResourceLoader. if you have an answer please explain it a bit im still pretty new to godot. Been learning for a few months now

:bust_in_silhouette: Reply From: coffeeDragon

Look at GitHub - godotengine/godot-demo-projects: Demonstration and Template Projects under /misc/threads

it not really what i need my game has many scenes. i want it so when you click on a level or finish one it will play the loading screen and load the next scene

Newby | 2018-04-25 07:00

:bust_in_silhouette: Reply From: Diet Estus

You ask:

Is it the poll that tells when the loading is finished or ResourceLoader?

poll() is a method of the ResourceLoader. You call poll() on the ResourceLoader to check the status of the load. Depending on what it returns, you either keep polling (if it’s not done), or stop polling and get the fully-loaded resource (if it’s done).

Usually, you’d make this call and do these checks in the _process() method of some kind of global singleton that is handling all your scene changes. While you are making these calls of poll() on the ResourceLoader, you display your loading animation (which you can build right into the singleton). If and when ResourceLoader.poll() == ERR_FILE_EOF, the load is done. You can access the loaded scene resource using ResourceLoader.get_resource(). Instance that scene resource, add it to the tree, and stop your loading animation. Voila!

I suspect your problem might be that you are not using a global singleton to handle your scene changes. Rather, you are trying to change from one scene to a loading animation, then to another scene. If this is indeed what you’re doing, consider learning about singletons. They are extremely useful for scene management.

is the code for background loading copy-paste-able in the Background loading — Godot Engine (stable) documentation in English
also how do you call the functions from the autoload

Newby | 2018-04-25 10:37

Not really. You’ll notice that that code references an “animation” node and a “progress” node. As such, that tutorial presupposes a certain structure of the scene management singleton (with an animation and progress node used for the loading animation). You may be able to copy and paste chunks of it though.

Diet Estus | 2018-04-25 10:44

so just say it does work how do i call it functions to get a new scene
cause currently my scenes just change with no loading animation so the screen just lags till the next scene is loaded

Newby | 2018-04-25 13:17