I’m creating many labels just like this code taken from the test project:
for( int i=0 ; i < 100;i ++ )
{
char str[6] = {0};
sprintf(str, "-%d-", i);
CCLabelBMFont* label = CCLabelBMFont::create(str, "fonts/bitmapFontTest.fnt");
addChild(label);
CCSize s = CCDirector::sharedDirector()->getWinSize();
CCPoint p = ccp( CCRANDOM_0_1() * s.width, CCRANDOM_0_1() * s.height);
label->setPosition( p );
label->setAnchorPoint(ccp(0.5f, 0.5f));
}
The thing is that when this code executes it creates an spike in the processor that causes a sound glitch (i have custom audio generation). I solved this situation by drawing the labels spaced through the frames; i create no more than 10 labels by frame. This creates a ‘populating’ effect that i don’t desire. Is there a better way to prevent the cpu spike?