Is calling setString() to update text in LabelBMFont class the right way to do so?

I created a LabelBMFont object once, and plan to change its text in runtime frequently.
The text to be updated varies from time to time, one may consists of multiple lines or one may only be a single line, and of course all of them is in different length.

I get the result as shown in attached image. But if I recreate an object every time the text changes, the problem is gone.

So my question is whether setString() function is the right way to update its text.
Is there any performance hit if I recreate it everytime (especially for LabelBMFont object) ?


Screen Shot 2012-07-26 at 1.12.20 PM.png (55.6 KB)

would you show us your code?

setString works as expected in our test cases

Even I have the same problem,
If a bmpfont is initialized, it works fine, but if another bmpfont is shown on the screen, the first font gets messed up like in the above pic.
Happens everytime.
Any help appreciated.

Edit: Forgot to mention this only happens when using bold bmpfonts.
With normal fonts everything is fine.

Thanks Hao Wu, here is my code (although I can’t seem to find an exact code I used in that particular of time, I commented out and didn’t push it up, anyway here is my closest one).

There’re 2 sections, the first one below, I created objects ahead of time and add them into a layer. I will play them via “visibility” flag + “setString()” to reduce the number of recreating objects in runtime.

@


// create a question object - only once
this.*questionLabel = cc.LabelBMFont.create;
this.*questionLabel.setPosition(cc.ccp(centerPos.x - 50, 491));
this.*questionLabel.setColor);
// create choices objects - only once
this.choiceLabels = [];
var choiceLabelsYPos = [345, 299, 244, 187];
var i=0;
for(; i<question_data[0].choices.length; i++)
{
this._choiceLabels[i] = cc.LabelBMFont.create(question_data[0].choices[i], res_font_gmo_32_fnt);
this._choiceLabels[i].setPosition(cc.ccp(centerPos.x - 40, choiceLabelsYPos[i]));
this._choiceLabels[i].setColor(cc.ccc3(0x99,0,0));
}
// check to init the less
if(i < 4)
{
for(; i<4 ;i++)
{
this._choiceLabels[i] = cc.LabelBMFont.create("", res_font_gmo_32_fnt);
this._choiceLabels[i].setPosition(cc.ccp(centerPos.x - 40, choiceLabelsYPos[i]));
this._choiceLabels[i].setColor(cc.ccc3(0x99,0,0));
this._choiceLabels[i].setIsVisible(false);
}
}
/

—> THEN ADD THEM INTO LAYER (Can’t seem to find my exact code for adding into a layer, but I believe it’s this way)

…@

Then another section, it’s time to make changes.

@


// set new question text for a question
this.*questionLabel.setString;
// set new choices-text for choices
var i = 0;
for
{
this.*choiceLabels[i].setString(q.choices[i]);
this.*choiceLabels[i].setIsVisible;
}
for
{
this.*choiceLabels[i].setIsVisible(false);
}


**/@
It’s pretty forward in code. I don’t think I would have a weird approach.
And thanks to Nick as well, I do have a multiple BMfont, and I do think my problem is really similar.
**Note*: Two BMFont here with different .fnt file used for each one. One BMFont may have one or multiple lines of text, and changes all the time.

Issue 1410 is created for it. It will be fixed soon.

So much thanks!