Scene

EntityVisualQuadLayerceramic.Scene (Class)

Base class for creating scenes in Ceramic.

Scenes are self-contained units of gameplay or application screens that manage their own assets, lifecycle, and update loop. They provide a structured way to organize different parts of your application (menus, levels, settings, etc.).

Key features:

  • Automatic asset loading and management
  • Lifecycle management (boot, preload, create, update, destroy)
  • Scene transition support
  • Pause/resume functionality
  • Observable status for tracking scene state

Typical scene lifecycle:

  1. new() - Constructor
  2. preload() - Load assets (optional)
  3. create() - Initialize scene content
  4. update() - Called every frame while active
  5. destroy() - Cleanup

Example usage:

class GameScene extends Scene {
    override function preload() {
        assets.add(Images.PLAYER);
        assets.add(Sounds.MUSIC);
    }
    override function create() {
        // Initialize game objects
    }
    override function update(delta:Float) {
        // Update game logic
    }
}

Instance Members

observedDirty: Bool

Default is false, automatically set to true when any of this instance's observable variables has changed.


assets: Assets

Asset manager for this scene. Automatically created when accessed for the first time. Use this to load images, sounds, fonts, etc. during the preload phase.


isRootScene: Bool

Whether this scene is a root scene. Root scenes are managed by the SceneSystem and receive automatic updates.


autoUpdate: Bool

Set to false if you want to disable auto update on this scene object. If auto update is disabled, you become responsible to explicitly call update(delta) at every frame yourself. Use this if you want to have control over when the animation update is actually happening. Don't use it to pause animation. (animation can be paused with paused property instead)


autoUpdateWhenInactive: Bool

If autoUpdate is enabled, setting autoUpdateWhenInactive to true will keep updating the scene even when inactive.


paused: Bool

Whether this scene is paused. When paused, the update() method will not be called.


invalidateStatus(): Void

ready(): Void

Called when the scene's status becomes READY


update(delta: Float): Void

Called at every frame, but only after create() has been called and when the scene is not paused

Name Type
delta Float

resize(width: Float, height: Float): Void

Called if the scene size has been changed during this frame.

Name Type Description
width Float new width
height Float new height

fadeIn(done: Function): Void

Play fade-in transition of this scene. This is automatically called right after the scene is ready to use, meaning after create() has been called. Default implementation does nothing and calls done() right away. Override in subclasses to perform custom transitions.

Name Type Description
done Function Called when the fade-in transition has finished.

fadeOut(done: Function): Void

Play fade-out transition of this scene. This is called manually on secondary scene but will be called automatically if the scene is the main scene and is replaced by a new scene or simply removed.

Name Type Description
done Function Called when the fade-out transition has finished.

isReady(): Bool

Check if the scene is ready (has completed initialization).

Returns Description
Bool True if the scene status is READY, false otherwise

scheduleOnceReady(owner: Entity, callback: Function): Bool

Schedule a callback to be executed once the scene is ready. If the scene is already ready, the callback is executed immediately.

Name Type Description
owner Entity The entity that owns the callback (for proper cleanup)
callback Function The function to call when the scene is ready
Returns Description
Bool True if the callback was scheduled/executed, false if scene is destroyed or in invalid state

destroy(): Void

new(): Void

Create a new scene instance.

Private Members

status: SceneStatus

Observable status of this scene. Possible values: NONE, PRELOAD, PRELOAD_COMPLETE, CREATE, READY


unobservedStatus: SceneStatus

emitObservedDirty(instance: Scene, fromSerializedField: Bool): Void

Event when any observable value as changed on this instance.

Name Type
instance Scene
fromSerializedField Bool

emitReplace(newScene: Scene): Void

An event to replace this scene with a new one. By default, this has effect only if our current scene instance was initially assigned to the scene system, like when using app.scenes.main = MyScene();, but you could implement your own logic by listening to that event in other situations too.

Name Type
newScene Scene

emitStatusChange(current: SceneStatus, previous: SceneStatus): Void

Event when status field changes.

Name Type
current SceneStatus
previous SceneStatus

internalCreate(): Void

internalLoad(): Void

willEmitResize(width: Float, height: Float): Void
Name Type
width Float
height Float

preload(): Void

Override this method to configure the scene, add assets to it... example: assets.add(Images.SOME_IMAGE); Added assets will be loaded automatically


load(next: Function): Void

Override this method to perform any additional asynchronous loading. next() must be called once the loading has finished so that the scene can continue its createialization process.

Name Type Description
next Function The callback to call once asynchronous loading is done

create(): Void

Called once the scene has finished its loading. At this point, and after create(), update(delta) will be called at every frame until the scene gets destroyed

Metadata

Name Parameters
:build tracker.macros.ObservableMacro.build()
:autoBuild tracker.macros.ObservableMacro.build()
:build tracker.macros.EventsMacro.build()
:autoBuild tracker.macros.EventsMacro.build()
:build ceramic.macros.EntityMacro.buildForCompletion()
:autoBuild ceramic.macros.EntityMacro.buildForCompletion()
:allow ceramic.SceneSystem