Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Text

Represents a managed paragraph of text. This class is not a Sprite but is easily integrable to one.

Hierarchy

  • Text

Index

Constructors

constructor

  • Parameters

    • text: string

      Text to render

    • position: Point

      Upper-left corner of text

    • width: number

      Desired width. Should be at least large enougth to put a word on a line

    • Default value font: Font = new Font()

      Font used

    • Default value align: TextAlign = TextAlign.LEFT

      Alignment type

    Returns Text

Properties

Protected align

align: TextAlign

Alignment type

Protected font

font: Font

Font used

Protected height

height: number

Height of the text

Protected justifySpace

justifySpace: Array<number>

Defined space size for justified text

Protected lineSpace

lineSpace: Array<number>

Space before first word in line

Protected lines

lines: Array<Array<string>>

Text cut in lines of words

Protected localCanvas

localCanvas: HTMLCanvasElement

Local rendering canvas (offset buffer)

Protected localCtx

localCtx: CanvasRenderingContext2D

Local rendering context

Protected position

position: Point

Upper-left corner of text

Protected space

space: number

Defined space size except for justified text

Protected text

text: string

Text to render

Protected width

width: number

Desired width. Should be at least large enougth to put a word on a line

Methods

Protected calculate

  • calculate(context: CanvasRenderingContext2D): void
  • calculates text rendering properties

    Parameters

    • context: CanvasRenderingContext2D

      Rendering context

    Returns void

getHeight

  • getHeight(): number
  • Retrieves height of the text block.

    Returns number

    Text height

Protected prerender

  • prerender(context: CanvasRenderingContext2D): void
  • Renders text on an offscreen canvas

    Parameters

    • context: CanvasRenderingContext2D

      Rendering context

    Returns void

render

  • render(context: CanvasRenderingContext2D): void
  • Renders text on client canvas. useful for Sprite integration

    Parameters

    • context: CanvasRenderingContext2D

      Rendering context

    Returns void

Protected setLineSpace

  • setLineSpace(currentLine: Array<string>, currentPosition: number, lastLine?: boolean): void
  • Calculates line spacing

    Parameters

    • currentLine: Array<string>

      The line to parse

    • currentPosition: number

      Size of text on line

    • Default value lastLine: boolean = false

      If the line is the last one (Used to avoid oddly justified text)

    Returns void

Protected update

  • update(): void

Generated using TypeDoc