Loader

The Loader module is responsible for loading additional resources into the engine.

Usage

To use this module, add the following require at the top of your script:

local Loader = require 'engine/loader'

Reference

loader.getItemCountToLoad()

Return how many items are currently beeing loaded

Returns:

item count

Return type:

number

loader.loadImage(path, options.flipY, options.waitUntilFinished)

Loads an image from an item by its relative path

Parameters:
  • path (str) – relative path to the image file inside the project i.e. (“/resources/textures/tex1”)

  • options.flipY (boolean) – if set to true, image will be flipped. for canvas rendering this should be set to false. default = true

  • options.waitUntilFinished (boolean) – if set to true, the promise will only fulfil as soon as the texture is fully loaded. default = false

Returns:

returns a promise that will deliver a Texture object

Return type:

Promise

loader.loadMaterial(path, options.waitUntilFinished)

Loads a material by path and will emit an loadMaterialResult event when the material is ready or loadMaterialError event on error

Parameters:
  • path (str) – relative path to the material item inside the project i.e. (“/resources/materials/mat1”)

  • options.waitUntilFinished (boolean) – if set to true, the promise will only fulfil as soon as the material is fully loaded. default = false

Returns:

returns a promise that will deliver a Material object

Return type:

Promise

loader.loadMesh(path, options.waitUntilFinished)

Loads a mesh from an item by its relative path.

Parameters:
  • path (str) – relative path to the mesh item inside the project i.e. (“/resources/meshes/mesh1”)

  • options.waitUntilFinished (boolean) – if set to true, the promise will only fulfil as soon as the mesh is fully loaded. default = false

Returns:

returns a promise that will deliver a Mesh object

Return type:

Promise

loader.loadPrefab(path, options.waitUntilFinished)

Loads a prefab from an item by its relative path.

Parameters:
  • path (str) – relative path to the prefab item inside the project i.e. (“/resources/meshes/prefab1”)

  • options.waitUntilFinished (boolean) – if set to true, the promise will only fulfil as soon as the prefab is fully loaded. default = false

Returns:

returns a promise that will deliver a Prefab object

Return type:

Promise

loader.loadGridMap(path, options.waitUntilFinished)

Loads a gridmap from an item by its relative path.

Parameters:
  • path (str) – relative path to the gridmap item inside the project i.e. (“/resources/gridmaps/gridmap1”)

  • options.waitUntilFinished (boolean) – if set to true, the promise will only fulfil as soon as the gridmap is fully loaded. default = false

Returns:

returns a promise that will deliver a GridMap object

Return type:

Promise

loader.loadFont(path, options.waitUntilFinished)

Loads a font from an item by its relative path. Once this is loaded, it can be instantly used in canvas by its name


for example Canvas.setFont(“20px font1”)

Parameters:
  • path (str) – relative path to the font item inside the project i.e. (“/resources/fonts/font1”)

  • options.waitUntilFinished (boolean) – if set to true, the promise will only fulfil as soon as the font is fully loaded. default = false

Returns:

returns a promise that will deliver a Font object

Return type:

Promise

Examples

Load a texture
local Loader = require 'engine/loader'

function init()
    Loader.loadImage("/resources/textures/mytexture"):next(function(texture)
        print("Loaded the texture: ", texture:getName())
    end)
end