CCLabelBMFont multiline problem in 2.1.4?

Hello, everybody.

I’m using a CCLabelBMFont to display COMBO information like this:
N-hit
COMBO!

I first create the CCLabelBMFont like this:

_comboDisplay = CCLabelBMFont::create("N-hit\nCOMBO!", "font.fnt", _screenSizeVisible.width * 0.7f, kCCTextAlignmentCenter);
    _comboDisplay->setAnchorPoint(ccp(0.5f,0.5f));
    _comboDisplay->setColor(ccc3(255,247,0));
    _comboDisplay->setPosition(ccp(xOffset + _screenSizeVisible.width * 1.5f, _screenSizeVisible.height * 0.75f));
    _comboDisplay->setScale((float)COMBO_DISPLAY_SCALE);
    this->addChild(_comboDisplay, kForeground);

And then, whenever the combo is updated, I do this:

sprintf(szValue, "%i-hit\nCOMBO!", _currentCombo);
_comboDisplay->setString (szValue);

So, the problem I have is: after updating the label, that ONE char is shown as at least 2 or 3 new lines: the space between the first and the second lines is HUGE.
If I DON’T update the string since the declaration, then that one char is shown perfectly.

Is there some bug in cocos2d-x 2.1.4 that ends up adding new line characters when sprintf is used? This exact same code doesn’t have this problem in 2.0.4.
Or maybe the way the string is updated has changed since 2.0.4?

Any help is greatly appreciated. :slight_smile:

Thanks!

To clarify, if I just create the string as shown in the first block of code, the game shows the label like this:

N-hit
COMBO!

But if I use sprintf and setString, the game shows the label like this:

2-hit
.
.
.
COMBO!

(without the dots, of course)

I don’t know why the extra lines are added.

Thanks!

Has anybody seen behaviour like this? I’m seeing it both in Windows and Android. :frowning:

I have exactly the same problem on IOS. After I change anchor point of label, some weird newlines are added… :frowning:

Do you have any solution?

Thanks.

I have found a solution.
In the file CCLabelBMFont.cpp
replace

if (c == ‘\n’)
{
nextFontPositionX = 0;
nextFontPositionY -= m_pConfiguration->m_nCommonHeight;
continue;
}

with

if (c == ‘\n’)
{
nextFontPositionX = 0;
nextFontPositionY -= m_pConfiguration->m_nCommonHeight;

        //make sure we have no children with this tag, because
        // they possibly were visible in a previous version of the string
        CCNode *childWithCurrentTagValue = getChildByTag(i);             
        if (childWithCurrentTagValue) 
        {
            removeChildByTag(i); 
        }
        continue;
    }