-
-
Notifications
You must be signed in to change notification settings - Fork 556
Assets
This page will familiarize you with what, where, when and how regarding game assets. Most of the asset loading is provided by JavaFX. FXGL simply wraps the API and brings them all together in AssetLoader
.
There is a special directory called assets
placed under src
if you are not following the Maven directory structure. If you are, then it is placed under src/main/resources
. This is necessary for the build process to easily pick up assets and package them when you distribute your game in an executable. This also works when you are developing or debugging your game in the IDE. Check Directory Structure.
After obtaining the reference to the asset loader (getAssetLoader()
) call load*
, where *
can be Texture, Music, Sound, etc. First, the loader will check if the asset is in the cache and return it if it is. If the asset was not found in the cache, the asset will be loaded from the file system and at the same time placed in the cache. You can also pre-load the assets before the game starts by calling cache()
on the loader.
Below you can find the supported types of assets:
Note: some assets support more formats than listed here, e.g. Texture can be loaded as bmp
, however, this is the standardized list and assets are expected to be of that format.
Directory: assets/textures/
Format: jpg
, png
Description: any image you want to display will fall under this category.
Directory: assets/music/
Format: mp3
Description: long audio files, e.g. background music or recorded dialogues.
Directory: assets/sounds/
Format: wav
Description: very short audio files, e.g. sound effects that commonly occur.
Directory: assets/text/
Format: txt
Description: anything in textual format, e.g. text dialogues, in-game item names.
Directory: assets/json/
Format: json
Description: any valid json data, e.g. Tiled map, some custom format.
Directory: assets/tmx/
Format: tmx
Description: Tiled map data.
Directory: assets/scripts/
Format: js
Description: valid scripts that can be run, e.g. AI scripts or behavior, dynamic code snippets.
Directory: assets/properties/
Format: properties
Description: essentially Java resource bundle, a collection of simple key values, useful for system configuration.
Directory: assets/kv/
Format: kv
Description: similar to properties but the file gets parsed into your own custom data structure, useful for entity configuration.
Directory: assets/ai/
Format: tree
Description: this is a standard gdxAI Behavior Tree.
Directory: assets/ui/css/
Format: css
Description: CSS files used to style your UI elements.
Directory: assets/ui/fonts/
Format: ttf
, otf
Description: fonts to be used in UI.
Directory: assets/ui/icons/
Format: jpg
, png
Description: icon images to be used in taskbar or window title.
Directory: assets/ui/cursors/
Format: jpg
, png
Description: cursor images that can be used to replace default mouse cursor.
Directory: assets/data/
Format: anything
Description: your own asset type that can be serialized with the default Java serialization mechanism.
Directory: anywhere under src
or if using Maven src/main/resources
Format: anything
Description: your own asset type that is serialized by you. Basically the loader gives you an InputStream
.