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: App
Shared App
instance singleton.
Instance Members
inUpdate: Bool
true
if the app is currently running its update phase.
computedFps: Int
Computed fps of the app. Read only. Value is automatically computed from last second of frame updates.
frame: Int
Current frame number
delta: Float
Current frame delta time (never above settings.maxDelta
)
realDelta: Float
Current frame real delta time (the actual elapsed time since last frame update)
backend: backend.Backend
Backend instance
screen: Screen
Screen instance
audio: Audio
Audio instance
settings: Settings
App settings
systems: Systems
Systems are objects to structure app work/phases and update cycle
logger: Logger
Logger. 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: Input
Shared instance of Input
renderTextures: Array<RenderTexture>
All active render textures in this app
assets: Assets
App level assets. Used to load default assets (font, texture, shader) required to make ceramic work properly.
defaultTexturedShader: Shader
Default textured shader. This is the shader used for any visual (quad or mesh) that don't have a custom shader assigned.
defaultWhiteTexture: Texture
Default 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: BitmapFont
Default font used by Text
instances.
projectDir: String
Project directory. May be null depending on the platform.
persistent: PersistentData
App 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: TextInput
Shared text input manager. Usually not used directly as is.
You might want to use EditText
component instead.
converters: Map
Converters 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: Timelines
All active timelines in this app.
scenes: SceneSystem
Shared 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): Void
Schedule 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(): Bool
Execute 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): Void
Remove a previously scheduled extended update callback
Name | Type | Description |
---|---|---|
callback |
Function | The callback to remove |
quit(): Void
Quit 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: Int
Current capacity of immediate callbacks array to optimize array operations
immediateCallbacksLen: Int
Current number of pending immediate callbacks
postFlushImmediateCallbacks: Array<Function>
Array of callbacks to be executed after all immediate callbacks are done
postFlushImmediateCallbacksCapacity: Int
Current capacity of post flush immediate callbacks array
postFlushImmediateCallbacksLen: Int
Current number of pending post flush immediate callbacks
hierarchyDirty: Bool
visualsContentDirty: Bool
beginUpdateCallbacks: 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(): Void
Fired 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(): Void
Fired when the app will enter background state.
CAUTION: Can execute outside main thread!
emitFinishEnterBackground(): Void
Fired when the app did finish entering background state.
CAUTION: Can execute outside main thread!
emitBeginEnterForeground(): Void
Fired when the app will enter foreground state.
CAUTION: Can execute outside main thread!
emitFinishEnterForeground(): Void
Fired when the app did finish entering foreground state.
CAUTION: Can execute outside main thread!
emitBeginSortVisuals(): Void
Fired right before sorting all visuals. Visual are sorted at each frame depending on their properties: depth, texture, blending, shader...
emitFinishSortVisuals(): Void
Fired right after all visuals have been sort.
emitBeginDraw(): Void
Fired right before drawing phase of visuals.
emitFinishDraw(): Void
Fired right after drawing phase of visuals.
emitLowMemory(): Void
Fired if the app is running low on memory. (not be implemented by all platforms/targets).
CAUTION: Can execute outside main thread!
emitTerminate(): Void
Fired when the app terminates.
CAUTION: Can execute outside main thread!
tickOnceXUpdates(): Void
Internal method to handle execution of extended update callbacks
cleanXUpdatesNullValues(): Void
backendReady(): Void
When 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(): Void
Bind app settings to their corresponding backend implementations. Currently handles FPS target synchronization.
initFieldConverters(): Void
Initialize 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): Void
Initialize 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(): Void
Called when all default assets are loaded. Proceeds with running any pending loaders.
runNextLoader(): Void
Run pending loaders sequentially until none remain, then trigger app ready state.
runReady(): Void
Initialize 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(): Void
Main 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(): Bool
Synchronize pending visuals into the main visuals list.
Returns | Description |
---|---|
Bool | True if any visuals were synchronized |
syncDestroyedVisuals(): Void
Remove destroyed visuals from the main visuals list. Uses an efficient gap-closing algorithm to maintain array density.
new(): Void
Metadata
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 |