Constructors

- TextSprite

Constructor Summary

TextSprite
(text,
font,
color,
alignment,
layerId)
A Text Sprite is used to display strings in a WADE app.

Functions Summary

clone()
Clone the text sprite
getLine
(lineIndex)
Get the width of a single line of text
getLineWidth
(lineIndex)
Get the width of a specific line of text
Get the current number of lines
Get the text currently associated with the sprite
scaleBounds
(scaleX,
scaleY)
Scale the bounding box of the text sprite
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).
setAlignment
(alignment)
Set the text alignment
setColor
(color)
Set the text color.
setFixedSize
(toggle)
Use a fixed size for this sprite.
setFont
(font)
Set a font style for the text sprite.
setLineSpacing
(lineSpacing)
Set the space between lines of text
setMaxLines
(maxLines)
Set the maximum number of lines that the text is allowed to contain.
setMaxWidth
(maxWidth)
The maximum width of a line of text.
setOutline
(width,
color)
Set the width and color of the text outline
setShadow
(color,
blur,
offsetX,
offsetY)
Set a shadow to draw around the text sprite
setText
(text)
Set the text for the sprite

Constructor Details


(text,
font,
color,
alignment,
layerId)
A Text Sprite is used to display strings in a WADE app.

Parameters:


{string}textOptional
A string to diplay 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}fontOptional, Default: '12px Arial'
An HTML font style description. For example '20px Verdana'.
{string}colorOptional
An HTML color string. For example 'red', '#f00, '#ff0000', or 'rgba(255,0,0,0.5)'
{string}alignmentOptional, Default: 'left'
A string describing the alignment property for the text, relative to its pivot position. Valid values are 'left', 'right' and 'center'.
{number}layerIdOptional, Default: 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,
    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.

Function Details

()
Clone the text sprite

Returns:


{object}
A copy of the text sprite

(lineIndex)
Get the width of a single line of text

Parameters:


{number}lineIndex
The index of the line of text to get

Returns:


{string | undefined}
The width of the requested line of text

(lineIndex)
Get the width of a specific line of text

Parameters:


{number}lineIndex
The index of the line of text

Returns:


{number}
The width of the line in pixels
()
Get the current number of lines

Returns:


{number}
The current number of lines
()
Get the text currently associated with the sprite

Returns:


{string}
The text currently associated with the sprite

(scaleX,
scaleY)
Scale the bounding box of the text sprite

Parameters:


{number}scaleX
The scale factor on the x axis
{number}scaleY
The scale factor on the y axis

(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).

Parameters:


{boolean}stringifyOptional
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}propertiesToExcludeOptional
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

(alignment)
Set the text alignment

Parameters:


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

(color)
Set the text color.

Parameters:


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

(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. 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.

Parameters:


{boolean}toggleOptional
Whether to use a fixed size or not. If this parameter is omitted, it is assumed to be true.

(font)
Set a font style for the text sprite.

Parameters:


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

(lineSpacing)
Set the space between lines of text

Parameters:


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

(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.

Parameters:


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

(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.

Parameters:


{number}maxWidth
The maximum width of the text, in pixels

(width,
color)
Set the width and color of the text outline

Parameters:


{number}width
The width of the outline
{string}colorOptional
The color of the text outline. Black by default.

(color,
blur,
offsetX,
offsetY)
Set a shadow to draw around the text sprite

Parameters:


{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

(text)
Set the text for the sprite

Parameters:


{string}text
A string to display when the sprite is drawn