Class cc.LabelBMFont

Class Summary
Constructor Attributes Constructor Name and Description
 
cc.LabelBMFont(str, fntFile, width, alignment, imageOffset)

cc.LabelBMFont is a subclass of cc.SpriteBatchNode.

Method Summary

Class Detail

cc.LabelBMFont(str, fntFile, width, alignment, imageOffset)

cc.LabelBMFont is a subclass of cc.SpriteBatchNode.

Features:

  • - Treats each character like a cc.Sprite. This means that each individual character can be:
  • - rotated
  • - scaled
  • - translated
  • - tinted
  • - change the opacity
  • - It can be used as part of a menu item.
  • - anchorPoint can be used to align the "label"
  • - Supports AngelCode text format

Limitations:
- All inner characters are using an anchorPoint of (0.5, 0.5) and it is not recommend to change it because it might affect the rendering

cc.LabelBMFont implements the protocol cc.LabelProtocol, like cc.Label and cc.LabelAtlas.
cc.LabelBMFont has the flexibility of cc.Label, the speed of cc.LabelAtlas and all the features of cc.Sprite.
If in doubt, use cc.LabelBMFont instead of cc.LabelAtlas / cc.Label.

Supported editors:
http://glyphdesigner.71squared.com/ (Commercial, Mac OS X)
http://www.n4te.com/hiero/hiero.jnlp (Free, Java)
http://slick.cokeandcode.com/demos/hiero.jnlp (Free, Java)
http://www.angelcode.com/products/bmfont/ (Free, Windows only)

// Example 01
var label1 = new cc.LabelBMFont("Test case", "test.fnt");

// Example 02
var label2 = new cc.LabelBMFont("test case", "test.fnt", 200, cc.TEXT_ALIGNMENT_LEFT);

// Example 03
var label3 = new cc.LabelBMFont("This is a \n test case", "test.fnt", 200, cc.TEXT_ALIGNMENT_LEFT, cc.p(0,0));
Parameters:
{String} str
{String} fntFile
{Number} width Optional, Default: -1
{Number} alignment Optional, Default: cc.TEXT_ALIGNMENT_LEFT
{cc.Point} imageOffset Optional, Default: cc.p(0,0)

Field Detail

{Number} boundingWidth
- Width of the bounding box of label, the real content width is limited by boundingWidth
{String} string
- Content string of label
{Number} textAlign
- Horizontal Alignment of label, cc.TEXT_ALIGNMENT_LEFT|cc.TEXT_ALIGNMENT_CENTER|cc.TEXT_ALIGNMENT_RIGHT

Method Detail

  • addLoadedEventListener(callback, target)
    add texture loaded event listener.
    Will execute the callback in the loaded.
    Parameters:
    {Function} callback
    {Object} target
    Deprecated:
    since 3.1, please use addEventListener instead
  • <static> {cc.LabelBMFont|Null} cc.LabelBMFont.create(str, fntFile, width, alignment, imageOffset)
    creates a bitmap font atlas with an initial string and the FNT file
    Parameters:
    {String} str
    {String} fntFile
    {Number} width Optional, Default: -1
    {Number} alignment Optional, Default: cc.TEXT_ALIGNMENT_LEFT
    {cc.Point} imageOffset Optional, Default: cc.p(0,0)
    Deprecated:
    since v3.0 please use new cc.LabelBMFont
    Returns:
    {cc.LabelBMFont|Null}
  • createFontChars()
    updates the font chars based on the string to render
  • ctor(str, fntFile, width, alignment, imageOffset)
    Constructor function, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function.
    creates a bitmap font atlas with an initial string and the FNT file.
    Parameters:
    {String} str
    {String} fntFile
    {Number} width Optional, Default: -1
    {Number} alignment Optional, Default: cc.TEXT_ALIGNMENT_LEFT
    {cc.Point} imageOffset Optional, Default: cc.p(0,0)
  • {String} getFntFile()
    Return the fnt file path.
    Returns:
    {String}
  • {String} getString()
    Gets the text of this label
    Returns:
    {String}
  • init()
    Initialization of the node, please do not call this function by yourself, you should pass the parameters to constructor to initialize it
.
  • {Boolean} initWithString(str, fntFile, width, alignment, imageOffset)
    init a bitmap font atlas with an initial string and the FNT file
    Parameters:
    {String} str
    {String} fntFile
    {Number} width Optional, Default: -1
    {Number} alignment Optional, Default: cc.TEXT_ALIGNMENT_LEFT
    {cc.Point} imageOffset Optional, Default: cc.p(0,0)
    Returns:
    {Boolean}
  • {Boolean} isOpacityModifyRGB()
    Conforms to cc.RGBAProtocol protocol.
    Returns:
    {Boolean}
  • setAlignment(alignment)
    Set text alignment.
    Parameters:
    {Number} alignment
  • setAnchorPoint(point, y)
    Set the AnchorPoint of the labelBMFont.
    In order to change the location of label.
    Parameters:
    {cc.Point|Number} point
    The anchor point of labelBMFont or The anchor point.x of labelBMFont.
    {Number} y Optional
    The anchor point.y of labelBMFont.
  • setBoundingWidth(width)
    Set the bounding width.
    max with display width. The exceeding string will be wrapping.
    Parameters:
    {Number} width
  • setCString(label)
    Set the text.
    Change this Label display string.
    Parameters:
    label
    Deprecated:
    since v3.0 please use .setString
  • setFntFile(fntFile)
    set fnt file path.
    Change the fnt file path.
    Parameters:
    {String} fntFile
  • setLineBreakWithoutSpace(breakWithoutSpace)
    Set the param to change English word warp according to whether the space.
    default is false.
    Parameters:
    {Boolean} breakWithoutSpace
  • setOpacityModifyRGB(opacityModifyRGB)
    Set whether to support cc.RGBAProtocol protocol
    Parameters:
    {Boolean} opacityModifyRGB
  • setScale(scale, scaleY)
    Set scale.
    Input a number, will be decrease or increase the font size.
    Parameters:
    {Number} scale
    {Number} scaleY Optional, Default: null
    default is scale
  • setScaleX(scaleX)
    Set scale of x.
    Input a number, will be decrease or increase the font size.
    Horizontal scale.
    Parameters:
    {Number} scaleX
  • setScaleY(scaleY)
    Set scale of x.
    Input a number, will be decrease or increase the font size.
    Longitudinal scale.
    Parameters:
    {Number} scaleY
  • setString(newString, needUpdateLabel)
    Set the text
    Parameters:
    {String} newString
    {Boolean|null} needUpdateLabel
  • {boolean} textureLoaded()
    return texture is loaded
    Returns:
    {boolean}
  • updateLabel()
    Update Label.
    Update this Label display string and more...
  • updateString(fromUpdate)
    Update String.
    Only update this label display string.
    Parameters:
    {Boolean} fromUpdate