Package com.deco2800.game.services
Class ResourceService
java.lang.Object
com.deco2800.game.services.ResourceService
- All Implemented Interfaces:
com.badlogic.gdx.utils.Disposable
Service for loading resources, e.g. textures, texture atlases, sounds, music, etc. Add new load
methods when new types of resources are added to the game.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidClears all loaded assets and assets in the preloading queue.<T> booleancontainsAsset(String resourceName, Class<T> type) Check if an asset has been loaded alreadyvoiddispose()com.badlogic.gdx.utils.Array<String><T> TLoad an asset from a filecom.badlogic.gdx.assets.AssetManagerintReturns the loading completion progress as a percentage.voidloadAll()Blocking call to load all assets.booleanloadForMillis(int duration) Loads assets for the specified duration in milliseconds.voidLoads a list of music assets into the asset manager.voidloadSounds(String[] soundNames) Loads a list of sounds into the asset manager.voidloadTextureAtlases(String[] textureAtlasNames) Loads a list of texture atlas assets into the asset manager.voidloadTextures(String[] textureNames) Loads a list of texture assets into the asset manager.voidunloadAssets(String[] assetNames)
-
Constructor Details
-
ResourceService
public ResourceService() -
ResourceService
public ResourceService(com.badlogic.gdx.assets.AssetManager assetManager)
-
-
Method Details
-
getAsset
Load an asset from a file- Type Parameters:
T- Type of class to load into- Parameters:
filename- Asset pathtype- Class to load into- Returns:
- Instance of class loaded from path
- See Also:
-
AssetManager.get(String, Class)
-
containsAsset
Check if an asset has been loaded already- Type Parameters:
T- Type of the asset- Parameters:
resourceName- path of the assettype- Class type of the asset- Returns:
- true if asset has been loaded, false otherwise
- See Also:
-
AssetManager.contains(String)
-
getProgress
public int getProgress()Returns the loading completion progress as a percentage.- Returns:
- progress
-
loadAll
public void loadAll()Blocking call to load all assets.- See Also:
-
AssetManager.finishLoading()
-
loadForMillis
public boolean loadForMillis(int duration) Loads assets for the specified duration in milliseconds.- Parameters:
duration- duration to load for- Returns:
- finished loading
- See Also:
-
AssetManager.update(int)
-
clearAllAssets
public void clearAllAssets()Clears all loaded assets and assets in the preloading queue.- See Also:
-
AssetManager.clear()
-
loadTextures
Loads a list of texture assets into the asset manager.- Parameters:
textureNames- texture filenames
-
loadTextureAtlases
Loads a list of texture atlas assets into the asset manager.- Parameters:
textureAtlasNames- texture atlas filenames
-
loadSounds
Loads a list of sounds into the asset manager.- Parameters:
soundNames- sound filenames
-
loadMusic
Loads a list of music assets into the asset manager.- Parameters:
musicNames- music filenames
-
unloadAssets
-
getAllLoadedAssets
-
dispose
public void dispose()- Specified by:
disposein interfacecom.badlogic.gdx.utils.Disposable
-
getAssetManager
public com.badlogic.gdx.assets.AssetManager getAssetManager()
-