Constructors

TextSprite

Constructor Summary

TextSprite

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

Fields Summary

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 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 [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
^

Fields Details

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)

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

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)

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.

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)

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.

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

^