## Constructors

- [Animation](/content/docs/Animation/index.html)
- [IsoCharacter](/content/docs/IsoCharacter/index.html)
- [Path](/content/docs/Path/index.html)
- [PhysicsObject](/content/docs/PhysicsObject/index.html)
- [SceneObject](/content/docs/SceneObject/index.html)
- [SceneObjectGroup](/content/docs/SceneObjectGroup/index.html)
- [Sprite](/content/docs/Sprite/index.html)
- [TextSprite](/content/docs/TextSprite/index.html)
- [TilemapCharacter](/content/docs/TilemapCharacter/index.html)
- [wade](/content/docs/wade/index.html)
- [wade.drawFunctions](/content/docs/wade.drawFunctions)
- [wade.iso](/content/docs/wade.iso)
- [wade.physics](/content/docs/wade.physics)
- [wade.tilemap](/content/docs/wade.tilemap)
- [wade.vec2](/content/docs/wade.vec2)

## TextSprite

# Constructor Summary

**TextSprite**

A Text Sprite is used to display strings in a WADE app.

# Functions Summary

**TextSprite.cache** _()_

Draw the text sprite to an image and subsequently use that image to display the text sprite when it needs to be rendered

**TextSprite.clone** _()_

Clone the text sprite

**TextSprite.getFirstLine** _()_

Get the index of the first line of text that is being drawn

**TextSprite.getLine** _(lineIndex)_

Get the width of a single line of text

**TextSprite.getLineWidth** _(lineIndex)_

Get the width of a specific line of text

**TextSprite.getNumLines** _()_

Get the current number of lines

**TextSprite.getText** _()_

Get the text currently associated with the sprite

**TextSprite.isCached** _()_

Check whether this TextSprite is currently cached (as a result of calling TextSprite.cache), and the cached image is up to date

**TextSprite.scaleBounds** _(scaleX, scaleY)_

Scale the bounding box of the text sprite

**TextSprite.serialize** _(stringify, propertiesToExclude)_

Export this TextSprite to an object that can then be used to create a new TextSprite like this one (by passing the resulting object to the TextSprite constructor).

**TextSprite.setAlignment** _(alignment)_

Set the text alignment

**TextSprite.setColor** _(color)_

Set the text color.

**TextSprite.setFirstLine** _(firstLine)_

Set the index of first line of text to be drawn (i.e. the number of lines to skip)

**TextSprite.setFixedSize** _(toggle)_

Use a fixed size for this sprite. This prevents expensive calculations that happen when the text (or font, shadows and other properties) change, and the bounding box of the sprite needs to be updated.

**TextSprite.setFont** _(font)_

Set a font style for the text sprite.

**TextSprite.setLineSpacing** _(lineSpacing)_

Set the space between lines of text

**TextSprite.setMaxLines** _(maxLines)_

Set the maximum number of lines that the text is allowed to contain. Any text that doesn't fit in that number of lines will not be drawn.

**TextSprite.setMaxWidth** _(maxWidth)_

The maximum width of a line of text. If, according to the current font style, the text to display is longer than the specified width, it will be displayed on multiple lines.

**TextSprite.setOutline** _(width, color)_

Set the width and color of the text outline

**TextSprite.setShadow** _(color, blur, offsetX, offsetY)_

Set a shadow to draw around the text sprite

**TextSprite.setText** _(text)_

Set the text for the sprite

# Constructor Details

**TextSprite**

A Text Sprite is used to display strings in a WADE app.

string  text  (optional): A string to display when the sprite is drawn. You can also use this constructor by passing in a single object (so just the first parameter) that contains all the TextSprite properties that you want to set (see remarks below for more details).

string  \[font='12px : Arial'\] An HTML font style description. For example '20px Verdana'.

string  color  (optional): An HTML color string. For example 'red', '#f00, '#ff0000', or 'rgba(255,0,0,0.5)'

string  alignment  (optional, defaults to 'left'): A string describing the alignment property for the text, relative to its pivot position. Valid values are 'left', 'right' and 'center'.

number  \[layerId : = wade.defaultLayer\] The id of the layer where the text sprite will be drawn

**Remarks:**

You can also use this constructor by passing in a single object (so just the first parameter) that contains all the TextSprite properties that you want to set. In this case, the object structure is as follows (all fields are optional):

```
{
type: 'TextSprite',
text: string,
font: string,
alignment: string,
color: string,
visible: boolean,
layer: number,
maxWidth: number,
shadowColor: string,
shadowBlur: number,
shadowOffset: {x: number, y: number},
lineSpacing: number,
maxLines: number,
outlineColor: string,
outlineWidth: number,
boundsScale: {x: number, y: number},
sortPoint: {x: number, y: number},
alwaysDraw: boolean,
drawModifiers: array,
properties: {}
}
```

Where properties is a set of properties to copy into the new TextSprite object. Note that properties are deep-copied, and cannot contain functions or cyclical references.

@augments Sprite

^

# Function Details

**TextSprite.cache** _()_

Draw the text sprite to an image and subsequently use that image to display the text sprite when it needs to be rendered

^

**TextSprite.clone** _()_

Clone the text sprite

Returns object : A copy of the text sprite

^

**TextSprite.getFirstLine** _()_

Get the index of the first line of text that is being drawn

Returns number : The index of the first line

^

**TextSprite.getLine** _(lineIndex)_

Get the width of a single line of text

number  lineIndex : The index of the line of text to get

Returns string | undefined : The width of the requested line of text

^

**TextSprite.getLineWidth** _(lineIndex)_

Get the width of a specific line of text

number  lineIndex : The index of the line of text

Returns number : The width of the line in pixels

^

**TextSprite.getNumLines** _()_

Get the current number of lines

Returns number : The current number of lines

^

**TextSprite.getText** _()_

Get the text currently associated with the sprite

Returns string : The text currently associated with the sprite

^

**TextSprite.isCached** _()_

Check whether this TextSprite is currently cached (as a result of calling TextSprite.cache), and the cached image is up to date

Returns boolean : The current cached status

^

**TextSprite.scaleBounds** _(scaleX, scaleY)_

Scale the bounding box of the text sprite

number  scaleX : The scale factor on the x axis

number  scaleY : The scale factor on the y axis

^

**TextSprite.serialize** _(stringify, propertiesToExclude)_

boolean  stringify  (optional): Whether the resulting object should be serialized to JSON. If this is set to true, this function returns a string representation of the TextSprite.

Array  propertiesToExclude  (optional): An array of strings that contains the name of the properties of this TextSprite object that you do NOT want to export.

Returns object|string : An object that represents the current TextSprite

^

**TextSprite.setAlignment** _(alignment)_

Set the text alignment

string  alignment : The text alignment. It can be 'left', 'center', or 'right'

^

**TextSprite.setColor** _(color)_

Set the text color.

string  color : An HTML color string. For example 'red', '#f00, '#ff0000', or 'rgba(255,0,0,0.5)'

^

**TextSprite.setFirstLine** _(firstLine)_

Set the index of first line of text to be drawn (i.e. the number of lines to skip)

@param {number} \[firstLine=0\]

^

**TextSprite.setFixedSize** _(toggle)_

This may be useful when using fixed-size fonts and when you are sure that the size doesn't change, or when you don't care about inaccuracies in the bounding box calculations. Use with care.

boolean  toggle  (optional): Whether to use a fixed size or not. If this parameter is omitted, it is assumed to be true.

^

**TextSprite.setFont** _(font)_

Set a font style for the text sprite.

string  font : A string describing an HTML font style. For example, '20px Verdana'

^

**TextSprite.setLineSpacing** _(lineSpacing)_

Set the space between lines of text

number  lineSpacing : The spacing to use between lines, as a fraction of the font size. The default value is 1.

^

**TextSprite.setMaxLines** _(maxLines)_

Set the maximum number of lines that the text is allowed to contain. Any text that doesn't fit in that number of lines will not be drawn.

number  maxLines : The maximum number of lines. A value of 0 (or falsy) indicates that there is no limit to the number of lines

^

**TextSprite.setMaxWidth** _(maxWidth)_

number  maxWidth : The maximum width of the text, in pixels

^

**TextSprite.setOutline** _(width, color)_

Set the width and color of the text outline

number  width : The width of the outline

string  color  (optional): The color of the text outline. Black by default.

^

**TextSprite.setShadow** _(color, blur, offsetX, offsetY)_

Set a shadow to draw around the text sprite

string  color : An HTML color string

number  blur : The amount of blur, in pixels

number  offsetX : The offset of the shadow along the horizontal axis, in pixels

number  offsetY : The offset of the shadow along the vertical axis, in pixels

^

**TextSprite.setText** _(text)_

Set the text for the sprite

string  text : A string to display when the sprite is drawn

^
