CCLabelBMFontMultiline class

Hello !
I propose to use CCLabelBMFontMultiline class for show multiline strings with BMP-font.
Howto use:

  1. Copy file “CCLabelBMFont.cpp” from attached archive to “cocos2dx/label_nodes” folder
  2. Copy file “CCLabelBMFont.h” from attached archive to “cocos2dx/include” folder
  3. Call subroutine output a line similar to the class CCLabelBMFont (labelWithString) with additional parameters:
    width - the width of the output lines in pixels,
    align - enum with 3 states (LeftAlignment, CenterAlignment, RightAlignment)

Example using CCLabelBMFontMultiline class:
CCMenuItemSprite* item1 = CCMenuItemSprite::itemFromNormalSprite(spriteNormal1, spriteSelected1, spriteDisabled1, this, menu_selector(MenuLayer1::menuCallback1) );
CCLabelBMFontMultiline* text1 = CCLabelBMFontMultiline::labelWithString(“Hello world !”, “fonts/arial16.fnt”,item1->getContentSize().width, CenterAlignment);


CCLabelBMFont.zip (9.6 KB)

thank you,

this is very useful but I’ve seen the post is from one year ago, do you know if the feature has been included in the framework?

Jesus Bosch wrote:

this is very useful but I’ve seen the post is from one year ago, do you know if the feature has been included in the framework?

Yeah it has been reintegrated. Just call “create” with the adequate arguments:

From API reference [[http://www.cocos2d-x.org/embedded/cocos2d-x/dc/dfb/classcocos2d_1_1_c_c_label_b_m_font.html]]:

static CCLabelBMFont* create ( const char * str,
const char * fntFile,
float width,
CCTextAlignment alignment,
CCPoint imageOffset
)

I agree it’s not super well documented though :slight_smile:

Just use the width to specify the width of your “multiline” label.