TextSprite Class

Extends CanvasSprite
Module: Meshes

Text sprite is used to represent text as a sprite.

This approach is memory expensive since it needs to write a new texture for each text. But allows the used to access any font available in the browser.

The text is rendered to canvas and then copied to a texture. It automatically ajusts the object scale to match the text aspect.

Methods

setText

(
  • text
)

Set the text to be displayed.

Parameters:

  • text String

updateCanvas

()

Update the canvas texture.

Redraw text into the canvas and update scale.

Attributes

align

String

Horizontal text alignment can be

  • TextSprite.LEFT
  • TextSprite.RIGHT
  • TextSprite.CENTER

CENTER

String static

Align text to the center.

color

String

CSS color of the text.

font

String

CSS Font style to be used.

LEFT

String static

Align text to the left side.

outline

Boolean

Indicates if the text has an outline border.

outlineColor

String

CSS color of the outline.

outlineWidth

Number

Width of the text outline.

resolution

Number

Vertical resolution of the texture created from canvas used.

Should always be a npot of 2.

RIGHT

String static

Align text to the right side.

size

Number

Scale of the object.

text

String

Text of this object.