Allows you to display one or more lines of dynamic text (not user editable) in the display list.
Line wrapping support (using the lineWidth is very basic, wrapping on spaces and tabs only. Note
that as an alternative to Text, you can position HTML text above or below the canvas relative to
items in the display list using the localToGlobal() method.
Constructor
Text
(
text
,
font
,
color
)
- Parameters:
-
text
<String>
Optional. The text to display.
-
font
<String>
Optional. The font style to use. Any valid value for the CSS font attribute is
acceptable (ex. "bold 36px Arial").
-
color
<String>
Optional. The color to draw the text in. Any valid value for the CSS color attribute
is acceptable (ex. "#F00").
Properties
The color to draw the text in. Any valid value for the CSS color attribute is acceptable (ex. "#F00"). Default is "#000".
font
- String
The font style to use. Any valid value for the CSS font attribute is acceptable (ex. "bold 36px Arial").
Indicates the line height (vertical distance between baselines) for multi-line text. If null or 0,
the value of getMeasuredLineHeight is used.
Indicates the maximum width for a line of text before it is wrapped to multiple lines. If null,
the text will not be wrapped.
The maximum width to draw the text. If maxWidth is specified (not null), the text will be condensed or
shrunk to make it fit in this width. For detailed information view the
whatwg spec.
If true, the text will be drawn as a stroke (outline). If false, the text will be drawn as a fill.
The horizontal text alignment. Any of "start", "end", "left", "right", and "center". For detailed
information view the
whatwg spec. Default is "left".
The vertical alignment point on the font. Any of "top", "hanging", "middle", "alphabetic",
"ideographic", or "bottom". For detailed information view the
whatwg spec. Default is "top".
Properties inherited from DisplayObject:
_cacheDataURL,
_cacheDataURLID,
_cacheOffsetX,
_cacheOffsetY,
_cacheScale,
_matrix,
alpha,
cacheCanvas,
cacheID,
compositeOperation,
filters,
hitArea,
id,
mask,
mouseEnabled,
name,
parent,
regX,
regY,
rotation,
scaleX,
scaleY,
shadow,
skewX,
skewY,
snapToPixel,
visible,
x,
y
Methods
protected
void
_drawTextLine
(
ctx
,
text
,
y
)
- Parameters:
-
ctx
<CanvasRenderingContext2D>
-
text
<Text>
-
y
<Number>
- Returns:
void
protected
_getWorkingContext
(
)
Draws multiline text.
Point
clone
(
)
Returns a clone of the Point instance.
- Returns:
Point
- a clone of the Point instance.
protected
void
cloneProps
(
o
)
- Parameters:
-
o
<Text>
- Returns:
void
void
draw
(
ctx
,
ignoreCache
)
Draws the Text into the specified context ignoring it's visible, alpha, shadow, and transform.
Returns true if the draw was handled (useful for overriding functionality).
NOTE: This method is mainly for internal use, though it may be useful for advanced uses.
- Parameters:
-
ctx
<CanvasRenderingContext2D>
The canvas 2D context object to draw into.
-
ignoreCache
<Boolean>
Indicates whether the draw operation should ignore any current cache.
For example, used for drawing the cache (to prevent it from simply drawing an existing cache back
into itself).
- Returns:
void
Number
getMeasuredHeight
(
)
Returns the approximate height of multiline text by multiplying the number of lines against
either the lineHeight (if specified) or getMeasuredLineHeight(). Note that this operation
requires the text flowing logic to run, which has an associated CPU cost.
- Returns:
Number
- The approximate height of the drawn multiline text.
Number
getMeasuredLineHeight
(
)
Returns an approximate line height of the text, ignoring the lineHeight property. This is based
on the measured width of a "M" character multiplied by 1.2, which approximates em for most fonts.
- Returns:
Number
- an approximate line height of the text, ignoring the lineHeight property. This is
based on the measured width of a "M" character multiplied by 1.2, which approximates em for most fonts.
Number
getMeasuredWidth
(
)
Returns the measured, untransformed width of the text without wrapping.
- Returns:
Number
- The measured, untransformed width of the text.
protected
void
initialize
(
)
Initialization method.
Boolean
isVisible
(
)
Returns true or false indicating whether the display object would be visible if drawn to a canvas.
This does not account for whether it would be visible within the boundaries of the stage.
NOTE: This method is mainly for internal use, though it may be useful for advanced uses.
- Returns:
Boolean
- Boolean indicating whether the display object would be visible if drawn to a canvas
String
toString
(
)
Returns a string representation of this object.
- Returns:
String
- a string representation of the instance.
_applyFilters,
_applyShadow,
_testHit,
_tick,
cache,
clone,
cloneProps,
draw,
getCacheDataURL.,
getConcatenatedMatrix,
getMatrix,
getStage,
globalToLocal,
hitTest,
initialize,
isVisible,
localToGlobal,
localToLocal,
setTransform,
setupContext,
toString,
uncache,
updateCache