AssetGroup

abstract class AssetGroup(val manager: AssetManager, filePrefix: String = "")

A class for managing a group of assets together, such that they can be loaded or unloaded en masse. AssetGroup should be subclassed and the assets should be defined by properties in the subclass by using asset or, delayedAsset, which can be used as delegates. If not using delegates, it is possible to selectively load and unload them, in which case it is not advised to use loadAll and unloadAll, because AssetManager's reference counts may be thrown off.

If fine control over individual assets of this group is not needed, a strategy to avoid the complexity of AssetManager's reference counting is to:

Parameters

manager

The AssetManager that will handle loading and unloading of this group.

filePrefix

A string that will be prefixed to any file path parameter passed to asset or delayedAsset.

Constructors

Link copied to clipboard
constructor(manager: AssetManager, filePrefix: String = "")

Properties

Link copied to clipboard

Functions

Link copied to clipboard

Blocks until all members of this group are loaded. This does not prioritize this group's members, so assets from outside this group may be loaded as well.

Link copied to clipboard
Link copied to clipboard
fun loadAll()

Queues all assets of this group for loading by the associated AssetManager. If any assets of this group are already loaded, their load counts in the AssetManager will still be incremented.

Link copied to clipboard
fun unloadAll()

Unloads all of the assets in this group. If any of the assets are dependencies of assets outside this group, or if they were loaded more than once, their load counts will only be decremented by one and the associated AssetManager will retain them.

Link copied to clipboard
fun unloadAllSafely(onError: (Asset<*>, Exception) -> Unit = { _, exception -> exception.ignore() })

Unloads all of the assets in this group, catching any exceptions. If any of the assets are dependencies of assets outside this group, or if they were loaded more than once, their load counts will only be decremented by one and the associated AssetManager will retain them.

Link copied to clipboard

Updates the associated AssetManager if the members of this group are not finished loading. This does not prioritize this group's assets, but it might provide early feedback that the members of this specific group are ready.