Search code examples
htmlimagelabelcocos2d-x

cocos2d-x Label Load Image like Sticker-Smile..(by html or ...)


i am using cocos2d-x (c++)... can i load sticker (smile) in my Label(a text mixed by image)? i know that we can load bitmap fonts by:

Label::createWithBMFont 

also i know many frameworks like flash can load html texts by textbox which can contains img tags... but what is the best way for adding smile image in the text of label in cocos2d-x?? can cocos2d Label load html text like :

"hello<br>How Are You<img src="..." width=".." height=".." alt="..">"???

thanks...


Solution

  • i've found my way... we can load images and show different text formats by UIRichText... also you can push unicode texts... example code is:

    auto text = cocos2d::ui::RichText::create();
    const auto font = std::string("fonts/FinalFonts/Berlin.ttf");
    text->pushBackElement(ui::RichElementCustomNode::create(1995, Color3B(255, 255, 255), 255, Label::createWithSystemFont(persianText01, font, 20, Size::ZERO, TextHAlignment::RIGHT, TextVAlignment::TOP)));
    text->pushBackElement(ui::RichElementImage::create(1993, Color3B(255, 255, 255), 255, "icons/sticker.png"));
    text->pushBackElement(ui::RichElementCustomNode::create(1994, Color3B(255, 255, 255), 255, Label::createWithSystemFont(persianText02, font, 20, Size::ZERO, TextHAlignment::RIGHT, TextVAlignment::TOP)));
    text->pushBackElement(ui::RichElementImage::create(1990, Color3B(255, 255, 255), 255, "icons3/sticker.png"));
    text->pushBackElement(ui::RichElementCustomNode::create(1998, Color3B(255, 255, 255), 255, Label::createWithSystemFont(persianText03, font, 20, Size::ZERO, TextHAlignment::RIGHT, TextVAlignment::TOP)));
    sprite->addChild(text);