ImageAsset

EntityAssetceramic.ImageAsset (Class)

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: Texture

The loaded texture instance. Observable property that updates when the texture is loaded or replaced. Null until the asset is successfully loaded.


invalidateTexture(): Void

load(): Void

Load the image file and create a texture. Handles density selection, hot reload, and visual updates. Emits complete event when finished.


destroy(): Void

new(name: String, ?variant: String, ?options: Null<AssetOptions>): Void

Create 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: Texture

defaultImageOptions: AssetOptions

reloadBecauseOfDensityChange: Bool

aseTexWidth: Int

aseTexHeight: Int

asePadding: Int

aseSpacing: Int

emitReplaceTexture(newTexture: Texture, prevTexture: Texture): Void

Emitted 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

emitTextureChange(current: Texture, previous: Texture): Void

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

texturesDensityDidChange(newDensity: Float, prevDensity: Float): Void

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(): Void

assetFilesDidChange(newFiles: ReadOnlyMap<String, Float>, previousFiles: ReadOnlyMap<String, Float>): Void

Handle 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()