Skip to main content

Util

Index

Namespaces

DrawUtil

DrawUtil:

BorderRadius

BorderRadius:

Represents border radius values

bl

bl: number

Bottom-left

br

br: number

Bottom-right

tl

tl: number

Top-left

tr

tr: number

Top-right

LineCapStyle

LineCapStyle: butt | round | square

A canvas linecap style. "butt" is the default flush style, "round" is a semi-circle cap with a radius half the width of the line, and "square" is a rectangle that is an equal width and half height cap.

circle

  • circle(ctx: CanvasRenderingContext2D, x: number, y: number, radius: number, stroke?: Color, fill?: Color): void
  • Parameters

    • ctx: CanvasRenderingContext2D
    • x: number
    • y: number
    • radius: number
    • stroke: Color = Color.White
    • fill: Color = null

    Returns void

line

  • line(ctx: CanvasRenderingContext2D, color?: Color, x1: number, y1: number, x2: number, y2: number, thickness?: number, cap?: LineCapStyle): void
  • Draw a line on canvas context


    Parameters

    • ctx: CanvasRenderingContext2D

      The canvas context

    • color: Color = Color.Red

      The color of the line

    • x1: number

      The start x coordinate

    • y1: number

      The start y coordinate

    • x2: number

      The ending x coordinate

    • y2: number

      The ending y coordinate

    • thickness: number = 1

      The line thickness

    • cap: LineCapStyle = 'butt'

      The LineCapStyle (butt, round, or square)

    Returns void

point

  • point(ctx: CanvasRenderingContext2D, color?: Color, point: Vector): void
  • Draw the vector as a point onto the canvas.


    Parameters

    • ctx: CanvasRenderingContext2D
    • color: Color = Color.Red
    • point: Vector

    Returns void

roundRect

  • roundRect(ctx: CanvasRenderingContext2D, x: number, y: number, width: number, height: number, radius?: number | BorderRadius, stroke?: Color, fill?: Color): void
  • Draw a round rectangle on a canvas context


    Parameters

    • ctx: CanvasRenderingContext2D

      The canvas context

    • x: number

      The top-left x coordinate

    • y: number

      The top-left y coordinate

    • width: number

      The width of the rectangle

    • height: number

      The height of the rectangle

    • radius: number | BorderRadius = 5

      The border radius of the rectangle

    • stroke: Color = Color.White

      The Color to stroke rectangle with

    • fill: Color = null

      The Color to fill rectangle with

    Returns void

vector

  • vector(ctx: CanvasRenderingContext2D, color: Color, origin: Vector, vector: Vector, scale?: number): void
  • Parameters

    • ctx: CanvasRenderingContext2D
    • color: Color
    • origin: Vector
    • vector: Vector
    • scale: number = 1.0

    Returns void

Enumerations

LogLevel

LogLevel:

Logging level that Excalibur will tag

Debug

Debug: 0

Error

Error: 3

Fatal

Fatal: 4

Info

Info: 1

Warn

Warn: 2

Classes

ConsoleAppender

ConsoleAppender:

Console appender for browsers (i.e. console.log)

constructor

publiclog

  • Logs a message at the given LogLevel


    Parameters

    • level: LogLevel

      Level to log at

    • args: any[]

      Arguments to log

    Returns void

EasingFunctions

EasingFunctions:

Standard easing functions for motion in Excalibur, defined on a domain of [0, duration] and a range from [+startValue,+endValue] Given a time, the function will return a value from positive startValue to positive endValue.

function Linear (t) {
   return t * t;
}

// accelerating from zero velocity
function EaseInQuad (t) {
   return t * t;
}

// decelerating to zero velocity
function EaseOutQuad (t) {
   return t * (2 - t);
}

// acceleration until halfway, then deceleration
function EaseInOutQuad (t) {
   return t < .5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
}

// accelerating from zero velocity
function EaseInCubic (t) {
   return t * t * t;
}

// decelerating to zero velocity
function EaseOutCubic (t) {
   return (--t) * t * t + 1;
}

// acceleration until halfway, then deceleration
function EaseInOutCubic (t) {
   return t < .5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1;
}

constructor

publicstaticEaseInCubic

EaseInCubic: EasingFunction<number> = ...

publicstaticEaseInOutCubic

EaseInOutCubic: EasingFunction<number> = ...

publicstaticEaseInOutQuad

EaseInOutQuad: EasingFunction<number> = ...

publicstaticEaseInQuad

EaseInQuad: EasingFunction<number> = ...

publicstaticEaseOutCubic

EaseOutCubic: EasingFunction<number> = ...

publicstaticEaseOutQuad

EaseOutQuad: EasingFunction<number> = ...

publicstaticLinear

Linear: EasingFunction<number> = ...

publicstaticCreateReversibleEasingFunction

publicstaticCreateVectorEasingFunction

Logger

Logger:

Static singleton that represents the logging facility for Excalibur. Excalibur comes built-in with a ConsoleAppender and ScreenAppender. Derive from Appender to create your own logging appenders.

constructor

publicdefaultLevel

defaultLevel: LogLevel = LogLevel.Info

Gets or sets the default logging level. Excalibur will only log messages if equal to or above this level. Default: LogLevel.Info

publicaddAppender

  • Adds a new Appender to the list of appenders to write to


    Parameters

    Returns void

publicclearAppenders

  • clearAppenders(): void
  • Clears all appenders from the logger


    Returns void

publicdebug

  • debug(...args: any[]): void
  • Writes a log message at the LogLevel.Debug level


    Parameters

    • rest...args: any[]

      Accepts any number of arguments

    Returns void

publicdebugOnce

  • debugOnce(...args: any[]): void
  • Writes a log message once at the LogLevel.Fatal level, if it sees the same args again it wont log


    Parameters

    • rest...args: any[]

      Accepts any number of arguments

    Returns void

publicerror

  • error(...args: any[]): void
  • Writes a log message at the LogLevel.Error level


    Parameters

    • rest...args: any[]

      Accepts any number of arguments

    Returns void

publicerrorOnce

  • errorOnce(...args: any[]): void
  • Writes a log message once at the LogLevel.Error level, if it sees the same args again it won't log


    Parameters

    • rest...args: any[]

      Accepts any number of arguments

    Returns void

publicfatal

  • fatal(...args: any[]): void
  • Writes a log message at the LogLevel.Fatal level


    Parameters

    • rest...args: any[]

      Accepts any number of arguments

    Returns void

publicfatalOnce

  • fatalOnce(...args: any[]): void
  • Writes a log message once at the LogLevel.Fatal level, if it sees the same args again it won't log


    Parameters

    • rest...args: any[]

      Accepts any number of arguments

    Returns void

publicinfo

  • info(...args: any[]): void
  • Writes a log message at the LogLevel.Info level


    Parameters

    • rest...args: any[]

      Accepts any number of arguments

    Returns void

publicinfoOnce

  • infoOnce(...args: any[]): void
  • Writes a log message once at the LogLevel.Info level, if it sees the same args again it wont log


    Parameters

    • rest...args: any[]

      Accepts any number of arguments

    Returns void

publicwarn

  • warn(...args: any[]): void
  • Writes a log message at the LogLevel.Warn level


    Parameters

    • rest...args: any[]

      Accepts any number of arguments

    Returns void

publicwarnOnce

  • warnOnce(...args: any[]): void
  • Writes a log message once at the LogLevel.Warn level, if it sees the same args again it won't log


    Parameters

    • rest...args: any[]

      Accepts any number of arguments

    Returns void

publicstaticgetInstance

  • Gets the current static instance of Logger


    Returns Logger

Observable

Observable<T>:

Simple Observable implementation


Type parameters

  • T

    is the typescript Type that defines the data being observed

constructor

publicobservers

observers: Observer<T>[] = []

publicsubscriptions

subscriptions: (val: T) => any[] = []

clear

  • clear(): void
  • Removes all observers and callbacks


    Returns void

notifyAll

  • notifyAll(message: T): void
  • Broadcasts a message to all observers and callbacks


    Parameters

    • message: T

    Returns void

register

  • Register an observer to listen to this observable


    Parameters

    Returns void

subscribe

  • subscribe(func: (val: T) => any): void
  • Register a callback to listen to this observable


    Parameters

    • func: (val: T) => any

      Returns void

    unregister

    • Remove an observer from the observable


      Parameters

      Returns void

    unsubscribe

    • unsubscribe(func: (val: T) => any): void
    • Remove a callback that is listening to this observable


      Parameters

      • func: (val: T) => any

        Returns void

      ScreenAppender

      ScreenAppender:

      On-screen (canvas) appender

      constructor

      publiccanvas

      canvas: HTMLCanvasElement

      publiclog

      • Logs a message at the given LogLevel


        Parameters

        • level: LogLevel

          Level to log at

        • args: any[]

          Arguments to log

        Returns void

      Interfaces

      Appender

      Appender:

      Contract for any log appender (such as console/screen)

      log

      • Logs a message at the given LogLevel


        Parameters

        • level: LogLevel

          Level to log at

        • args: any[]

          Arguments to log

        Returns void

      EasingFunction

      • EasingFunction(currentTime: number, startValue: TValueToEase, endValue: TValueToEase, duration: number): TValueToEase
      • Parameters

        • currentTime: number
        • startValue: TValueToEase
        • endValue: TValueToEase
        • duration: number

        Returns TValueToEase

      Message

      Message<T>:

      Defines a generic message that can contain any data


      Type parameters

      • T

        is the typescript Type of the data

      data

      data: T

      type

      type: string

      Observer

      Observer<T>:

      Defines an interface for an observer to receive a message via a notify() method


      Type parameters

      • T

      notify

      • notify(message: T): void
      • Parameters

        • message: T

        Returns void

      ScreenAppenderOptions

      ScreenAppenderOptions:

      optionalcolor

      color?: Color

      Provide a text color

      engine

      engine: Engine<any>

      optionalheight

      height?: number

      Optionally set the height of the overlay canvas

      optionalwidth

      width?: number

      Optionally set the width of the overlay canvas

      optionalxPos

      xPos?: number

      Adjust the text offset from the left side of the screen

      optionalzIndex

      zIndex?: number

      Optionally set the CSS zindex of the overlay canvas

      Type Aliases

      MaybeObserver

      MaybeObserver<T>: Partial<Observer<T>>

      Defines an interface for something that might be an observer if a notify() is present


      Type parameters

      • T

      Functions

      addItemToArray

      • addItemToArray<T>(item: T, array: T[]): boolean
      • Add an item to an array list if it doesn't already exist. Returns true if added, false if not and already exists in the array.

        @deprecated

        Will be removed in v0.26.0


        Type parameters

        • T

        Parameters

        • item: T
        • array: T[]

        Returns boolean

      contains

      • contains(array: any[], obj: any): boolean
      • See if an array contains something


        Parameters

        • array: any[]
        • obj: any

        Returns boolean

      delay

      • delay(milliseconds: number, clock?: Clock): Promise<void>
      • Create a promise that resolves after a certain number of milliseconds

        It is strongly recommended you pass the excalibur clock so delays are bound to the excalibur clock which would be unaffected by stop/pause.


        Parameters

        • milliseconds: number
        • optionalclock: Clock

        Returns Promise<void>

      fail

      • fail(message: never): never
      • Used for exhaustive checks at compile time


        Parameters

        • message: never

        Returns never

      getPosition

      • getPosition(el: HTMLElement): Vector
      • Find the screen position of an HTML element


        Parameters

        • el: HTMLElement

        Returns Vector

      isObject

      • isObject(item: any): item is object
      • Simple object check.


        Parameters

        • item: any

        Returns item is object

      mergeDeep

      • mergeDeep<T>(target: T, ...sources: T[]): T
      • Deep merge two objects.


        Type parameters

        • T: object

        Parameters

        • target: T
        • rest...sources: T[]

        Returns T

      omit

      • omit<TObject, Keys>(object: TObject, keys: Keys[]): Omit<TObject, Keys>
      • Remove keys from object literals


        Type parameters

        • TObject: Object
        • Keys: string | number | symbol

        Parameters

        • object: TObject
        • keys: Keys[]

        Returns Omit<TObject, Keys>

      removeItemFromArray

      • removeItemFromArray<T>(item: T, array: T[]): boolean
      • Remove an item from an list

        @deprecated

        Will be removed in v0.26.0


        Type parameters

        • T

        Parameters

        • item: T
        • array: T[]

        Returns boolean