Loading Resources - UQdeco2800/2022-studio-3 GitHub Wiki

Introduction

Resources are managed by the Resource Service which loads and stores resources. To spread out the loading times, resources should be loaded in batches as needed.

Currently, the Resource Service supports Textures, Texture Atlases, Music and Sounds, but can be easily extended to support more resource types.

Usage

Resources should be loaded and unloaded into ResourceService using the corresponding load method. The following example is for textures.

private static final String[] forestTextures = {
  "images/grass_1.png",
  "images/grass_2.png",
  "images/grass_3.png"
};

// load
public void create() {
  ServiceLocator.getResourceService().loadTextures(forestTextures);
}

// unload
public void dispose() {
  ServiceLocator.getResourceService().unloadAssets(forestTextures);
}

Behind the Scenes

ResourceService is essentially a wrapper class for libgdx's AssetManager. The main reasons for having a wrapper class are to make it easier to load resources in batches, support the addition of loading screens, and to improve logging.