Running from local file ⚠️
It seems like you have opened this file by double-clicking on it. In order to test your build in a browser
you need to load this file from a web server. You can either upload this file and the rest of the files from a Defold HTML5 bundle to a web hosting service OR host them using a local web server on your home network.
Learn more about running a local web server in the Defold HTML5 manual. Setup
The setup consists of several collections and game objects.
This is the bootstrap collection specified in
Script that handles loading and unloading of collection proxies Two
Collection proxies referencing the splash screen and a menu collection.
This collection contains a menu. Contains:
GUI with some box and text nodes that acts as buttons.
Collections representing the splash screen.
function init ( self )
msg . post ( "." , "acquire_input_focus" ) -- <1>
msg . post ( "#splashscreenproxy" , "async_load" ) -- <2>
function on_message ( self , message_id , message , sender )
if message_id == hash ( "proxy_loaded" ) then -- <3>
if sender . fragment == hash ( "splashscreenproxy" ) then -- <4>
msg . post ( "#splashscreenproxy" , "enable" ) -- <5>
msg . post ( "#menuproxy" , "async_load" ) -- <6>
self . menu_loading_started_time = os.time () -- <7>
elseif sender . fragment == hash ( "menuproxy" ) then -- <8>
local total_menu_loading_time = os.time () - self . menu_loading_started_time
local minimum_splash_duration = 5
local delay = math.max ( minimum_splash_duration - total_menu_loading_time , 0 ) -- <9>
timer . delay ( delay , false , function () -- <10>
msg . post ( "#splashscreenproxy" , "unload" ) -- <11>
msg . post ( "#menuproxy" , "enable" ) -- <12>
1. Acquire input focus for this game object. This is required for input to be able to propagate into any of the collection proxies on the same game object as this script.
2. Load the splash screen
3. The "proxy_loaded" message is received whenever a collection proxy has been loaded
4. Here we check if it was the splash screen proxy which was loaded
5. Enable the splash screen proxy so that the splash screen is shown
6. Load the menu screen
7. Save the time when the menu screen loading was started
8. Was the menu proxy loaded?
9. Calculate how much longer the splash screen should remain visible, based on how long it took to load the menu
10. Start a timer for the remaining time
11. Unload the splash screen
12. Show the menu
If you want to play with these examples, you can get the project on Github.
Do you want to see more examples? Why not write a few yourself and submit a pull request? We love contributions.