Skip to content

Resource Management

Avetis edited this page Nov 9, 2015 · 1 revision

The usual behavior of a graphical game can be separated into two parts.

  1. Load data into memory
  2. Render it.

Because every game is different, the "loading" part is always different from game to game, and lot's of developers optimize differently. Core part of overlap2d runtime assumes that data in form of graphical assets such as images or atlases, has been already loaded into memory. So while performing it's "daily rendering duties" runtime needs an API to ask user for the assets to render.

IResourceRetriever

IResourceRetriever is an interface that is used by runtime to ask for things. For example it has methods such as getRegion(name) that has to return the TextureRegion for particular texture region name. In ideal, a developer of production grade game, is welcome to create his own class that can load resources, keep them in memory, and implement IResourceRetriecer in order to be able to provide this resources to runtime on demand. But to keep it simple, we created our own "simple" implementation, so that you guys can get started quickly.

ResourceManager

ResourceManager is an example class that used with SceneLoader by default. It provides methods for finding the data in assets folder, it loads them into memory, and it implements IResourceRetriever so rutnime can "talk" to it.

Using the IResourceRetriever instance.

Ashley case: SceneLoader has two constructors, one is empty, and other expects IResourceRetriever instance. If you call empty constructor, then ResourceManager will be created, and all resources loaded at this point. If you plan to do loading yourself, then you have to instantiate ResourceManager or your own implementation before creating SceneLoader. Make it load all the data. And then pass it to SceneLoader that will, in that case, expect all data to be loaded at this point.

Scene2D case: In this case, you are welcome to create an instance of ResourceManager or any other IResourceRetriever. Make it load all the data, and then when creating CompositeActor instance, just pass the IResourceRetriever instance as a second parameter.

Async Loading

If it's a production grade game, you probably require Async resource loading. For that libGDX provides awesome class AssetManager that will load things async. All you have to do is create your own IResourceRetriever that uses AssetManager.