ImageAsset
Asset type for loading image files as textures.
Supports various image formats including PNG, JPG, WebP (backend-dependent), and Aseprite files (.ase/.aseprite) when the ase plugin is enabled.
Features:
- Automatic density selection based on screen resolution
- Hot reload support for development
- Texture replacement with automatic visual updates
- Integration with texture atlas packing
var assets = new Assets();
assets.addImage('hero.png');
assets.load();
// Access loaded texture
var texture = assets.texture('hero');
Instance Members
texture: TextureThe loaded texture instance. Observable property that updates when the texture is loaded or replaced. Null until the asset is successfully loaded.
invalidateTexture(): Voidload(): VoidLoad the image file and create a texture. Handles density selection, hot reload, and visual updates. Emits complete event when finished.
destroy(): Voidnew(name: String, ?variant: String, ?options: Null<AssetOptions>): VoidCreate a new image asset.
| Name | Type | Default | Description |
|---|---|---|---|
name |
String | Image file name (with or without extension) | |
variant |
String | (optional) | Optional variant suffix |
options |
Null<AssetOptions> | (optional) | Loading options including: - premultiplyAlpha: Whether to premultiply alpha channel - width/height: For Aseprite grid texture loading - layers: Specific layers to load from Aseprite files |
Private Members
unobservedTexture: TexturedefaultImageOptions: AssetOptionsreloadBecauseOfDensityChange: BoolaseTexWidth: IntaseTexHeight: IntasePadding: IntaseSpacing: IntEmitted when the texture is replaced (e.g., during hot reload). All visuals using the previous texture are automatically updated.
| Name | Type | Description |
|---|---|---|
newTexture |
Texture | The newly loaded texture |
prevTexture |
Texture | The previous texture being replaced |
Event when texture field changes.
| Name | Type |
|---|---|
current |
Texture |
previous |
Texture |
loadTexture(path: String, loadOptions: AssetOptions, callback: Function): Void| Name | Type |
|---|---|
path |
String |
loadOptions |
AssetOptions |
callback |
Function |
Handle screen density changes by reloading the texture at appropriate resolution. Only triggers if the asset is already loaded and a better resolution is available.
| Name | Type |
|---|---|
newDensity |
Float |
prevDensity |
Float |
checkTexturesDensity(): VoidassetFilesDidChange(newFiles: ReadOnlyMap<String, Float>, previousFiles: ReadOnlyMap<String, Float>): VoidHandle file system changes for hot reload. Automatically reloads the texture when the source file is modified.
| Name | Type |
|---|---|
newFiles |
ReadOnlyMap<String, Float> |
previousFiles |
ReadOnlyMap<String, Float> |
Metadata
| Name | Parameters |
|---|---|
:build |
tracker.macros.EventsMacro.build() |
:autoBuild |
tracker.macros.EventsMacro.build() |
:build |
ceramic.macros.EntityMacro.buildForCompletion() |
:autoBuild |
ceramic.macros.EntityMacro.buildForCompletion() |
:build |
tracker.macros.ObservableMacro.build() |
:autoBuild |
tracker.macros.ObservableMacro.build() |