Add-ons / Preload Macro

This macro allows you to preload image resources.

Author ChapelR
Website https://twinelab.net/custom-macros-for-sugarcube-2/#/preload
Story format SugarCube 2
Last checked Mon Jul 22 2024
License Unlicense
Download preload.zip

Index

Overview

This macro allows you to preload image resources.

Macros

<<preload>>

<<preload>>

Syntax: <<preload urls>>

This macro will preload a list of image resources so that they will be available and not have to take time to download as they are encountered during play. In general, only important or necessary images should be preloaded, and because the process of preloading merely moves the downloads to startup rather than eliminating them, preloading too many images or extremely large images can cause startup times to become excessive. Still, judicious use of this macro can help a game feel snappier and more performant.

⚠️ Danger: The <<preload>> macro will throw an error if used outside of the StoryInit special passage (or equivalent). If you absolutely need to preload at some other time, set setup.preload.force to true. This is not recommended, and only included as an option for bizarre use-cases.

Arguments:

Usage:

<<preload 'assets/lisa/jpg' 'assets/bob.jpg'>>

/* you can also provide the arguments as an array if you prefer */
<<preload `['assets/lisa/jpg', 'assets/bob.jpg']`>>

READ: Documentation

JavaScript API

setup.preload()

setup.preload()

Syntax: setup.preload(urls)

This function does exactly the same thing as <<preload>> and is subject to the exact same restrictions.

Arguments:

Usage:

setup.preload('assets/lisa/jpg', 'assets/bob.jpg');

// you can also provide the arguments as an array if you prefer
setup.preload(['assets/lisa/jpg', 'assets/bob.jpg'])

Live demo

Demo Twee code:

:: Start
Here's a pre-loaded kitten:
[img[https://loremflickr.com/150/120]]

:: StoryInit
<<preload 'https://loremflickr.com/150/120'>>