Class cc.LabelTTF

Class Summary
Constructor Attributes Constructor Name and Description
 
cc.LabelTTF(text, fontName, fontSize, dimensions, hAlignment, vAlignment)

cc.LabelTTF is a subclass of cc.TextureNode that knows how to render text labels with system font or a ttf font file
All features from cc.Sprite are valid in cc.LabelTTF
cc.LabelTTF objects are slow for js-binding on mobile devices.

Method Summary

Class Detail

cc.LabelTTF(text, fontName, fontSize, dimensions, hAlignment, vAlignment)

cc.LabelTTF is a subclass of cc.TextureNode that knows how to render text labels with system font or a ttf font file
All features from cc.Sprite are valid in cc.LabelTTF
cc.LabelTTF objects are slow for js-binding on mobile devices.
Consider using cc.LabelAtlas or cc.LabelBMFont instead.
You can create a cc.LabelTTF from a font name, alignment, dimension and font size or a cc.FontDefinition object.

var myLabel = new cc.LabelTTF('label text',  'Times New Roman', 32, cc.size(320,32), cc.TEXT_ALIGNMENT_LEFT);

var fontDef = new cc.FontDefinition();
fontDef.fontName = "Arial";
fontDef.fontSize = "32";
var myLabel = new cc.LabelTTF('label text',  fontDef);
Parameters:
{String} text
{String|cc.FontDefinition} fontName Optional, Default: "Arial"
{Number} fontSize Optional, Default: 16
{cc.Size} dimensions Optional, Default: cc.size(0,0)
{Number} hAlignment Optional, Default: cc.TEXT_ALIGNMENT_LEFT
{Number} vAlignment Optional, Default: cc.VERTICAL_TEXT_ALIGNMENT_TOP

Field Detail

{Number} boundingHeight
- Height of the bounding box of label, the real content height is limited by boundingHeight
{Number} boundingWidth
- Width of the bounding box of label, the real content width is limited by boundingWidth
{cc.Color} fillStyle
- The fill color
{String} font
- The label font with a style string: e.g. "18px Verdana"
{String} fontName
- Font name of label
{Number} fontSize
- Font size of label
{Number} lineWidth
- The line width for stroke
{Number} shadowBlur
- The blur size of shadow
{Number} shadowOffsetX
- The x axis offset of shadow
{Number} shadowOffsetY
- The y axis offset of shadow
{Number} shadowOpacity
- The opacity of shadow
{String} string
- Content string of label
{cc.Color} strokeStyle
- The stroke color
{Number} textAlign
- Horizontal Alignment of label: cc.TEXT_ALIGNMENT_LEFT|cc.TEXT_ALIGNMENT_CENTER|cc.TEXT_ALIGNMENT_RIGHT
{Number} verticalAlign
- Vertical Alignment of label: cc.VERTICAL_TEXT_ALIGNMENT_TOP|cc.VERTICAL_TEXT_ALIGNMENT_CENTER|cc.VERTICAL_TEXT_ALIGNMENT_BOTTOM

Method Detail

  • <static> {cc.LabelTTF|Null} cc.LabelTTF.create(text, fontName, fontSize, dimensions, hAlignment, vAlignment)
    creates a cc.LabelTTF from a font name, alignment, dimension and font size
    Parameters:
    {String} text
    {String|cc.FontDefinition} fontName Optional, Default: "Arial"
    {Number} fontSize Optional, Default: 16
    {cc.Size} dimensions Optional, Default: cc.size(0,0)
    {Number} hAlignment Optional, Default: cc.TEXT_ALIGNMENT_LEFT
    {Number} vAlignment Optional, Default: cc.VERTICAL_TEXT_ALIGNMENT_TOP
    Deprecated:
    since v3.0, please use the new construction instead
    Returns:
    {cc.LabelTTF|Null}
    See:
    cc.LabelTTF
  • <static> cc.LabelTTF.createWithFontDefinition()
    Deprecated:
    since v3.0, please use the new construction instead
  • disableShadow()
    Disable shadow rendering
  • disableStroke()
    Disable label stroke
  • enableShadow(a, b, c, d)
    Enable or disable shadow for the label
      old:
        labelttf.enableShadow(shadowOffsetX, shadowOffsetY, shadowOpacity, shadowBlur);
      new:
        labelttf.enableShadow(shadowColor, offset, blurRadius);
    Parameters:
    {cc.Color | Number} a
    Color or The x axis offset of the shadow
    {cc.Size | Number} b
    Size or The y axis offset of the shadow
    {Number} c
    The blur size of the shadow or The opacity of the shadow (0 to 1)
    {null | Number} d
    Null or The blur size of the shadow
  • enableStroke(strokeColor, strokeSize)
    Enable label stroke with stroke parameters
    Parameters:
    {cc.Color} strokeColor
    The color of stroke
    {Number} strokeSize
    The size of stroke
  • {cc.Size} getContentSize()
    Returns the actual content size of the label, the content size is the real size that the label occupied while dimension is the outer bounding box of the label.
    Returns:
    {cc.Size} The content size
  • {cc.Size} getDimensions()
    Returns the dimensions of cc.LabelTTF, the dimension is the maximum size of the label, set it so that label will automatically change lines when necessary.
    Returns:
    {cc.Size}
    See:
    cc.LabelTTF#setDimensions, cc.LabelTTF#boundingWidth and cc.LabelTTF#boundingHeight
  • {String} getFontName()
    Returns font name of cc.LabelTTF
    Returns:
    {String}
  • {Number} getFontSize()
    Returns font size of cc.LabelTTF
    Returns:
    {Number}
  • Returns Horizontal Alignment of cc.LabelTTF
    Returns:
    {cc.TEXT_ALIGNMENT_LEFT|cc.TEXT_ALIGNMENT_CENTER|cc.TEXT_ALIGNMENT_RIGHT}
  • {String} getString()
    Returns the text of the label
    Returns:
    {String}
  • {cc.FontDefinition} getTextDefinition()
    Extract the text definition used by this label
    Returns:
    {cc.FontDefinition}
  • Returns Vertical Alignment of cc.LabelTTF
    Returns:
    {cc.VERTICAL_TEXT_ALIGNMENT_TOP|cc.VERTICAL_TEXT_ALIGNMENT_CENTER|cc.VERTICAL_TEXT_ALIGNMENT_BOTTOM}
  • {Boolean} initWithString(label, fontName, fontSize, dimensions, hAlignment, vAlignment)
    Initializes the cc.LabelTTF with a font name, alignment, dimension and font size, do not call it by yourself, you should pass the correct arguments in constructor to initialize the label.
    Parameters:
    {String} label
    string
    {String} fontName
    {Number} fontSize
    {cc.Size} dimensions Optional
    {Number} hAlignment Optional
    {Number} vAlignment Optional
    Returns:
    {Boolean} return false on error
  • {Boolean} initWithStringAndTextDefinition(text, textDefinition)
    Initializes the CCLabelTTF with a font name, alignment, dimension and font size, do not call it by yourself, you should pass the correct arguments in constructor to initialize the label.
    Parameters:
    {String} text
    {cc.FontDefinition} textDefinition
    Returns:
    {Boolean}
  • setDimensions(dim, height)
    Set Dimensions of cc.LabelTTF, the dimension is the maximum size of the label, set it so that label will automatically change lines when necessary.
    Parameters:
    {cc.Size|Number} dim
    dimensions or width of dimensions
    {Number} height Optional
    height of dimensions
  • setFontFillColor(fillColor)
    Sets the text fill color
    Parameters:
    {cc.Color} fillColor
    The fill color of the label
  • setFontName(fontName)
    Sets font name of cc.LabelTTF
    Parameters:
    {String} fontName
  • setFontSize(fontSize)
    Sets font size of cc.LabelTTF
    Parameters:
    {Number} fontSize
  • setHorizontalAlignment(alignment)
    Sets Horizontal Alignment of cc.LabelTTF
    Parameters:
    {cc.TEXT_ALIGNMENT_LEFT|cc.TEXT_ALIGNMENT_CENTER|cc.TEXT_ALIGNMENT_RIGHT} alignment
    Horizontal Alignment
  • setString(text)
    Changes the text content of the label
    Parameters:
    {String} text
    Text content for the label
  • setTextDefinition(theDefinition)
    Sets the text definition used by this label
    Parameters:
    {cc.FontDefinition} theDefinition
  • setVerticalAlignment(verticalAlignment)
    Sets Vertical Alignment of cc.LabelTTF
    Parameters:
    {cc.VERTICAL_TEXT_ALIGNMENT_TOP|cc.VERTICAL_TEXT_ALIGNMENT_CENTER|cc.VERTICAL_TEXT_ALIGNMENT_BOTTOM} verticalAlignment