Class TextSprite
Extends
Sprite.
Constructor Attributes | Constructor Name and Description |
---|---|
TextSprite(text, font, color, alignment, layerId)
A Text Sprite is used to display strings in a WADE app.
|
Method Attributes | Method Name and Description |
---|---|
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
|
|
getText()
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
|
- Methods borrowed from class Sprite:
- addAnimation, alwaysDraw, bringToFront, cache, containsScreenPoint, drawToImage, fadeIn, fadeOut, getAllImageNames, getAnimation, getCurrentAnimation, getCurrentAnimationName, getDrawFunction, getDrawModifiers, getImageArea, getImageName, getIndexInLayer, getLayerId, getName, getOverlappingObjects, getPixelShader, getPixelShaderUniforms, getPosition, getRotation, getScaleFactor, getSceneObject, getScreenPositionAndExtents, getSize, getSortPoint, getWorldOffset, hasAnimation, isAlwaysDrawing, isVisible, overlapsSprite, playAnimation, pushToBack, putBehindSprite, resumeAnimation, setDirtyArea, setDrawFunction, setDrawModifiers, setImageArea, setImageFile, setIndexInLayer, setLayer, setName, setPixelShader, setPosition, setRotation, setSceneObject, setSize, setSortPoint, setVisible, step, stopAnimation
Class Detail
TextSprite(text, font, color, alignment, layerId)
A Text Sprite is used to display strings in a WADE app.
- Parameters:
- {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 Optional, Default: '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, Default: 'left'
- A string describing the alignment property for the text, relative to its pivot position. Valid values are 'left', 'right' and 'center'.
- {number} layerId Optional, 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.
Method Detail
{object}
clone()
Clone the text sprite
- Returns:
- {object} A copy of the text sprite
{string | undefined}
getLine(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
{number}
getLineWidth(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
{number}
getNumLines()
Get the current number of lines
- Returns:
- {number} The current number of lines
{string}
getText()
Get the text currently associated with the sprite
- Returns:
- {string} The text currently associated with the sprite
scaleBounds(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
{object|string}
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).
- Parameters:
- {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
setAlignment(alignment)
Set the text alignment
- Parameters:
- {string} alignment
- The text alignment. It can be 'left', 'center', or 'right'
setColor(color)
Set the text color.
- Parameters:
- {string} color
- An HTML color string. For example 'red', '#f00, '#ff0000', or 'rgba(255,0,0,0.5)'
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 updatedd.
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} toggle Optional
- Whether to use a fixed size or not. If this parameter is omitted, it is assumed to be true.
setFont(font)
Set a font style for the text sprite.
- Parameters:
- {string} font
- A string describing an HTML font style. For example, '20px Verdana'
setLineSpacing(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.
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.
- 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
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.
- Parameters:
- {number} maxWidth
- The maximum width of the text, in pixels
setOutline(width, color)
Set the width and color of the text outline
- Parameters:
- {number} width
- The width of the outline
- {string} color Optional
- The color of the text outline. Black by default.
setShadow(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
setText(text)
Set the text for the sprite
- Parameters:
- {string} text
- A string to display when the sprite is drawn