melonJS
    Preparing search index...

    Function load

    • load a level into the game manager, and return a promise that settles once it is actually in the world
      (will also create all level defined entities, etc..)

      options.onLoaded still fires, so the two forms mix freely. An unknown levelId throws SYNCHRONOUSLY rather than rejecting — that is a typo, not a load failure, and it should not need await to surface.

      Parameters

      • levelId: string

        level id

      • options: LevelLoadOptions & { async: true }

        load options, with async set

      Returns Promise<boolean>

      resolves true once the level is in the world

      await me.loader.preload(game.assets);
      await me.level.load("a4_level1", { async: true });
      // the world is populated here
    • load a level into the game manager
      (will also create all level defined entities, etc..)

      While the game loop is running the load is DEFERRED to a timer, so this returns before anything is in the world. Sequence follow-up work from options.onLoaded, from an event.LEVEL_LOADED listener, or by passing async: true and awaiting the promise that overload returns.

      Note that await me.level.load(id) without async: true does not await the load: the call returns a boolean, and await true resolves at once.

      Parameters

      • levelId: string

        level id

      • Optionaloptions: LevelLoadOptions & { async?: false }

        additional optional parameters

      Returns boolean

      true

      // load a level
      me.level.load("a4_level1");

      // load into a specific container
      me.level.load("a4_level2", { container: levelContainer });

      // a glTF/GLB scene (preloaded with type "glb") under a Camera3d:
      // 50 pixels per glTF unit, authored intensities kept at a 1/1000 scale
      me.level.load("diorama", { scale: 50, lightIntensityScale: 0.001 });