Resource

Namespace: resource Language: Lua Type: Defold Lua File: script_resource.cpp Source: engine/gamesys/src/gamesys/scripts/script_resource.cpp

Functions and constants to access resources.

API

resource.atlas

Type: FUNCTION Constructor-like function with two purposes:

Load the specified resource as part of loading the script Return a hash to the run-time version of the resource

This function can only be called within go.property function calls.

Parameters

Returns

Examples

Load an atlas and set it to a sprite:

go.property("my_atlas", resource.atlas("/atlas.atlas"))
function init(self)
  go.set("#sprite", "image", self.my_atlas)
end

Load an atlas and set it to a gui:

go.property("my_atlas", resource.atlas("/atlas.atlas"))
function init(self)
  go.set("#gui", "textures", self.my_atlas, {key = "my_atlas"})
end

resource.buffer

Type: FUNCTION Constructor-like function with two purposes:

Load the specified resource as part of loading the script Return a hash to the run-time version of the resource

This function can only be called within go.property function calls.

Parameters

Returns

Examples

Set a unique buffer it to a sprite:

go.property("my_buffer", resource.buffer("/cube.buffer"))
function init(self)
  go.set("#mesh", "vertices", self.my_buffer)
end

resource.create_atlas

Type: FUNCTION This function creates a new atlas resource that can be used in the same way as any atlas created during build time. The path used for creating the atlas must be unique, trying to create a resource at a path that is already registered will trigger an error. If the intention is to instead modify an existing atlas, use the resource.set_atlas function. Also note that the path to the new atlas resource must have a ‘.texturesetc’ extension, meaning “/path/my_atlas” is not a valid path but “/path/my_atlas.texturesetc” is. When creating the atlas, at least one geometry and one animation is required, and an error will be raised if these requirements are not met. A reference to the resource will be held by the collection that created the resource and will automatically be released when that collection is destroyed. Note that releasing a resource essentially means decreasing the reference count of that resource, and not necessarily that it will be deleted.

Notes

Parameters