Assets
Assets are the static resources that your game loads to run. These can be:
- Images
- JSON files
- Audio files
- Fonts
- Spritesheets
- Spine animations
Loading Assets
Setting up your build tools per our project setup guide will automatically copy your assets to the correct location whether you’re developing locally or building for production.
From the Application
You can load assets that are available globally to the entire application by defining them in
the requiredAssets()
getter in the Application.ts
file or where your application is defined.
From a Game State
For assets that are only needed in a single game state,
you can define which assets you want to load in the Assets()
getter of the game state:
Accessing Assets
Once your assets are loaded, you can access them in your game. The way you access them depends on the type of asset.
Images
Images are loaded as Texture
objects. You can access them by their key:
JSON Files
JSON files are accessed using Pixi’s Cache
class. For example, if you have the following file:
You can access it in your game like this:
Audio Files
Once audio files have been loaded, you can play them using the playAudioTrack
function:
Fonts
The only font format that can be loaded using the asset manager is an .fnt
file, which is a bitmap font.
Once a font has been loaded, you can use it in your game like this:
To use web fonts and load custom fonts, check out the styling text guide.