javascripthtmlcocos2d-xcocos2d-x-3.0cocos2d-js

Cocos2d js How to word- wrap ccLabel


I have created a label and tried to wrap it. Its wrapping when space appears in the text but it also wrapping when comma(,) appears in the text.

I do not want to wrap when comma appears.

Any help.

Code -

    var label = new cc.LabelTTF("Get 100% Welcome Bonus upto Rs. 1,000 on your first deposit.", "Arial", 30);
    label.setPosition(cc.p(this.width / 2, this.height / 2));
    label.setScale(0.5);
    label.setColor(cc.color(255, 0, 0));
    label._setBoundingWidth(520);
    this.addChild(label, 1000);

Screenshot


Solution

  • I have found solution to this problem

    Cocos2d use regex to wrap word. So we need to add comma in regex.

    cc.LabelTTF._lastWordRex = /([a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]+|\S)$/;
    cc.LabelTTF._lastEnglish = /[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]+$/;
    cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû]/;
    

    To

    cc.LabelTTF._lastWordRex = /([a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû,]+|\S)$/;
    cc.LabelTTF._lastEnglish = /[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû,]+$/;
    cc.LabelTTF._firsrEnglish = /^[a-zA-Z0-9ÄÖÜäöüßéèçàùêâîôû,]/;
    

    Just put it in main.js