Skip to main content

Camera

Cameras

Camera is the base class for all Excalibur cameras. Cameras are used to move around your game and set focus. They are used to determine what is "off screen" and can be used to scale the game.

Implements

Index

Constructors

constructor

Properties

publicacc

acc: Vector = Vector.Zero

Get or set the camera's acceleration

publicaz

az: number = 0

Get or set zoom acceleration

publicdrawPos

drawPos: Vector = ...

Interpolated camera position if more draws are running than updates

Enabled when Engine.fixedUpdateFps is enabled, in all other cases this will be the same as pos

publicdz

dz: number = 0

Get or set rate of change in zoom, defaults to 0

publicevents

events: EventEmitter<CameraEvents> = ...

publicinverse

inverse: AffineMatrix = ...

publicrotation

rotation: number = 0

Current rotation of the camera

publicstrategy

strategy: StrategyContainer = ...

publictransform

transform: AffineMatrix = ...

publicvel

vel: Vector = Vector.Zero

Get or set the camera's velocity

Accessors

publicangularVelocity

  • get angularVelocity(): number
  • set angularVelocity(value: number): void
  • Get or set the camera's angular velocity


    Returns number

  • Parameters

    • value: number

    Returns void

publicax

  • get ax(): number
  • set ax(value: number): void
  • Get or set the camera's x acceleration


    Returns number

  • Parameters

    • value: number

    Returns void

publicay

  • get ay(): number
  • set ay(value: number): void
  • Get or set the camera's y acceleration


    Returns number

  • Parameters

    • value: number

    Returns void

publicdx

  • get dx(): number
  • set dx(value: number): void
  • Get or set the camera's x velocity


    Returns number

  • Parameters

    • value: number

    Returns void

publicdy

  • get dy(): number
  • set dy(value: number): void
  • Get or set the camera's y velocity


    Returns number

  • Parameters

    • value: number

    Returns void

publicisInitialized

  • get isInitialized(): boolean
  • Returns boolean

publicpos

publicviewport

  • Gets the bounding box of the viewport of this camera in world coordinates


    Returns BoundingBox

publicx

  • get x(): number
  • set x(value: number): void
  • Get the camera's x position


    Returns number

  • Set the camera's x position (cannot be set when following an Actor or when moving)


    Parameters

    • value: number

    Returns void

publicy

  • get y(): number
  • set y(value: number): void
  • Get the camera's y position


    Returns number

  • Set the camera's y position (cannot be set when following an Actor or when moving)


    Parameters

    • value: number

    Returns void

publiczoom

  • get zoom(): number
  • set zoom(val: number): void
  • Returns number

  • Parameters

    • val: number

    Returns void

Methods

public_initialize

  • _initialize(engine: Engine<any>): void
  • Parameters

    Returns void

publicaddStrategy

  • Adds a new camera strategy to this camera


    Type parameters

    • T

    Parameters

    Returns void

publicclearAllStrategies

  • clearAllStrategies(): void
  • Clears all camera strategies from the camera


    Returns void

publicdraw

  • Applies the relevant transformations to the game canvas to "move" or apply effects to the Camera


    Parameters

    Returns void

publicemit

  • emit<TEventName>(eventName: TEventName, event: CameraEvents[TEventName]): void
  • emit(eventName: string, event?: any): void

publicgetFocus

  • Returns the focal point of the camera, a new point giving the x and y position of the camera


    Returns Vector

publicmove

  • This moves the camera focal point to the specified position using specified easing function. Cannot move when following an Actor.


    Parameters

    Returns Promise<Vector>

    A Promise that resolves when movement is finished, including if it's interrupted. The Promise value is the Vector of the target position. It will be rejected if a move cannot be made.

publicoff

  • off<TEventName>(eventName: TEventName, handler: Handler<CameraEvents[TEventName]>): void
  • off(eventName: string, handler: Handler<unknown>): void
  • off(eventName: string): void

publicon

publiconInitialize

  • onInitialize(engine: Engine<any>): void
  • Safe to override onPostUpdate lifecycle event handler. Synonymous with .on('preupdate', (evt) =>{...})

    onPostUpdate is called directly after a scene is updated.


    Parameters

    Returns void

publiconPostUpdate

  • onPostUpdate(engine: Engine<any>, elapsedMs: number): void
  • Safe to override onPostUpdate lifecycle event handler. Synonymous with .on('preupdate', (evt) =>{...})

    onPostUpdate is called directly after a scene is updated.


    Parameters

    • engine: Engine<any>
    • elapsedMs: number

    Returns void

publiconPreUpdate

  • onPreUpdate(engine: Engine<any>, elapsedMs: number): void
  • Safe to override onPreUpdate lifecycle event handler. Synonymous with .on('preupdate', (evt) =>{...})

    onPreUpdate is called directly before a scene is updated.


    Parameters

    • engine: Engine<any>
    • elapsedMs: number

    Returns void

publiconce

publicremoveStrategy

publicrunStrategies

  • runStrategies(engine: Engine<any>, elapsedMs: number): void
  • Parameters

    • engine: Engine<any>
    • elapsedMs: number

    Returns void

publicshake

  • shake(magnitudeX: number, magnitudeY: number, duration: number): void
  • Sets the camera to shake at the specified magnitudes for the specified duration


    Parameters

    • magnitudeX: number

      The x magnitude of the shake

    • magnitudeY: number

      The y magnitude of the shake

    • duration: number

      The duration of the shake in milliseconds

    Returns void

publicupdate

  • update(engine: Engine<any>, elapsedMs: number): void
  • Parameters

    • engine: Engine<any>
    • elapsedMs: number

    Returns void

publicupdateTransform

  • updateTransform(pos: Vector): void
  • Parameters

    Returns void

publicupdateViewport

  • updateViewport(): void
  • Returns void

publiczoomOverTime

  • zoomOverTime(scale: number, duration?: number, easingFn?: EasingFunction): Promise<boolean>
  • Zooms the camera in or out by the specified scale over the specified duration. If no duration is specified, it take effect immediately.


    Parameters

    • scale: number

      The scale of the zoom

    • duration: number = 0

      The duration of the zoom in milliseconds

    • easingFn: EasingFunction = EasingFunctions.EaseInOutCubic

    Returns Promise<boolean>