开发者

What is the best way of creating a label in Cocos2D that will change its text constantly?

I know that changing the text of a CCLabel is really time consuming and hence 开发者_运维问答cannot be done every frame. So how can I achieve this?


My understanding is that the general recommendation when you have to update a level regularly (for a score or the like) is to use a CCLablBMFont. CCLabelBMFont uses a bitmap font file, so it will only draw to the screen once and then can just replace the numbers or letters as needed. You really shouldn't be using CCLabelTTF for anything but completely static text, so CCLabelBMFont would be the way to go for you.

*Edit

Before you worry about the images you need to make sure you uncomment these lines in your AppDelagate:

//if( ! [director enableRetinaDisplay:YES] )
    //CCLOG(@"Retina Display Not supported");

Then when you create your .fnt and .png make sure to create a second .fnt and .png, which is twice is big as the original font you created and append -hd after the name. So your files should look like "original.fnt" "original.png" "original-hd.fnt" "original-hd.png"


It's not all that bad. If you have one label and you really need to change it every frame, I would go ahead and try it. You might not notice any problem. If you do notice a slowdown, though, you can either (a) use a CCLabelAtlas, which is much faster, or (b) set up a counter that tracks how many frames have passed since the last time you updated it, so you're only doing it every 2 or 3 or 5 frames.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜