Skip to main content

Class: SpriteText

A sprite that can be used to display text. This is highly inspired by the THREE.SpriteText library.

Sprite text uses ColorText internally to generate the texture that supports multiple colors in the same text.

Sprite texts live exclusively on SCENE_OVERLAY_LAYER, so they only render through cameras that have that layer enabled.

Sprite text

Hierarchy​

  • Sprite

    ↳ SpriteText

    ↳↳ NameTag

Constructors​

constructor​

• new SpriteText(text?, textHeight?): SpriteText

Create a new sprite text.

Parameters​

NameTypeDefault valueDescription
textstring""The text to display.
textHeightnumber10The height of the text in pixels.

Returns​

SpriteText

Overrides​

Sprite.constructor

Accessors​

backgroundColor​

• get backgroundColor(): string | false

Get the background color of the sprite text.

Returns​

string | false

• set backgroundColor(color): void

Set the background color of the sprite text. This will regenerate the sprite.

Parameters​

NameType
colorstring | false

Returns​

void


borderColor​

• get borderColor(): string

Get the border color of the sprite text.

Returns​

string

• set borderColor(borderColor): void

Set the border color of the sprite text. This will regenerate the sprite.

Parameters​

NameType
borderColorstring

Returns​

void


borderRadius​

• get borderRadius(): number

Get the border radius of the sprite text.

Returns​

number

• set borderRadius(borderRadius): void

Set the border radius of the sprite text. This will regenerate the sprite.

Parameters​

NameType
borderRadiusnumber

Returns​

void


borderWidth​

• get borderWidth(): number

Get the border width of the sprite text.

Returns​

number

• set borderWidth(borderWidth): void

Set the border width of the sprite text. This will regenerate the sprite.

Parameters​

NameType
borderWidthnumber

Returns​

void


fontFace​

• get fontFace(): string

Get the font face of the sprite text.

Returns​

string

• set fontFace(fontFace): void

Set the font face of the sprite text. This will regenerate the sprite.

Parameters​

NameType
fontFacestring

Returns​

void


fontSize​

• get fontSize(): number

Get the font size of the sprite text.

Returns​

number

• set fontSize(fontSize): void

Set the font size of the sprite text. This will regenerate the sprite.

Parameters​

NameType
fontSizenumber

Returns​

void


fontWeight​

• get fontWeight(): string

Get the font weight of the sprite text.

Returns​

string

• set fontWeight(fontWeight): void

Set the font weight of the sprite text. This will regenerate the sprite.

Parameters​

NameType
fontWeightstring

Returns​

void


padding​

• get padding(): number

Get the padding of the sprite text. This is the space between the text and the border.

Returns​

number

• set padding(padding): void

Set the padding of the sprite text. This is the space between the text and the border. This will regenerate the sprite.

Parameters​

NameType
paddingnumber

Returns​

void


strokeColor​

• get strokeColor(): string

Get the stroke color of the sprite text. In other words, the color of the text.

Returns​

string

• set strokeColor(strokeColor): void

Set the stroke color of the sprite text. In other words, the color of the text. This will regenerate the sprite.

Parameters​

NameType
strokeColorstring

Returns​

void


strokeWidth​

• get strokeWidth(): number

Get the stroke width of the sprite text.

Returns​

number

• set strokeWidth(strokeWidth): void

Set the stroke width of the sprite text. This will regenerate the sprite.

Parameters​

NameType
strokeWidthnumber

Returns​

void


text​

• get text(): string

Get the text rendered in the sprite.

Returns​

string

• set text(text): void

Set the text to display. This will regenerate the sprite.

Parameters​

NameType
textstring

Returns​

void


textHeight​

• get textHeight(): number

Get the text height in pixels.

Returns​

number

• set textHeight(textHeight): void

Set the text height to display. This will regenerate the sprite.

Parameters​

NameType
textHeightnumber

Returns​

void

Methods​

dispose​

▸ dispose(): void

Free the label's GPU texture and material. The quad geometry is three's shared sprite geometry and stays. Call once the sprite has left the scene for good.

Returns​

void