Cocos3 -- 7. Use the UI's RichText

Source: Internet
Author: User

Cocos3 -- 7. Use the UI's RichText

1. Create

            var richText = new ccui.RichText();            richText.ignoreContentAdaptWithSize(false);            richText.width = 120;            richText.height = 100;
Set contentSize by assigning the width and height values, and set ignoreContentAdaptWithSize to false to layout the text according to contentSize.


2. Create text elements

static RichElementText* create(int tag, const Color3B& color, GLubyte opacity, const std::string& text, const std::string& fontName, float fontSize);static RichElementImage* create(int tag, const Color3B& color, GLubyte opacity, const std::string& filePath);static RichElementCustomNode* create(int tag, const Color3B& color, GLubyte opacity, Node* customNode);
The three elements are text, images, and common nodes (Classes derived from Node can be mounted with common nodes ).

The tag seems to be useless internally and cannot be accessed externally. Other parameters are easy to understand.

Var re1 = new ccui. richElementText (0, cc. color. WHITE, 255, 'White, WHITE, black, 24); var re2 = new ccui. richElementText (0, cc. color. RED, 255, 'this is RED, 'body', 24); var reimg = new ccui. richElementImage (0, cc. color. WHITE, 255, 'res/pic/CloseNormal.png '); var renode = new ccui. richElementCustomNode (0, cc. color. WHITE, 255, new cc. sprite ('res/pic/CloseNormal.png '));

3. add or delete Elements

    void insertElement(RichElement* element, int index);    void pushBackElement(RichElement* element);    void removeElement(int index);    void removeElement(RichElement* element);

4. Other Methods

    void setVerticalSpace(float space);    virtual void setAnchorPoint(const Vec2 &pt);    virtual Size getVirtualRendererSize() const override;    void formatText();    virtual void ignoreContentAdaptWithSize(bool ignore);
The js getVirtualRendererSize does not seem to be exported.

5. Results






Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.