Loading Screen
In nanos world it is possible to add a customized and dynamic Loading Screen to your Server using WebUI.
Creating a Loading Screenβ
For that, you will need to create a new Package of type loading-screen, and add your HTML/CSS/JS files into the Package's root folder. Your primary HTML file should be called index.html
. It will look like that:
Packages/
βββ my-loading-screen/
βββ Package.toml
βββ index.html
βββ style.css
βββ ...
Getting Load/Download Progressβ
To be able to display dynamic information in the screen, you can listen to the Event UpdateScreen
(which will trigger every few ms):
Event UpdateScreen
β
Parameter | Description |
---|---|
message | Display the current state (loading, validating, downloading...) |
message_secondary | Display the current asset/file being loaded or downloaded |
progress_small | Current small progress |
progress_small_total | Max small progress |
progress | Current progress |
progress_total | Max progress value |
current_stage | The current stage of the load (loading , downloading ) |
Events.Subscribe("UpdateScreen", function(message, message_secondary, progress_small, progress_small_total, progress, progress_total, current_stage) {
// Update your HTML here
});
You can use progress
and progress_total
for filling up the main loading bar, and progress_small
for a small/sub loading bar.
Always use progress / progress_total
for getting the current %
percentage, as progress_total can represent the total amount of files being downloaded for example.
Player Informationβ
Also, it is possible to fetch Playerβs information by accessing a global variable called LoadingScreen:
var LoadingScreen = {
server_ip,
server_name,
server_description,
server_port,
player_nanos_id,
player_nanos_username
};
Stop Menu Musicβ
It is possible to turn off the built-in menu music by calling an event from Loading Screen JS:
Events.Call("StopMenuMusic")
Configuring your server to use the Loading Screenβ
After creating your loading-screen package, you will need to configure your server to load it in your Config.toml. Just set the setting loading_screen
to your Package's folder name.
# loading-screen package to load (the loading screen will be displayed when players join your server)
loading_screen = "my-loading-screen"
Or start it with --loading_screen "my-loading-screen"
.