Best way to dynamically load assets

Does defold support dynamically loading assets? I intend to use quite a few really hi-res graphics (4k graphics) for my next game (I have to use hi-res since svg isn’t supported), and I would like a better loading system than just a ten-second lag on program launch.
Thanks!

1 Like

Yes! Live update is what you’re looking for:

I used it in an HTML5 game, it worked great. For apps you have to store the content on a server, all explained in the docs above.

4 Likes

Can I self-host instead of using AWS?

Which platform(s) are you targetting?

1 Like

Desktop and mobile (not web, but dealing with large number of massive assets)

For desktop you might be able to store them locally, but not sure if that makes sense. For mobile I believe the only option is AWS.

1 Like

zip isn’t supported on mobile?

You can self host your files on any file server (not just AWS).

Not sure what other users use though. @pkeod @agulev, do you have any suggestions?

1 Like

how do I do that? is there a hidden “other” option in live update?

You export to “.zip” as you mentioned.
Then (regardless of AWS or not), you will need to load these files from a file server. The .zip contains the files that the live update will request later on.

1 Like

You can try it with a local python server, e.g. “python m SimpleHTTPServer”, which will give you a file server (from the current directory), at “http://localhost:8000

1 Like

I think there was a misunderstanding in the original post. @Griffin is not needing live update features but instead needing to use collection proxies to not load everything at once. https://defold.com/manuals/collection-proxy/

Use Monarch and only reference the atlases you need on the screens they are mentioned on. This makes it easy for general assets, you load between screens.

We have 50+ location backgrounds often in our games, these are loaded and unloaded dynamically with collection proxies too. So max there are 2 loaded at once and they are usually swapped between screens.

What do you mean by 4k graphics? You should know that max texture size matters a lot especially on mobile you should try to keep atlases at least below 2048, but even targeting 1024 is also a good idea. This can be done with texture profiles.

9 Likes

Is there also a way to download and load assets from a url? Or will I have to make an atlas with a 1x1 image of every single hexadecimal color and make my own encoder with an absolutely ridiculous quantity of gui nodes?

You can download images from the net and set their textures to nodes. For other assets, you can download them too, and as long as you have a way to make them useful, you can use them.

Here’s a bare bones example of downloading an image and setting it on a node.

http.request(url, "GET", function(self, id, response)
	if response.status ~= 200 and response.status ~= 304 then
		print("Couldn't access URL of image")
	else
		local downloaded_image = image.load(response.response)
		if not downloaded_image then return nil, "Failed to load image" end
		
		gui.new_texture(url, downloaded_image.width, downloaded_image.height, downloaded_image.type, downloaded_image.buffer)
		gui.set_texture_data(url, downloaded_image.width, downloaded_image.height, downloaded_image.type, downloaded_image.buffer)
		gui.set_texture(my_node, url)
	end
end, nil, nil, {timeout = 0.75})

Typically if you want to download resources like this you will also want to cache them to disk and use their cached versions based on a file manifest so you do not waste your user’s bandwidth. I’ll post an example of how to do this sometime in the future.

5 Likes

Sorry to necro this thread but would you still be up for doing this, @Pkeod ? :sweat_smile:

Or maybe someone knows an example of this that already exists!

I’m personally looking for a solution that would work on HTML5.

1 Like

Maybe this is what you are looking for - Use Live Update to improve load speed of HTML5 game

3 Likes