Skip to content

Asset loading

Open Javadoc

Pine uses asset pools to manage assets efficiently, by avoiding loading assets multiple times. There is a separate pool for every type of asset. The asset pools each take a string that represents the path to a file, then load that file as an asset, add it to the pool and return it. Then, if you use the asset pool to load that same file again, it will return the pooled asset instead of loading it again.

Classes that use assets, like the SpriteRenderer component or ImageNode component, will often provide an alternative method or constructor that has a path (string) instead of an asset as an argument. These use the asset pools to load the assets efficiently based on the given path.

Image image = AssetPools.images.load("images/image.png");
Texture texture = AssetPools.textures.load("images/image.png"); // Will call the previous line internally
Font font = AssetPools.fonts.load("fonts/font.ttf"); // Loads a font with the default font size (16)
Font font = AssetPools.fonts.load("fonts/font.ttf", 16);
StyleSheet styleSheet = AssetPools.styleSheets.load("style/sheet.css");
AudioSource audioSource = AssetPools.audioSources.load("audio/sound.ogg");

The following method can be used to discard all pooled assets. This might be useful when switching between two scenes that do not share many assets, to free up more memory.

AssetPools.clear();