温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Cocos2d-x 3.0 RichText富文本

发布时间:2020-08-05 21:18:12 阅读:4263 作者:yuzp2160 栏目:游戏开发
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>
...
if (this._super()) {
            //init text
            this._topDisplayLabel.setString("");
            this._bottomDisplayLabel.setString("RichText");

            var widgetSize = this._widget.getContentSize();
           
            // RichText
            //容器
            var richText = new ccui.RichText();
            richText.ignoreContentAdaptWithSize(false);
            richText.setContentSize(cc.size(120100));
            
            //创建不同颜色的字串
            var re1 = new ccui.RichElementText(1, cc.color.WHITE, 255"This color is white. ""Helvetica"10);
           
            var re2 = new ccui.RichElementText(2, cc.color.YELLOW, 255"And this is yellow. ""Helvetica"10);
            var re3 = new ccui.RichElementText(3, cc.color.BLUE, 255"This one is blue. ""Helvetica"10);
            var re4 = new ccui.RichElementText(4, cc.color.GREEN, 255"And green. ""Helvetica"10);
            var re5 = new ccui.RichElementText(5, cc.color.RED, 255"Last one is red ""Helvetica"10);
            //还能支持图片
            var reimg = new ccui.RichElementImage(6, cc.color.WHITE, 255"res/cocosui/sliderballnormal.png");
            
            //这里就吊了,还支持动画
            ccs.armatureDataManager.addArmatureFileInfo("res/cocosui/100/100.ExportJson");
            var pAr = ccs.Armature.create("100");
            pAr.getAnimation().play("Animation1");

            var recustom = new ccui.RichElementCustomNode(1, cc.color.WHITE, 255, pAr);
            //然后最后再拼回图片
            var re6 = new ccui.RichElementText(7, cc.color.ORANGE, 255"Have fun!! ""Helvetica"10);
            
            richText.pushBackElement(re1);
            richText.insertElement(re2, 1);
            richText.pushBackElement(re3);
            richText.pushBackElement(re4);
            richText.pushBackElement(re5);
            richText.insertElement(reimg, 2);
            richText.pushBackElement(recustom);
            richText.pushBackElement(re6);

            richText.setPosition(cc.p(widgetSize.width / 2, widgetSize.height / 2));

            this._mainNode.addChild(richText);
            this._richText = richText;
            return true;
        }
        ...

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI

开发者交流群×