Container for storing and loading of scenes. An instance of the registry is created on the AppBase object as AppBase#scenes.

Constructors

Properties

_app: AppBase
_index: {} = {}

Type declaration

    _list: SceneRegistryItem[] = []
    _urlIndex: {} = {}

    Type declaration

      Methods

      • Private

        Private function to load scene data with the option to cache. This allows us to retain expected behavior of loadSceneSettings and loadSceneHierarchy where they don't store loaded data which may be undesired behavior with projects that have many scenes.

        Parameters

        • sceneItem: string | SceneRegistryItem

          The scene item (which can be found with SceneRegistry#find, URL of the scene file (e.g."scene_id.json") or name of the scene.

        • storeInCache: boolean

          Whether to store the loaded data in the scene item.

        • callback: LoadSceneDataCallback

          The function to call after loading, passed (err, sceneItem) where err is null if no errors occurred.

        Returns void

      • Add a new item to the scene registry.

        Parameters

        • name: string

          The name of the scene.

        • url: string

          The url of the scene file.

        Returns boolean

        Returns true if the scene was successfully added to the registry, false otherwise.

      • Change to a new scene. Calling this function will load the scene data, delete all entities and graph nodes under app.root and load the scene settings and hierarchy.

        Parameters

        • sceneItem: string | SceneRegistryItem

          The scene item (which can be found with SceneRegistry#find, URL of the scene file (e.g."scene_id.json") or name of the scene.

        • Optional callback: ChangeSceneCallback

          The function to call after loading, passed (err, entity) where err is null if no errors occurred.

        Returns void

        Example

        app.scenes.changeScene("Scene Name", function (err, entity) {
        if (!err) {
        // success
        } else {
        // error
        }
        });
      • Load the scene hierarchy and scene settings. This is an internal method used by the AppBase.

        Parameters

        • url: string

          The URL of the scene file.

        • callback: LoadSceneCallback

          The function called after the settings are applied. Passed (err, scene) where err is null if no error occurred and scene is the Scene.

        Returns void

      • Loads and stores the scene data to reduce the number of the network requests when the same scenes are loaded multiple times. Can also be used to load data before calling SceneRegistry#loadSceneHierarchy and SceneRegistry#loadSceneSettings to make scene loading quicker for the user.

        Parameters

        • sceneItem: string | SceneRegistryItem

          The scene item (which can be found with SceneRegistry#find, URL of the scene file (e.g."scene_id.json") or name of the scene.

        • callback: LoadSceneDataCallback

          The function to call after loading, passed (err, sceneItem) where err is null if no errors occurred.

        Returns void

        Example

        const sceneItem = app.scenes.find("Scene Name");
        app.scenes.loadSceneData(sceneItem, function (err, sceneItem) {
        if (err) {
        // error
        }
        });
      • Load a scene file, create and initialize the Entity hierarchy and add the hierarchy to the application root Entity.

        Parameters

        • sceneItem: string | SceneRegistryItem

          The scene item (which can be found with SceneRegistry#find, URL of the scene file (e.g."scene_id.json") or name of the scene.

        • callback: LoadHierarchyCallback

          The function to call after loading, passed (err, entity) where err is null if no errors occurred.

        Returns void

        Example

        const sceneItem = app.scenes.find("Scene Name");
        app.scenes.loadSceneHierarchy(sceneItem, function (err, entity) {
        if (!err) {
        const e = app.root.find("My New Entity");
        } else {
        // error
        }
        });
      • Load a scene file and apply the scene settings to the current scene.

        Parameters

        • sceneItem: string | SceneRegistryItem

          The scene item (which can be found with SceneRegistry#find, URL of the scene file (e.g."scene_id.json") or name of the scene.

        • callback: LoadSettingsCallback

          The function called after the settings are applied. Passed (err) where err is null if no error occurred.

        Returns void

        Example

        const sceneItem = app.scenes.find("Scene Name");
        app.scenes.loadSceneSettings(sceneItem, function (err) {
        if (!err) {
        // success
        } else {
        // error
        }
        });