Skip to content

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

getItemCountToLoad

static getItemCountToLoad()

Return how many items are currently beeing loaded

Returns

  • number: count

loadImage

static loadImage(path, options)

Loads an image from an item by its relative path

Parameters

  • path (string): relative path to the image file inside the project i.e. ("/resources/textures/tex1")
  • options: object with the following keys:
    • flipY (boolean): if set to true, image will be flipped. for canvas rendering this should be set to false. default = true
    • waitUntilFinished (boolean): if set to true, the promise will only fulfil as soon as the texture is fully loaded. default = false

Returns

  • Promise: a promise that will deliver a Texture object

loadMaterial

static loadMaterial(path, options)

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

Parameters

  • path (string): relative path to the material item inside the project i.e. ("/resources/materials/mat1")
  • options: object with the following keys:
    • waitUntilFinished (boolean): if set to true, the promise will only fulfil as soon as the material is fully loaded. default = false

Returns

  • Promise: a promise that will deliver a Material object

loadMesh

static loadMesh(path, options)

Loads a mesh from an item by its relative path.

Parameters

  • path (string): relative path to the mesh item inside the project i.e. ("/resources/meshes/mesh1")
  • options: object with the following keys:
    • waitUntilFinished (boolean): if set to true, the promise will only fulfil as soon as the mesh is fully loaded. default = false

Returns

  • Promise: a promise that will deliver a Mesh object

loadPrefab

static loadPrefab(path, options)

Loads a prefab from an item by its relative path.

Parameters

  • path (string): relative path to the prefab item inside the project i.e. ("/resources/meshes/prefab1")
  • options: object with the following keys:
    • waitUntilFinished (boolean): if set to true, the promise will only fulfil as soon as the prefab is fully loaded. default = false

Returns

  • Promise: a promise that will deliver a Prefab object

loadGridMap

static loadGridMap(path, options)

Loads a gridmap from an item by its relative path.

Parameters

  • path (string): relative path to the gridmap item inside the project i.e. ("/resources/gridmaps/gridmap1")
  • options: object with the following keys:
    • waitUntilFinished (boolean): if set to true, the promise will only fulfil as soon as the gridmap is fully loaded. default = false

Returns

  • Promise: a promise that will deliver a GridMap object

loadFont

static loadFont(path, options)

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 (string): relative path to the font item inside the project i.e. ("/resources/fonts/font1")
  • options: object with the following keys:
    • waitUntilFinished (boolean): if set to true, the promise will only fulfil as soon as the font is fully loaded. default = false

Returns

  • Promise: a promise that will deliver a Font object

Examples

local Loader = require 'engine/loader'

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