natiny.resource.load_async

Lua
natiny.resource.load_async(path, callback)

Asynchronously loads a resource out of the mounted folders, or from disk (the network on web) when no mount holds it. The callback fires when loading completes.

Parameters

Name Type Description
path string Name of the file inside a mounted folder, such as "textures/hero.png"
callback function function(resource) called on completion

Callback

The callback receives one argument: - resource - loaded resource handle, or nil on failure.

Example

Lua
natiny.resource.load_async("textures/hero.png", function(resource)
    if resource then
        tex = natiny.texture.create(resource)
    else
        print("Failed to load texture!")
    end
end)

Notes

  • On the web this is the call that pays off: packs fetched here are kept in the browser's IndexedDB under a key carrying their hash, so a returning player downloads nothing that has not changed. The synchronous natiny.resource.load cannot reach that store and goes to the network.