• cocos creator基础-(八)cc.Label使用


    1: 掌握cc.Label组件使用;
    2: 掌握cc.RichText组件使用;

    cc.Label

    1:cc.Label是显示文字的组件;
    2:cc.Label属性面板:
      String: 文本显示的内容;
      Horiznotal: 水平对齐的方式: 左 右 居中;
      Vertial: 上, 下, 居中, 字与行的排版
      Font Size: 字体大小;
      LineHeight: 每行的高度;
      OverFlow:文字排版:
        None: 没有任何特性; Clamp: 截断;
        Shank:自动缩放到节点大小; Resize Height: 根据宽度自动折行;
      Font: ttf字库文件, 位图字体字库文件;
      Font Family: 字体家族,使用系统的哪种字库;
      Use System Font: 是否使用系统字体;
    3: Label节点所在的锚点修改;

    自定义字库


    1: 准备好字体文件 .ttf矢量字库;
    使用矢量字体 , 优点: 灵活方便,缺点:字库文件占资源

    2: 使用字体制作工具生成位图字体;
    使用位图字体;

    3: 位图字体的优点与缺点:
    速度快,文件小; 支持的字符个数是有限的;

    4: 自定义ttf字库与自定义位图字库: 个性化我们的字体,个性化系统没有的字库;
    自定义ttf字库,字符不限制,你这个字库里面有多少字符,就会支持, 灵活,占空间比较大
    位图字库, 字符的个数是有限制的,省空间

    代码使用cc.Label

    1: 代码中获取cc.Label组件;
    2: 代码绑定cc.Label组件到编辑器;
    3: 修改cc.Label的文字内容: label.string = “xxxxxxxxxx”;

    RichText组件

    1: 添加富文本组件;
    2: 设置富文本的字符内容;
    <color=#0fffff>Text</color> 指定文字的颜色;
      <img src='cow1_1'/> img标签,文本插入图片,图片要在指定的图集里面;
      u: 给文本加下划线
      i: 用斜体来渲染, b: 用粗体来渲染
      size: 指定字体渲染大小,大小值必须是一个整数 <size=30>enlarge me</size>
      outline: 设置文本的描边颜色和描边宽度 <outline color=red width=4>A label with outline</outline>

    cc.Class({
        extends: cc.Component,
    
        properties: {
            // foo: {
            //    default: null,      // The default value will be used only when the component attaching
            //                           to a node for the first time
            //    url: cc.Texture2D,  // optional, default is typeof default
            //    serializable: true, // optional, default is true
            //    visible: true,      // optional, default is true
            //    displayName: 'Foo', // optional
            //    readonly: false,    // optional, default is false
            // },
            // ...
            bmp_font: {
                type: cc.Label,
                default: null,
            },
        },
    
        // use this for initialization
        onLoad: function () {
            this.bmp_font.string = "1111";
    
            // 代码里面获取cc.Label组件, 修改文本内容
            var sys_label = this.node.getChildByName("sys_label").getComponent(cc.Label);
            sys_label.string = "MMM NNN";
        },
    
        // called every frame, uncomment this function to activate update callback
        // update: function (dt) {
    
        // },
    });
  • 相关阅读:
    Scala控制抽象
    【转】ZooKeeper详细介绍和使用第一节
    zookeeper入门系列讲解
    最全面的 Spring 学习笔记
    MySQL 字符串拼接详解
    细说Python2.x与3​​.x版本区别
    【转】微信公众开发URL和token填写详解
    【转】Java代码操作Redis的sentinel和Redis的集群Cluster操作
    Java正则表达式的使用和详解(下)
    Java正则表达式的使用和详解(上)
  • 原文地址:https://www.cnblogs.com/orxx/p/10435828.html
Copyright © 2020-2023  润新知