Class cc.LabelTTF

Class Summary
Constructor Attributes Constructor Name and Description
 
cc.LabelTTF is a subclass of cc.TextureNode that knows how to render text labels
All features from cc.TextureNode are valid in cc.LabelTTF
cc.LabelTTF objects are slow for js-binding on mobile devices.Consider using cc.LabelAtlas or cc.LabelBMFont instead.

Method Summary

Class Detail

cc.LabelTTF()
cc.LabelTTF is a subclass of cc.TextureNode that knows how to render text labels
All features from cc.TextureNode are valid in cc.LabelTTF
cc.LabelTTF objects are slow for js-binding on mobile devices.Consider using cc.LabelAtlas or cc.LabelBMFont instead.
Consider using cc.LabelAtlas or cc.LabelBMFont instead.

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
{Boolean} initWithStringAndTextDefinition
initializes the CCLabelTTF with a font name, alignment, dimension and font size
{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
    // Example
    1.
    var myLabel = cc.LabelTTF.create('label text',  'Times New Roman', 32, cc.size(320,32), cc.TEXT_ALIGNMENT_LEFT);
    2.
    var fontDef = new cc.FontDefinition();
    fontDef.fontName = "Arial";
    fontDef.fontSize = "32";
    var myLabel = cc.LabelTTF.create('label text',  fontDef);
    Parameters:
    {String} text
    {String|cc.FontDefinition} fontName
    {Number} fontSize
    {cc.Size} dimensions Optional, Default: cc.size(0,0)
    {Number} hAlignment Optional
    {Number} vAlignment Optional, Default: cc.VERTICAL_TEXT_ALIGNMENT_TOP
    Returns:
    {cc.LabelTTF|Null}
  • ctor()
    Constructor
  • {String} description()
    Prints out a description of this class
    Returns:
    {String}
  • disableShadow()
    disable shadow rendering
  • disableStroke()
    disable stroke
  • draw(ctx)
    Draw sprite to canvas
    Parameters:
    {CanvasRenderingContext2D|WebGLRenderingContext} ctx
    Render context of canvas, 2d or 3d
  • enableShadow(shadowOffset, shadowOpacity, shadowBlur, shadowBlur)
    enable or disable shadow for the label
    Parameters:
    {cc.Point} shadowOffset
    {Number} shadowOpacity
    (0 to 1)
    {Number} shadowBlur
    shadowBlur
  • enableStroke(strokeColor, strokeSize)
    enable or disable stroke
    Parameters:
    {cc.Color} strokeColor
    {Number} strokeSize
  • {cc.Size} getDimensions()
    return Dimensions of cc.LabelTTF
    Returns:
    {cc.Size}
  • {String} getFontName()
    return font name of cc.LabelTTF
    Returns:
    {String}
  • {Number} getFontSize()
    return font size of cc.LabelTTF
    Returns:
    {Number}
  • return 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()
    get the text definition used by this label
    Returns:
    {cc.FontDefinition}
  • return 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
    Parameters:
    {String} label
    string
    {String} fontName
    {Number} fontSize
    {cc.Size} dimensions Optional
    {Number} hAlignment Optional
    {Number} vAlignment Optional
    Returns:
    {Boolean} return false on error
  • setDimensions(dim)
    set Dimensions of cc.LabelTTF
    Parameters:
    {cc.Size} dim
  • setFontFillColor(tintColor)
    set text tinting
    Parameters:
    {cc.Color} tintColor
  • setFontName(fontName)
    set font name of cc.LabelTTF
    Parameters:
    {String} fontName
  • setFontSize(fontSize)
    set font size of cc.LabelTTF
    Parameters:
    {Number} fontSize
  • setHorizontalAlignment(alignment)
    set 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 string to render
    Parameters:
    {String} text
    text for the label
  • setTextDefinition(theDefinition)
    set the text definition used by this label
    Parameters:
    {cc.FontDefinition} theDefinition
  • setVerticalAlignment(verticalAlignment)
    set Vertical Alignment of cc.LabelTTF
    Parameters:
    {cc.VERTICAL_TEXT_ALIGNMENT_TOP|cc.VERTICAL_TEXT_ALIGNMENT_CENTER|cc.VERTICAL_TEXT_ALIGNMENT_BOTTOM} verticalAlignment