Reference preload()

preload()

A function that's called once to load assets before the sketch runs.

Declaring the function preload() sets a code block to run once automatically before setup() or draw(). It's used to load assets including multimedia files, fonts, data, and 3D models:

function preload() {
  // Code to run before the rest of the sketch.
}

Functions such as loadImage(), loadFont(), loadJSON(), and loadModel() are guaranteed to either finish loading or raise an error if they're called within preload(). Doing so ensures that assets are available when the sketch begins running.

Examples

Notice any errors or typos? Please let us know. Please feel free to edit src/core/main.js and open a pull request!

Related References