Skip to content

Resource loading

Open Javadoc

Pine uses a resource pool to manage resources efficiently, by avoiding loading resources multiple times. The resource pool takes a string that represents the path to a file, then loads that file as a resource, adds it to the pool and returns it. Then, if you use the resource pool to load that same file again, it will return the pooled resource instead of loading it again.

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

Image image = ResourcePool.loadImage("images/image.png");
Texture texture = ResourcePool.loadTexture("images/image.png");
Font font = ResourcePool.loadFont("fonts/font.ttf"); // Loads a font with the default font size (16)
Font font = ResourcePool.loadFont("fonts/font.ttf", 16);

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

ResourcePool.clear();