Class cc.LabelBMFont

Class Summary
Constructor Attributes Constructor Name and Description
 

cc.LabelBMFont is a subclass of cc.SpriteBatchNode.

Method Summary

Class Detail

cc.LabelBMFont()

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
  • - chage 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)

Method Detail

  • addLoadedEventListener(callback, target)
    add texture loaded event listener
    Parameters:
    {Function} callback
    {Object} target
  • <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
    // Example 01
    var label1 = cc.LabelBMFont.create("Test case", "test.fnt");
    
    // Example 02
    var label2 = cc.LabelBMFont.create("test case", "test.fnt", 200, cc.TEXT_ALIGNMENT_LEFT);
    
    // Example 03
    var label3 = cc.LabelBMFont.create("This is a \n test case", "test.fnt", 200, cc.TEXT_ALIGNMENT_LEFT, cc.PointZero());
    Parameters:
    {String} str
    {String} fntFile
    {Number} width
    {Number} alignment
    {cc.Point} imageOffset
    Returns:
    {cc.LabelBMFont|Null}
  • createFontChars()
    updates the font chars based on the string to render
  • ctor()
    Constructor
  • draw(ctx)
    Parameters:
    {CanvasRenderingContext2D} ctx
  • {String} getFntFile()
    Returns:
    {String}
  • {String} getString()
    get the text of this label
    Returns:
    {String}
  • init()
    init LabelBMFont
  • {Boolean} initWithString(str, fntFile, width, alignment, imageOffset)
    init a bitmap font altas with an initial string and the FNT file
    Parameters:
    {String} str
    {String} fntFile
    {Number} width
    {Number} alignment
    {cc.Point} imageOffset
    Returns:
    {Boolean}
  • {Boolean} isOpacityModifyRGB()
    conforms to cc.RGBAProtocol protocol
    Returns:
    {Boolean}
  • <static> cc.LabelBMFont.purgeCachedData()
    Purges the cached .fnt data
  • setAlignment(alignment)
    Set text vertical alignment
    Parameters:
    {Number} alignment
  • setAnchorPoint(point, y)
    set the AnchorPoint of the labelBMFont
    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.
  • setColor(color3)
    tint this label
    Parameters:
    {cc.Color3B} color3
  • setCString(label)
    Parameters:
    label
  • setFntFile(fntFile)
    set fnt file path
    Parameters:
    {String} fntFile
  • setLineBreakWithoutSpace(breakWithoutSpace)
    Parameters:
    {Boolean} breakWithoutSpace
  • setOpacity(opacity)
    Override synthesized setOpacity to recurse items
    Parameters:
    {Number} opacity
  • setOpacityModifyRGB(opacityModifyRGB)
    Parameters:
    {Boolean} opacityModifyRGB
  • setScale(scale, scaleY)
    Parameters:
    {Number} scale
    {Number} scaleY Optional, Default: null
  • setScaleX(scaleX)
    Parameters:
    {Number} scaleX
  • setScaleY(scaleY)
    Parameters:
    {Number} scaleY
  • setString(newString, needUpdateLabel)
    set the text
    Parameters:
    {String} newString
    {Boolean|null} needUpdateLabel
  • setWidth(width)
    Parameters:
    {Number} width
  • {boolean} textureLoaded()
    return texture is loaded
    Returns:
    {boolean}
  • updateLabel()
    update Label
  • updateString(fromUpdate)
    update String
    Parameters:
    {Boolean} fromUpdate