How do you specify line break mode when constructing a cc.LabelTTF in javascript? Also, the docs state ‘cc.LabelTTF objects are slow for js-binding on mobile devices’ – what is a faster alternative?
You can include manual line breaks \n in your content string:
var label = new LabelTTF("Here is a line\nHere is the new line");
In JSB, cc.LabelTTF is slower than cc.LabelBMFont which support fnt formatted fonts, you can try it out also.
Ah okay, that’s one approach. What I’d really like, however, is to be able to specify a rectangle around the Label which causes automatic line breaks to be generated whenever the text string would otherwise render outside the given bounding rectangle – I think CCLabelTTF in C++ accepted a CGSize argument for this purpose; is there an equivalent configuration option in javascript?
Please refer to the API reference
http://www.cocos2d-x.org/reference/html5-js/V3.0rc3/symbols/cc.LabelTTF.html
You can either use the dimension parameter in construction or use boundingWidth & boundingHeight properties to modify them
got it, thanks! I had tried the cc.LabelTTF constructor with a dimensions argument as follows
var label = new cc.LabelTTF(this.mv_sContent, this.mv_sFont, this.mv_iFontSize, [boundWidth,boundHeight], cc.TEXT_ALIGNMENT_CENTER,cc.VERTICAL_TEXT_ALIGNMENT_CENTER);
but the dimensions were not applied; I’m guessing the dimension argument syntax I used is wrong?
This should be cc.size(boundWidth, boundHeight)