Skip to main content
Version: 9.0.2

gre.load_resource

gre.load_resource(
pool_name,
resource_name,
[pool parameters]
)

This function will force the loading of a resource, such as an image or font, into the Storyboard application. This can be used in order to avoid load time delays that may be incurred as resources are lazy loaded into the application.

This call can only be made from the main Lua action execution thread.

Parameters

ParameterTypeDescription
pool_name#stringThe name of the resource pool: image or font
resource_name `#stringThe name of the resource that is to be loaded
options#tableA table of options that vary depending on the resource pool. See Image Pool Options and Font Pool Options

The optional parameters vary depending on the pool being specified may not be required:

Image Pool Options

KeyTypeDescription
w#numberThe width to cache the image at
h#numberThe height to cache the image at
background#booleanWhether or not to load the image asynchronously in the 'background'. Asynchronous loading capabilities are determined by the hardware rendering capabilities of the system and may require serialization with the main rendering thread for a complete load to occur.

Font Pool Options

KeyTypeDescription
size#numberThe point size of the font to load (required)
antialias#booleanA flag indicating if anti-aliasing is to be used These options should be passed as a table as the third parameter to ensure that the loader receives the appropriate values. On completion of a 'background' loaded resource, the following event is sent: gre.resource_loaded 1s0 resource

Example

-- Call this to pre-load the image and font into the cache
function on_app_init(mapargs)
-- Call this to pre-load a font at a 24pt size
local opt = {}
opt.size = 24
gre.load_resource("font", "fonts/DejaVu.ttf", opt)

-- Call this to pre-load the image unscaled
gre.load_resource("image", "images/tree.jpg")

-- Call this to pre-load the image and scale it to 100x100
local opt = {}
opt.w = 100
opt.h = 100
gre.load_resource("image", "images/scaledtree.jpg", opt)

-- Call this to pre-load the image and scale it to 100x100 asynchronously
local opt = {}
opt.w = 100
opt.h = 100
opt.background = 1
gre.load_resource("image", "images/scaledtreebg.jpg", opt)
end