Splash spinner stops before collection is unloaded (solved)

Hi there,

I made a splash screen based on this example: Splash
Since I load a large model, it can take some time before the game starts, so I added a spinner to indicate the app is running, based on this example: Spinner animation

My test spinner stops before the splash screen is fully unloaded:


Would it be possible to make it spin longer, ideally until the splash screen is fully unloaded?

This is my code for the loader.script:

function init(self)
	msg.post(".", "acquire_input_focus")
	msg.post("#splashproxy", "async_load")
end

function on_message(self, message_id, message, sender)
	if message_id == hash("proxy_loaded") then 
		if sender.fragment == hash("splashproxy") then 
			msg.post("#splashproxy", "enable") 
			msg.post("#gameproxy", "async_load") 
			self.game_loading_started_time = os.time() 
		elseif sender.fragment == hash("gameproxy") then 
			local total_game_loading_time = os.time() - self.game_loading_started_time
			local minimum_splash_duration = 3
			-- local minimum_splash_duration = 0
			local delay = math.max(minimum_splash_duration - total_game_loading_time, 0)
			timer.delay(delay, false, function() 
				msg.post("#splashproxy", "unload") 
				msg.post("#gameproxy", "enable")
			end)
		end
	end
end

And this for the splash.gui_script:

local spinner
local t
local speed

function init(self)
	spinner = gui.get_node("spinner")
	t = 0
	speed = 16 
end

function update(self, dt)
	t = t + dt
	local step = math.floor(t * speed)
	local angle = math.pi / 6 * step
	local rot = vmath.quat_rotation_z(-angle)
	gui.set_rotation(spinner,rot)
end

If someone could help me with this, I’d be very grateful.

I would use gui.animate for this. This should be an endless loop:

gui.animate(gui.get_node("spinner"), "rotation.z", -360, gui.EASING_LINEAR, 1, 0, nil, gui.PLAYBACK_LOOP_FORWARD)

Not sure why yours is stopping though.

3 Likes

Thank you Alex!
I just added a second spinner. One uses gui.set_rotation and one gui.animate. Both spin happily along and then stop, exactly at the same point and both before the splash is unloaded. :thinking:

EDIT:
tried the same with a sprite instead of a gui, same thing.

Fairly confident then that it’s nothing to do with how and what is rotated, but rather something with the loading of the proxies. I don’t know what though!

1 Like

Makes two of us then :laughing:

If you really want to figure it out, you can use socket.gettime() to get millisecond-accurate times. I would print that in your spinner update and final, and also when your game proxy is loaded, and maybe some other times, to see where exactly the delay is happening. It seems like the splash proxy is ceasing to get updates before it’s actually removed.

But I would also try not using a proxy for the splash screen. Just put it in your bootstrap collection and delete it when loading is done. Maybe that will be better.

Or another quick thing to test would be to unload the splash proxy after enabling the game proxy.

1 Like

Great idea!

Thank you, Ross ! I’ll try these suggestions and see how it goes.

2 Likes

I have meanwhile found the culprit after having had a look at the times. The app actually freezes between the message to enable the game proxy and the game starting to run. With the help of @ross.grams, I, well he, found the reason for this: it’s because I dynamically load a large amount of textures for my models in the init function of my game script.
So, nothing wrong with the code above, it’s my texture loading which I rewrite just now.

2 Likes