public interface AssetLoader
The "assets" directory must be located in source folder ("src" by default). If you are using the Maven directory structure then under "src/main/resources/".
Resources (assets) will be searched for in these specified directories:
getStream(String) to obtain an InputStream and then
parse into whatever resource you need.| Modifier and Type | Method and Description |
|---|---|
void |
cache()
Pre-loads all textures / sounds / music / text / fonts and binary data
from their respective folders.
|
void |
clearCache()
Release all cached assets.
|
InputStream |
getStream(String name)
Opens a stream to resource with given name.
|
javafx.scene.image.Image |
loadAppIcon(String name)
Loads an app icon from /assets/ui/icons/.
|
<T> BehaviorTree<T> |
loadBehaviorTree(String name)
Loads a behavior tree from /assets/ai/.
|
CSS |
loadCSS(String name)
Loads a CSS file from /assets/ui/css/.
|
javafx.scene.image.Image |
loadCursorImage(String name)
Loads cursor image with given name from /assets/ui/cursors/.
|
List<String> |
loadFileNames(String directory)
Loads file names from a directory.
|
FontFactory |
loadFont(String name)
Loads a native JavaFX font with given name from /assets/ui/fonts/
wrapped in a FontFactory, which later can be used to produce fonts
with different sizes without accessing the font file.
|
List<String> |
loadJSON(String name)
Loads JSON file with given name from /assets/json/.
|
<T> T |
loadJSON(String name,
Class<T> type)
Loads JSON file with given name from /assets/json/ and parses into an object of type T.
|
KVFile |
loadKV(String name)
Loads KVFile with given name from /assets/kv/.
|
Music |
loadMusic(String name)
Loads sound with given name from /assets/music/.
|
ResourceBundle |
loadResourceBundle(String name)
Loads resource bundle with given name from "/assets/properties/".
|
String |
loadScript(String name)
Loads script with given name from /assets/scripts/ as a single string.
|
Sound |
loadSound(String name)
Loads sound with given name from /assets/sounds/.
|
List<String> |
loadText(String name)
Loads text file with given name from /assets/text/
into List
|
Texture |
loadTexture(String name)
Loads texture with given name from /assets/textures/.
|
Texture |
loadTexture(String name,
double width,
double height)
Loads texture with given name from /assets/textures/.
|
UI |
loadUI(String name,
UIController controller)
Loads an FXML (.fxml) file from /assets/ui/.
|
Texture loadTexture(String name)
Supported image formats are:
name - texture name without the /assets/textures/, e.g. "player.png"IllegalArgumentException - if asset not found or loading errorTexture loadTexture(String name, double width, double height)
Supported image formats are:
name - texture name without the /assets/textures/, e.g. "player.png"width - requested widthheight - requested heightIllegalArgumentException - if asset not found or loading errorSound loadSound(String name)
Supported sound format:
name - sound name without the /assets/sounds/, e.g. "explosion.wav"IllegalArgumentException - if asset not found or loading errorMusic loadMusic(String name)
Supported music format:
name - music name without the /assets/music/, e.g. "background_music.mp3"IllegalArgumentException - if asset not found or loading errorList<String> loadText(String name)
name - text file name without the /assets/text/, e.g. "level_0.txt"IllegalArgumentException - if asset not found or loading errorKVFile loadKV(String name)
name - KVFile name without the /assets/kv/, .e.g "settings.kv"IllegalArgumentException - if asset not found or loading errorList<String> loadJSON(String name)
name - JSON file name, e.g. level_data.jsonIllegalArgumentException - if asset not found or loading error<T> T loadJSON(String name, Class<T> type)
name - JSON file name, e.g. level_data.jsontype - object type to parse toIllegalArgumentException - if asset not found or loading errorString loadScript(String name)
name - script file without the /assets/scripts/, e.g. "skill_heal.js"IllegalArgumentException - if asset not found or loading errorResourceBundle loadResourceBundle(String name)
name - must be under "/assets/properties/", e.g. system.properties, game.propertiesIllegalArgumentException - if asset not found or loading errorjavafx.scene.image.Image loadCursorImage(String name)
name - image name without the /assets/ui/cursors/, e.g. "attack_cursor.png"IllegalArgumentException - if asset not found or loading errorUI loadUI(String name, UIController controller)
name - FXML file namecontroller - the controller objectIllegalArgumentException - if asset not found or loading/parsing errorCSS loadCSS(String name)
name - CSS file name without the /assets/ui/css/, e.g. "ui_button.css"IllegalArgumentException - if asset not found or loading errorFontFactory loadFont(String name)
Supported font formats are:
name - font file name without the /assets/ui/fonts/, e.g. "quest_font.ttf"IllegalArgumentException - if asset not found or loading errorjavafx.scene.image.Image loadAppIcon(String name)
name - image name without the /assets/ui/icons/, e.g. "app_icon.png"IllegalArgumentException - if asset not found or loading error<T> BehaviorTree<T> loadBehaviorTree(String name)
T - tree typename - tree name without the /assets/ai/, e.g. "patrol.tree"IllegalArgumentException - if asset not found or loading errorInputStream getStream(String name)
name - resource nameIllegalArgumentException - if any error occurs or stream is nullList<String> loadFileNames(String directory)
directory - name of directoryIllegalArgumentException - if directory does not start with "/assets/" or was not foundvoid cache()
void clearCache()
Copyright © 2017. All rights reserved.