UNPKG

playcanvas

Version:

Open-source WebGL/WebGPU 3D engine for the web

36 lines (35 loc) 1.17 kB
import { getApplication } from "./globals.js"; let _createdLoadingScreen = false; const script = { // set during script load to be used for initializing script app: null, /** * Handles the creation of the loading screen of the application. A script can subscribe to the * events of a {@link AppBase} to show a loading screen, progress bar etc. In order for * this to work you need to set the project's loading screen script to the script that calls * this method. * * @param {CreateScreenCallback} callback - A function which can set up and tear down a * customized loading screen. * @example * pc.script.createLoadingScreen((app) => { * const showSplashScreen = () => {}; * const hideSplashScreen = () => {}; * const showProgress = (progress) => {}; * app.on("preload:start", showSplashScreen); * app.on("preload:progress", showProgress); * app.on("start", hideSplashScreen); * }); */ createLoadingScreen(callback) { if (_createdLoadingScreen) { return; } _createdLoadingScreen = true; const app = getApplication(); callback(app); } }; export { script };