Skip to content

textmode.js / loading / LoadingScreenRendererContext

Interface: LoadingScreenRendererContext

Context object passed to a loading screen renderer function.

Can be used to create a custom loading screen to fit your needs.

Example

ts
const t = textmode.create({
  width: 800,
  height: 600,
  loadingScreen: {
    message: 'loading...',
    renderer: (ctx) => {
      const { textmodifier: tm, grid, progress, message, transitionOpacity } = ctx;

      // Clear the screen
      tm.background(0, 0, 0, Math.floor(transitionOpacity * 255));

      // Position at top-left corner
      const x = -Math.floor(grid.cols / 2) + 2;
      const y = -Math.floor(grid.rows / 2) + 2;

      tm.push();
      tm.translate(x, y, 0);
      tm.charColor(255, 255, 255, transitionOpacity * 255);

      // Display message
      if (message) {
        for (let i = 0; i < message.length; i++) {
          tm.char(message[i]);
          tm.rect(1, 1);
          tm.translateX(1);
        }
      }

      // Display progress bar
      tm.translate(-message.length, 2, 0);
      const barWidth = 20;
      const filled = Math.floor(progress * barWidth);

      for (let i = 0; i < barWidth; i++) {
        tm.char(i < filled ? '=' : '-');
        tm.rect(1, 1);
        tm.translateX(1);
      }

      tm.pop();
    }
  }
});

Properties

PropertyTypeDescription
elapsedMsnumberThe elapsed time since the loading started, in milliseconds.
errorDetails?stringDetailed error information, if any.
errorMessage?stringThe error message to display, if any.
frameCountnumberThe number of frames rendered since the loading started.
gridTextmodeGridThe TextmodeGrid representing the screen grid.
isErrorbooleanIndicates if the loading screen is in an error state.
message?stringThe current loading message, if any.
paletteTextmodeColor[]The palette of colors available for rendering based on the theme.
phasesLoadingPhaseSnapshot[]The phases of the loading process.
progressnumberThe current loading progress (0-1).
textmodifierTextmodifierThe Textmodifier instance for rendering text and graphics.
themeLoadingScreenThemeThe current theme of the loading screen.
transitionOpacitynumberThe opacity level for transition effects.