Skip to main content

Director <TKnownScenes>

The Director is responsible for managing scenes and changing scenes in Excalibur.

It deals with transitions, scene loaders, switching scenes

This is used internally by Excalibur, generally not mean to be instantiated end users directly.

Index

Constructors

constructor

  • Type parameters

    • TKnownScenes: string = any

    Parameters

    Returns Director<TKnownScenes>

Properties

currentScene

currentScene: Scene<unknown>

Current scene playing in excalibur

currentSceneName

currentSceneName: string

Current scene's name

currentTransition

currentTransition: Transition

Current transition if any

publicevents

mainLoader

mainLoader: DefaultLoader

publicreadonlyrootScene

rootScene: Scene<unknown>

The default [[Scene]] of the game, use [[Engine.goToScene]] to transition to different scenes.

publicreadonlyscenes

scenes: SceneMap<WithRoot<TKnownScenes>> = ...

All registered scenes in Excalibur

startScene

startScene: string

Accessors

isInitialized

  • get isInitialized(): boolean
  • Returns boolean

publicisTransitioning

  • get isTransitioning(): boolean
  • Gets whether the director currently transitioning between scenes

    Useful if you need to block behavior during transition


    Returns boolean

Methods

add

assertAdded

  • assertAdded<TScene>(name: TScene): Director<TKnownScenes | TScene>
  • Returns the same Director, but asserts a scene DOES exist to the type system


    Type parameters

    • TScene: string

    Parameters

    • name: TScene

    Returns Director<TKnownScenes | TScene>

assertRemoved

  • assertRemoved<TScene>(name: TScene): Director<Exclude<TKnownScenes, TScene>>
  • Returns the same Director, but asserts a scene DOES NOT exist to the type system


    Type parameters

    • TScene: string

    Parameters

    • name: TScene

    Returns Director<Exclude<TKnownScenes, TScene>>

configureStart

  • Configures the start scene, and optionally the transition & loader for the director

    Typically this is called at the beginning of the game to the start scene and transition and never again.


    Parameters

    Returns void

getDeferredScene

getSceneDefinition

  • Returns a scene by name if it exists, might be the constructor and not the instance of a scene


    Parameters

    • name: string

    Returns Scene<unknown> | SceneConstructor

getSceneInstance

  • getSceneInstance(scene: string): Scene<unknown>
  • Retrieves a scene instance by key if it's registered.

    This will call any constructors that were given as a definition


    Parameters

    • scene: string

    Returns Scene<unknown>

getSceneName

  • getSceneName(scene: Scene<unknown>): string
  • Returns the name of the registered scene, null if none can be found


    Parameters

    Returns string

goto

  • goto(destinationScene: string | TKnownScenes, options?: GoToOptions<any>): Promise<void>
  • Go to a specific scene, and optionally override loaders and transitions


    Parameters

    • destinationScene: string | TKnownScenes
    • optionaloptions: GoToOptions<any>

    Returns Promise<void>

maybeLoadScene

  • maybeLoadScene(scene: string, hideLoader?: boolean): Promise<void>
  • Triggers scene loading if has not already been loaded


    Parameters

    • scene: string
    • hideLoader: boolean = false

    Returns Promise<void>

onInitialize

  • onInitialize(): Promise<void>
  • Initialize the director's internal state


    Returns Promise<void>

playTransition

  • playTransition(transition: Transition): Promise<void>
  • Plays a transition in the current scene


    Parameters

    Returns Promise<void>

remove

  • Parameters

    Returns void

swapScene

  • swapScene<TData>(destinationScene: string, data?: TData): Promise<void>
  • Swaps the current and destination scene after performing required lifecycle events


    Type parameters

    • TData = undefined

    Parameters

    • destinationScene: string
    • optionaldata: TData

    Returns Promise<void>