• cocos代码研究(26)Widget子类RichView学习笔记


    理论部分

    一个显示多个RichElement的容器类。 我们可以使用它很容易显示带图片的文本,继承自 Widget。

    代码实践

    static RichText * create ()
    创建一个空的RichText

    void insertElement (RichElement *element, int index)
    在指定位置插入一个RichElement。

    void pushBackElement (RichElement *element)
    在容器最后插入一个RichElement。

    void removeElement (int index)
    移除指定位置的RichElement。

    void removeElement (RichElement *element)
    移除一个RichElement。

    void setVerticalSpace (float space)
    设置每个RichElement的垂直间隔。

    void formatText ()
    重新排列所有的RichElement。 常内部调用。

    static RichElementText * create (int tag, //标签值。
    const Color3B &color, //颜色值。
    GLubyte opacity, //不透明度。
    const std::string &text, //文本内容。
    const std::string &fontName, //文本字体名称。
    float fontSize) //文本字体大小。
    通过多个变量创建一个RichElementText类。

    static RichElementImage * create (int tag, //标签值。
    const Color3B &color, //颜色值。
    GLubyte opacity, //不透明度。
    const std::string &filePath) //图片文件名。
    通过多个变量创建一个RichElementImage类。

    static RichElementCustomNode * create(int tag, //标签值。
    const Color3B &color, //颜色值。
    GLubyte opacity, //不透明度。
    Node *customNode) //自定义节点指针。
    通过多个变量创建一个RichElementCustomNode类。

    实例:

            // RichText
            _richText = RichText::create();
            _richText->ignoreContentAdaptWithSize(false);
            _richText->setContentSize(Size(100, 100));
            
            RichElementText* re1 = RichElementText::create(1, Color3B::WHITE, 255, str1, "SimSun", 10);
            RichElementText* re2 = RichElementText::create(2, Color3B::YELLOW, 255, "And this is yellow. ", "Helvetica", 10);
            RichElementText* re3 = RichElementText::create(3, Color3B::GRAY, 255, str2, "Yu Mincho", 10);
            RichElementText* re4 = RichElementText::create(4, Color3B::GREEN, 255, "And green with TTF support. ", "fonts/Marker Felt.ttf", 10);
            RichElementText* re5 = RichElementText::create(5, Color3B::RED, 255, "Last one is red ", "Helvetica", 10);
            
            RichElementImage* reimg = RichElementImage::create(6, Color3B::WHITE, 255, "cocosui/sliderballnormal.png");
            
            cocostudio::ArmatureDataManager::getInstance()->addArmatureFileInfo("cocosui/100/100.ExportJson");
            cocostudio::Armature *pAr = cocostudio::Armature::create("100");
            pAr->getAnimation()->play("Animation1");
            
            RichElementCustomNode* recustom = RichElementCustomNode::create(1, Color3B::WHITE, 255, pAr);
            RichElementText* re6 = RichElementText::create(7, Color3B::ORANGE, 255, "Have fun!! ", "Helvetica", 10);
  • 相关阅读:
    感性的记录一次生活
    CF 696 A Lorenzo Von Matterhorn(二叉树,map)
    UVA 673 Parentheses Balance(栈)
    POJ 1363 Rails(栈)
    HDU 1314 Numerically Speaking(大数加减乘除+另类二十六进制互相转换)
    UVA 540 Team Queue(模拟+队列)
    HDU 1276 士兵队列训练问题(模拟)
    CF 480 B Long Jumps (map标记)
    UVA 136 Ugly Numbers
    HDU 1027 Ignatius and the Princess II
  • 原文地址:https://www.cnblogs.com/damowang/p/4865287.html
Copyright © 2020-2023  润新知