Skip to main content

ExcaliburGraphicsContext2DCanvas

Implements

Index

Constructors

constructor

Properties

publicbackgroundColor

backgroundColor: Color = Color.ExcaliburBlue

Set the background color of the graphics context, default is Color.ExcaliburBlue

debug

debug: ExcaliburGraphicsContext2DCanvasDebug = ...

Access the debug drawing api

publicsnapToPixel

snapToPixel: boolean = false

Snaps all drawings to the nearest pixel truncated down, by default false

publicreadonlyuseDrawSorting

useDrawSorting: boolean = false

Unused in Canvas implementation

publicz

z: number = 0

Unused in Canvas implementation

Accessors

publicheight

  • get height(): number
  • Returns number

publicmaterial

  • get material(): Material | null | undefined
  • set material(material: Material | null | undefined): void
  • Gets or sets the material to be used in the current context's drawings

    This allows customs shaders to be used but draw calls are no longer batched by default.


    Returns Material | null | undefined

  • Gets or sets the material to be used in the current context's drawings

    This allows customs shaders to be used but draw calls are no longer batched by default.


    Parameters

    Returns void

publicopacity

  • get opacity(): number
  • set opacity(value: number): void
  • Sets the opacity of the current Graphic being drawn, default is 1


    Returns number

  • Sets the opacity of the current Graphic being drawn, default is 1


    Parameters

    • value: number

    Returns void

publicsmoothing

  • get smoothing(): boolean
  • set smoothing(value: boolean): void
  • Enable smoothed drawing (also known as anti-aliasing), by default true


    Returns boolean

  • Enable smoothed drawing (also known as anti-aliasing), by default true


    Parameters

    • value: boolean

    Returns void

publictint

  • get tint(): Color | null | undefined
  • set tint(color: Color | null | undefined): void
  • Sets the tint color to be multiplied by any images drawn, default is black 0xFFFFFFFF


    Returns Color | null | undefined

  • Sets the tint color to be multiplied by any images drawn, default is black 0xFFFFFFFF


    Parameters

    • color: Color | null | undefined

    Returns void

publicwidth

  • get width(): number
  • Returns number

Methods

publicaddPostProcessor

  • Add a post processor to the graphics context

    Post processors are run in the order they were added.


    Parameters

    Returns void

publicbeginDrawLifecycle

  • beginDrawLifecycle(): void
  • Returns void

clear

  • clear(): void
  • Clears the screen with the current background color


    Returns void

publicclearPostProcessors

  • clearPostProcessors(): void
  • Remove all post processors from the graphics context


    Returns void

publiccreateMaterial

  • Creates and initializes the material which compiles the internal shader


    Parameters

    Returns Material

dispose

  • dispose(): void
  • Returns void

publicdraw

  • draw<TRenderer>(_rendererName: TRenderer[type], ..._args: Parameters<TRenderer[draw]>): void
  • Issue a draw command to a named renderer plugin.

    The renderer is looked up by name (auto-instantiating lazy renderers) and its draw() method is called with the provided arguments. Draw calls are sorted by z-index and renderer priority before flushing.

    In the Canvas 2D fallback context this is a no-op.


    Type parameters

    Parameters

    • _rendererName: TRenderer[type]
    • rest..._args: Parameters<TRenderer[draw]>

    Returns void

publicdrawCircle

  • drawCircle(pos: Vector, radius: number, color: Color, stroke?: Color, thickness?: number): void
  • Draw a circle to the Excalibur Graphics context


    Parameters

    • pos: Vector
    • radius: number
    • color: Color
    • optionalstroke: Color

      Optionally specify the stroke color

    • optionalthickness: number

    Returns void

drawImage

  • drawImage(image: HTMLImageSource, x: number, y: number): void
  • drawImage(image: HTMLImageSource, x: number, y: number, width: number, height: number): void
  • drawImage(image: HTMLImageSource, sx: number, sy: number, swidth?: number, sheight?: number, dx?: number, dy?: number, dwidth?: number, dheight?: number): void
  • Draw an image to the Excalibur Graphics context at an x and y coordinate using the images width and height


    Parameters

    Returns void

publicdrawLine

  • Draw a solid line to the Excalibur Graphics context


    Parameters

    Returns void

publicdrawRectangle

  • drawRectangle(pos: Vector, width: number, height: number, color: Color): void
  • Draw a solid rectangle to the Excalibur Graphics context


    Parameters

    Returns void

publicendDrawLifecycle

  • endDrawLifecycle(): void
  • Returns void

flush

  • flush(): void
  • Flushes the batched draw calls to the screen


    Returns void

publicget

  • Look up a registered renderer plugin by its type name.

    If the renderer was lazily registered, it will be instantiated and initialized on first access.


    Parameters

    • _rendererName: string

    Returns RendererPlugin | undefined

    The renderer plugin, or undefined if not found

publicgetTransform

  • Gets the current transform


    Returns AffineMatrix

publiclazyRegister

  • lazyRegister<TRenderer>(_type: TRenderer[type], _renderer: () => TRenderer): void
  • Lazily register a custom renderer plugin with the graphics context.

    The renderer factory is stored and only instantiated the first time it is requested via ExcaliburGraphicsContext.get. Use this for renderers that may not be needed in every game to avoid unnecessary initialization cost.

    In the Canvas 2D fallback context this is a no-op.


    Type parameters

    Parameters

    • _type: TRenderer[type]
    • _renderer: () => TRenderer

      Returns void

    publicmultiply

    • Multiplies the current transform by a matrix


      Parameters

      Returns void

    publicregister

    • register<T>(_renderer: T): void
    • Register a custom renderer plugin with the graphics context.

      The renderer is immediately initialized with the WebGL context. Use this for renderers that should always be available.

      In the Canvas 2D fallback context this is a no-op.


      Type parameters

      Parameters

      • _renderer: T

      Returns void

    publicremovePostProcessor

    • Remove a specific post processor from the graphics context


      Parameters

      Returns void

    publicresetTransform

    • resetTransform(): void
    • Resets the current transform to the identity matrix


      Returns void

    restore

    • restore(): void
    • Restore the state of the canvas from the stack


      Returns void

    rotate

    • rotate(angle: number): void
    • Rotate the context about the current origin


      Parameters

      • angle: number

      Returns void

    save

    • save(): void
    • Save the current state of the canvas to the stack (transforms and opacity)


      Returns void

    scale

    • scale(x: number, y: number): void
    • Scale the context by an x and y factor


      Parameters

      • x: number
      • y: number

      Returns void

    translate

    • translate(x: number, y: number): void
    • Translate the origin of the context by an x and y


      Parameters

      • x: number
      • y: number

      Returns void

    publicupdateViewport

    • Update the context with the current viewport dimensions (used in resizing)


      Parameters

      Returns void