App
App class is the root instance of any ceramic app.
App serves as the main entry point and lifecycle manager for Ceramic applications. It handles initialization, update loops, rendering, and provides global access to core systems and settings.
Key responsibilities:
- Application lifecycle management (ready, update, draw)
- Default asset loading and management
- Screen and audio system initialization
- Settings and persistent data management
- Error handling and crash reporting
- Background/foreground state transitions
The App instance is a singleton accessible via app static property or
through the ceramic.Shortcuts.app convenience reference.
Static Members
app: AppShared App instance singleton.
Instance Members
inUpdate: Booltrue if the app is currently running its update phase.
computedFps: IntComputed fps of the app. Read only. Value is automatically computed from last second of frame updates.
frame: IntCurrent frame number
delta: FloatCurrent frame delta time (never above settings.maxDelta)
realDelta: FloatCurrent frame real delta time (the actual elapsed time since last frame update)
backend: backend.BackendBackend instance
screen: ScreenScreen instance
audio: AudioAudio instance
settings: SettingsApp settings
systems: SystemsSystems are objects to structure app work/phases and update cycle
logger: LoggerLogger. Used by log shortcut
Visuals (ordered) Active list of visuals being managed by ceramic. This list is ordered and updated at every frame. In between, it could contain destroyed visuals as they are removed only at the end of the frame for performance reasons.
Pending visuals: visuals that have been created this frame
but were not added to the visual list yet
Pending destroyed visuals: visuals that have been destroyed this frame
but were not removed to the visual list yet
All groups of entities in this app
input: InputShared instance of Input
renderTextures: Array<RenderTexture>All active render textures in this app
assets: AssetsApp level assets. Used to load default assets (font, texture, shader) required to make ceramic work properly.
defaultTexturedShader: ShaderDefault textured shader. This is the shader used for any visual (quad or mesh) that don't have a custom shader assigned.
defaultWhiteTexture: TextureDefault white texture. When a quad or mesh doesn't have a texture assigned, it will use the default white texture instead to render as plain flat coloured object. This means that the same default shader is used and everything can be batched together (textured & non-textured in the same batch).
defaultFont: BitmapFontDefault font used by Text instances.
projectDir: StringProject directory. May be null depending on the platform.
persistent: PersistentDataApp level persistent data.
This is a simple key-value store ready to be used.
Don't forget to call persistent.save() to apply changes permanently.
textInput: TextInputShared text input manager. Usually not used directly as is.
You might want to use EditText component instead.
converters: MapConverters are used to transform field data in Fragment instances.
This map is matching a type (as string, like "Array<Float>") with an instance
of a ConvertField subclass.
timelines: TimelinesAll active timelines in this app.
scenes: SceneSystemShared scene system.
Schedule immediate callback that is garanteed to be executed before the next time frame (before elements are drawn onto screen)
| Name | Type | Description |
|---|---|---|
owner |
Entity | Owner of this callback, allowing to cancel callback if owner is destroyed |
handleImmediate |
Function | The callback to execute |
oncePostFlushImmediate(owner: Entity, handlePostFlushImmediate: Function, ?defer: Bool = true): VoidSchedule callback that is garanteed to be executed when no immediate callback are pending anymore.
| Name | Type | Default | Description |
|---|---|---|---|
owner |
Entity | Owner of this callback, allowing to cancel callback if owner is destroyed | |
handlePostFlushImmediate |
Function | The callback to execute | |
defer |
Bool | true |
if true (default), will box this call into an immediate callback |
flushImmediate(): BoolExecute and flush every awaiting immediate callback, including the ones that
could have been added with onceImmediate() after executing the existing callbacks.
| Returns | Description |
|---|---|
| Bool | true if anything was flushed |
Schedule a callback to be executed after a specific number of update frames.
| Name | Type | Description |
|---|---|---|
owner |
Entity | The entity that owns this callback (used to prevent execution if owner is destroyed) |
numUpdates |
Int | Number of update frames to wait before executing the callback |
callback |
Function | The function to execute after numUpdates frames |
offXUpdates(callback: Function): VoidRemove a previously scheduled extended update callback
| Name | Type | Description |
|---|---|---|
callback |
Function | The callback to remove |
quit(): VoidQuit the application. Works on desktop (windows, mac, linux), unity. Can also work on web by closing the window if electron plugin is enabled and the app is running via electron instead of a regular browser.
Get a group with the given id.
| Name | Type | Default | Description |
|---|---|---|---|
id |
String | The id of the group | |
createIfNeeded |
Bool | true |
true (default) to create a group if not created already for this id |
| Returns | Description |
|---|---|
| Group<Entity> | the group or null if no group was found and none created. |
Shared arcade system. (arcade plugin)
Shared nape system. (nape plugin)
Private Members
preInitCallbacks: Array<Function>immediateCallbacks: Array<Function>Array of callbacks to be executed immediately before the next frame. These callbacks are guaranteed to run before visual updates and rendering.
immediateCallbacksCapacity: IntCurrent capacity of immediate callbacks array to optimize array operations
immediateCallbacksLen: IntCurrent number of pending immediate callbacks
postFlushImmediateCallbacks: Array<Function>Array of callbacks to be executed after all immediate callbacks are done
postFlushImmediateCallbacksCapacity: IntCurrent capacity of post flush immediate callbacks array
postFlushImmediateCallbacksLen: IntCurrent number of pending post flush immediate callbacks
hierarchyDirty: BoolvisualsContentDirty: BoolbeginUpdateCallbacks: Array<Function>List of functions that will be called and purged when update iteration begins. Useful to run some specific code once exactly before update event is sent.
oncePreInit(handle: Function): Void| Name | Type |
|---|---|
handle |
Function |
emitReady(): VoidFired when the app is ready and the game logic can be started.
Fired as many times as there are frames per seconds. It is in sync with screen FPS but used for everything that needs to get updated depending on time (ceramic.Timer relies on it). Use this event to update your contents before they get drawn again.
| Name | Type | Description |
|---|---|---|
delta |
Float | The elapsed delta time since last frame |
Fired right before update event and can be used when you want to run garantee your code will be run before regular update event.
| Name | Type | Description |
|---|---|---|
delta |
Float | The elapsed delta time since last frame |
Fired right after update event and can be used when you want to run garantee your code will be run after regular update event.
| Name | Type | Description |
|---|---|---|
delta |
Float | The elapsed delta time since last frame |
Fired right before default assets are being loaded.
| Name | Type | Description |
|---|---|---|
assets |
Assets | * The Assets instance used to load default assets. If you add custom assets to this instance, they will be loaded as well. |
Fired when the app hits an critical (uncaught) error. Can be used to perform custom crash reporting. If this even is handled, app exit should be performed by the event handler.
| Name | Type | Description |
|---|---|---|
error |
Dynamic | The error |
stack |
Array |
The stack trace of the error |
emitBeginEnterBackground(): VoidFired when the app will enter background state.
CAUTION: Can execute outside main thread!
emitFinishEnterBackground(): VoidFired when the app did finish entering background state.
CAUTION: Can execute outside main thread!
emitBeginEnterForeground(): VoidFired when the app will enter foreground state.
CAUTION: Can execute outside main thread!
emitFinishEnterForeground(): VoidFired when the app did finish entering foreground state.
CAUTION: Can execute outside main thread!
emitBeginSortVisuals(): VoidFired right before sorting all visuals. Visual are sorted at each frame depending on their properties: depth, texture, blending, shader...
emitFinishSortVisuals(): VoidFired right after all visuals have been sort.
emitBeginDraw(): VoidFired right before drawing phase of visuals.
emitFinishDraw(): VoidFired right after drawing phase of visuals.
emitLowMemory(): VoidFired if the app is running low on memory. (not be implemented by all platforms/targets).
CAUTION: Can execute outside main thread!
emitTerminate(): VoidFired when the app terminates.
CAUTION: Can execute outside main thread!
tickOnceXUpdates(): VoidInternal method to handle execution of extended update callbacks
cleanXUpdatesNullValues(): VoidbackendReady(): VoidWhen backend is ready, initialize core systems and load default assets. Steps:
- Initialize persistent data and text input
- Bind settings
- Run pre-init callbacks
- Initialize field converters and collections
- Load default shaders, fonts and textures
bindSettings(): VoidBind app settings to their corresponding backend implementations. Currently handles FPS target synchronization.
initFieldConverters(): VoidInitialize all field converters used to transform field data in Fragment instances. Registers default converters for common types like:
- Textures, Fonts, Colors
- Maps and Arrays
- Components
initCollections(collections: AutoCollections, ?info: Dynamic): VoidInitialize collections from app info configuration. Loads collection data from assets and instantiates collection entries.
| Name | Type | Default | Description |
|---|---|---|---|
collections |
AutoCollections | The collections container | |
info |
Dynamic | (optional) | Optional info object containing collection definitions |
assetsLoaded(): VoidCalled when all default assets are loaded. Proceeds with running any pending loaders.
runNextLoader(): VoidRun pending loaders sequentially until none remain, then trigger app ready state.
runReady(): VoidInitialize app ready state:
- Run platform specific initialization
- Setup debug entity tracking if enabled
- Configure screen
- Setup update/render pipeline
- Configure input handling
Update method called before the app is fully ready. Handles basic asset and immediate callback processing.
| Name | Type |
|---|---|
delta |
Float |
Main update method called every frame once the app is ready. Handles:
- Frame timing and FPS management
- System updates
- Input processing
- Visual hierarchy updates
- Entity lifecycle
| Name | Type | Description |
|---|---|---|
realDelta |
Float | Actual time elapsed since last frame |
render(): VoidMain render method called every frame. Handles the complete rendering pipeline:
- Begins draw phase
- Renders all visible visuals
- Ends draw phase
- Handles display buffer swapping
syncPendingVisuals(): BoolSynchronize pending visuals into the main visuals list.
| Returns | Description |
|---|---|
| Bool | True if any visuals were synchronized |
syncDestroyedVisuals(): VoidRemove destroyed visuals from the main visuals list. Uses an efficient gap-closing algorithm to maintain array density.
new(): VoidMetadata
| Name | Parameters |
|---|---|
:build |
ceramic.macros.EntityMacro.buildForCompletion() |
:autoBuild |
ceramic.macros.EntityMacro.buildForCompletion() |
:build |
tracker.macros.EventsMacro.build() |
:autoBuild |
tracker.macros.EventsMacro.build() |
:build |
ceramic.macros.AppMacro.build() |
:allow |
ceramic.Visual |
:allow |
ceramic.Screen |
:allow |
ceramic.Entity |
:allow |
ceramic.Timer |