Class SpritesLayer

Hierarchy (view full)

Constructors

Accessors

  • get canvas(): HTMLCanvasElement
  • Get output canvas

    Returns HTMLCanvasElement

Methods

  • Add a renderer to this layer. It's constructed with the layer's own width/height, so callers pass only the class and its config - never dimensions.

    Type Parameters

    Parameters

    • id: string

      unique id for this renderer within the layer

    • rendererClass: (new (width, height, params?) => T)

      the renderer class (not an instance)

        • new (width, height, params?): T
        • Parameters

          • width: number
          • height: number
          • Optional params: P

          Returns T

    • Optional params: P

      optional config forwarded to the renderer constructor

    • active: boolean = true

      if true (default) the renderer is added to the render queue

    Returns Promise<T>

    the constructed, initialised renderer instance

    Example

    const shaky = await layer.addRenderer('shaky', ShakyRenderer, { mode: 'decay' })
    shaky.triggerShake()
  • Remove a renderer from this layer. If it was in the render queue, it will be removed from there too.

    Parameters

    • id: string

      Renderer id to remove. If not found, this is a no-op.

    Returns void

  • Re-enable a previously deactivated renderer, restoring it at its original position in the queue. The renderer must have been registered via the constructor renderers dict or addRenderer.

    Parameters

    • id: string

      Renderer id to activate.

    Returns void

    Throws

    if the renderer is not registered on this layer.

  • Animate layer opacity from its current value to 1 (fully opaque).

    Parameters

    • duration: number

      fade duration in ms

    • easing: EasingFunction = Easing.easeOutSine

      easing function (defaults to easeOutSine)

    Returns Promise<void>

    resolves when the fade completes

  • Animate layer opacity from its current value to 0 (fully transparent).

    Parameters

    • duration: number

      fade duration in ms

    • easing: EasingFunction = Easing.easeOutSine

      easing function (defaults to easeOutSine)

    Returns Promise<void>

    resolves when the fade completes

  • Create a sprite and add it to the layer

    Parameters

    • id: string
    • spriteSheet: ImageBitmap
    • hFrameOffset: number

      (horizontal distance between frames)

    • vFrameOffset: number

      (vertical distance between frames)

    • animations: SpriteAnimationItem[]
    • x: string | number

      horizontal position on the layer: pixels (12) or a percentage string ('50%')

    • y: string | number

      vertical position on the layer: pixels (12) or a percentage string ('50%')

    Returns Promise<Sprite>

  • Add an existing Sprite object to the layer ad x,y position

    Parameters

    • id: string
    • sprite: Sprite
    • _x: string | number

      horizontal position: pixels (12) or a percentage string ('50%')

    • _y: string | number

      vertical position: pixels (12) or a percentage string ('50%')

    • Optional v: boolean

    Returns boolean

    true if sprite was assed false otherwise

  • This layer's render loop is driven by run()/stop(), not by having renderers, so BaseLayer.setVisibility(true) alone would leave the loop stopped and the output frozen when the layer is shown while sprites are running (they keep animating while hidden). Resume compositing on show.

    Parameters

    • isVisible: boolean

    Returns void