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.

Hierarchy

Implements

Constructors

Properties

_follow: Actor
_isShaking: boolean = false
_isZooming: boolean = false
acc: Vector = Vector.Zero

Get or set the camera's acceleration

az: number = 0

Get or set zoom acceleration

dz: number = 0

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

eventDispatcher: EventDispatcher<any>

Direct access to the game object event dispatcher.

inverse: AffineMatrix = ...
rotation: number = 0

Current rotation of the camera

strategy: StrategyContainer = ...
transform: AffineMatrix = ...
vel: Vector = Vector.Zero

Get or set the camera's velocity

Accessors

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

    Returns number

  • set angularVelocity(value: number): void
  • Parameters

    • value: number

    Returns void

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

    Returns number

  • set ax(value: number): void
  • Parameters

    • value: number

    Returns void

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

    Returns number

  • set ay(value: number): void
  • Parameters

    • value: number

    Returns void

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

    Returns number

  • set dx(value: number): void
  • Parameters

    • value: number

    Returns void

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

    Returns number

  • set dy(value: number): void
  • Parameters

    • value: number

    Returns void

  • get isInitialized(): boolean
  • Returns boolean

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

    Returns number

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

    Parameters

    • value: number

    Returns void

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

    Returns number

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

    Parameters

    • value: number

    Returns void

  • get zoom(): number
  • Returns number

  • set zoom(val: number): void
  • Parameters

    • val: number

    Returns void

Methods

  • Internal

    It is not recommended that internal excalibur methods be overridden, do so at your own risk.

    Internal _preupdate handler for onPostUpdate lifecycle event

    Parameters

    Returns void

  • Internal

    It is not recommended that internal excalibur methods be overridden, do so at your own risk.

    Internal _preupdate handler for onPreUpdate lifecycle event

    Parameters

    Returns void

  • Clears all camera strategies from the camera

    Returns void

  • Emits a new event

    Parameters

    • eventName: string

      Name of the event to emit

    • eventObject: any

      Data associated with this event

    Returns void

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

    Returns Vector

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

    Returns

    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.

    Parameters

    • pos: Vector

      The target position to move to

    • duration: number

      The duration in milliseconds the move should last

    • Optional easingFn: Util.EasingFunction = EasingFunctions.EaseInOutCubic

      An optional easing function (ex.EasingFunctions.EaseInOutCubic by default)

    Returns Promise<Vector>

  • Safe to override onPostUpdate lifecycle event handler. Synonymous with .on('preupdate', (evt) =>{...})

    onPostUpdate is called directly after a scene is updated.

    Parameters

    Returns 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
    • _delta: number

    Returns 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
    • _delta: number

    Returns void

  • Parameters

    Returns 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

  • 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: Util.EasingFunction = EasingFunctions.EaseInOutCubic

    Returns Promise<boolean>