• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
养眼大魔王
博客园    首页    新随笔    联系   管理    订阅  订阅

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);

 

posted @ 2015-10-09 21:58  养眼大魔王  阅读(1110)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3