Assets
Entity →
ceramic.Assets (Class)
The main asset management class for Ceramic framework.
Handles loading, managing, and hot-reloading of various asset types including:
- Images/Textures
- Fonts (bitmap and TTF/OTF)
- Atlases (texture atlases)
- Text files
- Binary data
- Sounds/Audio
- Databases (CSV)
- Fragments (JSON-based UI/game fragments)
- Shaders
Features:
- Reference counting for memory management
- Asset variants and density handling for multi-resolution support
- Hot reloading when watching directories
- Parent-child asset relationships
- Custom asset type registration
- Parallel/serial loading strategies
var assets = new Assets();
assets.addImage('hero.png');
assets.addFont('main.fnt');
assets.load();
Static Members
All active Assets instances in the application.
Read-only array to prevent external modification.
All available asset paths in the project.
All available directory paths in the project.
Map of asset names to their available file paths.
Useful for finding all variants of an asset.
Map of directory names to their paths.
Decode an asset path to extract information about density, variant, etc.
| Name |
Type |
Description |
path |
String |
The asset path to decode |
| Returns |
Description |
| AssetPathInfo |
AssetPathInfo object containing parsed path information |
Register a custom asset kind that can be loaded by the asset system.
| Name |
Type |
Description |
kind |
String |
The unique identifier for this asset type (e.g., 'sprite', 'level') |
add |
Function |
Function that handles adding this asset type to an Assets instance |
extensions |
Array<String> |
File extensions associated with this asset type |
dir |
Bool |
Whether this asset type is directory-based |
types |
Array<String> |
Additional type information for the asset kind |
Get the base assets path for the current platform.
| Returns |
Description |
| String |
The platform-specific assets path |
Get the asset name associated with a given file path.
| Name |
Type |
Description |
path |
String |
The file path to look up |
| Returns |
Description |
| String |
The asset name, or null if no asset uses this path |
| Name |
Type |
realAssetPath |
String |
Instance Members
If set, will be provided to each added asset in this Assets instance.
Used for runtime asset loading from file system.
Default options applied to all image assets added to this instance.
Can be overridden per asset.
The loading method to use (SYNC or ASYNC).
SYNC blocks until loading completes, ASYNC loads in background.
The scheduling method for loading multiple assets.
PARALLEL loads all at once, SERIAL loads one at a time.
If > 0, adds a delay every X assets when loading in parallel.
Useful to avoid overwhelming the system with too many concurrent loads.
reloadOnTextureDensityChange: Bool
Whether to automatically reload assets when texture density changes.
Useful for supporting multiple screen resolutions.
If provided, when requesting an asset, it will also check if the parent Assets
instance has it and return it if that's the case.
A shared texture atlas packer that can be used to merge smaller textures together.
Also required when loading some kind of assets, like .ase/.aseprite files.
Set to true to enable hot reload.
When enabled and used with watchDirectory(), assets will automatically
reload when their files change on disk.
Note: this won't do anything unless used in pair with watchDirectory(path)
Destroy assets that have their refCount at 0.
This is useful for cleaning up unused assets to free memory.
Assets with refCount > 0 are still in use and won't be destroyed.
Add all assets matching given path pattern (if provided).
Automatically detects asset types based on file extensions.
| Name |
Type |
Default |
Description |
pathPattern |
EReg |
(optional) |
Optional regex pattern to filter asset paths haxe // Add all assets assets.addAll(); // Add only assets in 'sprites' folder assets.addAll(~/^sprites\/.*$/); |
addText(name: String, ?variant: String, ?options: Null<AssetOptions>): Void
Add the given asset to this Assets instance.
If an asset with the same kind and name already exists, it will be replaced.
| Name |
Type |
Description |
asset |
Asset |
The asset to add |
| Returns |
Description |
| Asset |
The previous asset if one was replaced, null otherwise |
Move all assets owned by this Assets instance
to the given toAssets object.
Useful for transferring assets between scenes or asset groups.
| Name |
Type |
Description |
toAssets |
Assets |
The target Assets instance to move assets to |
hasAnythingToLoad(): Bool
Returns true if there are assets that should be loaded.
Checks for assets with status NONE (not yet loaded).
| Returns |
Description |
| Bool |
True if there are unloaded assets, false otherwise |
countAssetsWithStatus(status: Anonymous): Int
| Name |
Type |
status |
Anonymous |
Load all assets that have been added to this instance.
Emits progress events during loading and complete event when finished.
| Name |
Type |
Default |
Description |
warnIfNothingToLoad |
Bool |
true |
If true, logs a warning when there are no assets to load |
pos |
Null<haxe.PosInfos> |
(optional) |
Source position for debugging (automatically provided) |
Ensures and asset is loaded and return it on the callback.
This will check if the requested asset is currently being loaded,
already loaded or should be added and loaded. In all cases, it will try
its best to deliver the requested asset or null if something went wrong.
ensureText(name: Either<String, AssetId<String>>, ?variant: String, ?options: Null<AssetOptions>, done: Function): Void
Get a loaded texture by name.
| Returns |
Description |
| Texture |
The texture, or null if not found |
Get a loaded font by name.
| Returns |
Description |
| BitmapFont |
The font, or null if not found |
Get a loaded sound by name.
| Returns |
Description |
| Sound |
The sound, or null if not found |
Get loaded text content by name.
| Returns |
Description |
| String |
The text content, or null if not found |
Get a loaded shader by name.
| Returns |
Description |
| Shader |
The shader, or null if not found |
Watch the given asset directory for changes.
Any file change will fire assetFilesChange event and optionally trigger hot reload.
This is particularly useful during development to see asset changes without restarting.
Behavior may differ depending on the platform.
| Name |
Type |
Default |
Description |
path |
String |
(optional) |
The assets path to watch. If null, uses the default assets path from project configuration. You can use ceramic.macros.DefinesMacro.getJsonDefine('assets_path') to get the default. |
hotReload |
Bool |
true |
If true (default), assets will automatically reload when their files change |
| Returns |
Description |
| WatchDirectory |
WatchDirectory instance used internally * haxe // Watch default assets directory with hot reload assets.watchDirectory(); * // Watch custom path without hot reload assets.watchDirectory('/path/to/assets', false); * Note: When using web target via electron, add ceramic_use_electron define. |
Private Members
reloadCountByRealAssetPath: Map
lastModifiedByRealAssetPath: Map
| Name |
Type |
realAssetPath |
String |
Emitted when all assets have finished loading.
| Name |
Type |
Description |
success |
Bool |
True if all assets loaded successfully, false if any failed |
Emitted when an individual asset is updated (loaded, reloaded, etc).
| Name |
Type |
Description |
asset |
Asset |
The asset that was updated |
Emitted during loading to report progress.
| Name |
Type |
Description |
loaded |
Int |
Number of assets loaded so far |
total |
Int |
Total number of assets to load |
success |
Bool |
True if all loaded assets succeeded so far |
Emitted when watched asset files change on disk.
| Name |
Parameters |
:build |
ceramic.macros.EntityMacro.buildForCompletion() |
:autoBuild |
ceramic.macros.EntityMacro.buildForCompletion() |
:build |
tracker.macros.EventsMacro.build() |
:autoBuild |
tracker.macros.EventsMacro.build() |
:allow |
ceramic.Asset |