Skip to main content

Scene

A scene is the basic container for animations, managing animation rendering, state, and time.

Overview

The Scene interface defines the core functionality of scenes, including:

  • Lifecycle management
  • Rendering control
  • State management
  • Event system

Properties

Basic Properties

PropertyTypeDescription
namestringScene name
playbackPlaybackStatusPlayback status reference
metaSceneMetadataScene metadata
previousScene | nullPrevious scene

Managers

PropertyTypeDescription
timeEventsTimeEventsTime event manager
shadersShadersShader manager (experimental)
slidesSlidesSlide manager
soundsSoundsSound manager
loggerLoggerLogger
variablesVariablesVariable manager
randomRandomRandom number generator

Signals

PropertyTypeDescription
previousOnTopSignalValue<boolean>Whether the previous scene is on top during transition

Computed Properties

PropertyReturn typeDescription
firstFramenumberScene start frame
lastFramenumberScene end frame
transitionDurationnumberTransition duration (frames)

Events

EventTypeDescription
onCacheChangedSubscribableValueEvent<CachedSceneData>Cache change event
onReloadedSubscribableEvent<void>Reload event
onRecalculatedSubscribableEvent<void>Recalculation event
onRenderLifecycleSubscribableEvent<[SceneRenderEvent, CanvasRenderingContext2D]>Render lifecycle event
onResetSubscribableEvent<void>Reset event

Methods

Rendering

render(context: CanvasRenderingContext2D): Promise<void>

Renders the scene to the specified 2D canvas context.

reload(description?: SceneDescriptionReload<T>): void

Reloads the scene description.

recalculate(setFrame: (frame: number) => void): Promise<void>

Recalculates scene time.

Playback Control

next(): Promise<void>

Advances one frame.

reset(previous?: Scene): Promise<void>

Resets to initial state.

State Query

getSize(): Vector2

Gets the scene size.

getRealSize(): Vector2

Gets the actual rendering size.

isAfterTransitionIn(): boolean

Whether the scene is after the transition-in phase.

canTransitionOut(): boolean

Whether the scene can transition out.

isFinished(): boolean

Whether the scene is finished.

isCached(): boolean

Whether the scene is cached.

Lifecycle

enterInitial(): void

Enters the initial state.

enterAfterTransitionIn(): void

Enters the state after transition-in.

enterCanTransitionOut(): void

Enters the state where transition-out is possible.

Examples

import {makeScene2D, Circle} from '@wangyaoshen/locus';

export default makeScene2D(function* (view) {
const circle = new Circle({
radius: 100,
fill: 'red',
});

view.add(circle);

yield;
});