码迷,mamicode.com
首页 > 其他好文 > 详细

8, 文本

时间:2017-09-28 13:13:59      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:shape   div   graphic   var   ddc   不用   ddl   添加   fill   

1, 显示文本

import tr = egret.sys.tr;

class Main extends egret.DisplayObjectContainer {

    public constructor() {
        super();
        this.once(egret.Event.ADDED_TO_STAGE, this.start, this);
    }

    private start(event:egret.Event) {
        /**
         * 绘制一行简单的文字
         * label.text 绘制统一的文字
         * label.textFlow 可以给每一个字符添加特定的样式
         */
        var label:egret.TextField = new egret.TextField();
        //label.text = "普通的文字";
        label.textFlow = <Array<egret.ITextElement>>[
            {text: "妈妈再也不用担心我在", style: {"size": 12}},
            {text: "Egret", style: {"textColor": 0x336699, "size": 60, "strokeColor": 0x6699cc, "stroke": 2}},
            {text: "里说一句话不能包含各种", style: {"fontFamily": "楷体"}},
            {text: "五", style: {"textColor": 0xff0000}},
            {text: "彩", style: {"textColor": 0x00ff00}},
            {text: "缤", style: {"textColor": 0xf000f0}},
            {text: "纷", style: {"textColor": 0x00ffff}},
            {text: "、\n"},
            {text: "大", style: {"size": 36}},
            {text: "小", style: {"size": 6}},
            {text: "不", style: {"size": 16}},
            {text: "一", style: {"size": 24}},
            {text: "、"},
            {text: "格", style: {"italic": true, "textColor": 0x00ff00}},
            {text: "式", style: {"size": 16, "textColor": 0xf000f0}},
            {text: "各", style: {"italic": true, "textColor": 0xf06f00}},
            {text: "样", style: {"fontFamily": "楷体"}},
            {text: ""},
            {text: "的文字了!"}
        ];
        label.x = 0;
        label.y = 0;
        label.width = 640;
        label.height = 1136;
        label.size = 50;
        label.textColor = 0xff0000;
        label.fontFamily = "KaiTi";
        label.textAlign = egret.HorizontalAlign.CENTER;
        label.verticalAlign = egret.VerticalAlign.MIDDLE;
        label.strokeColor = 0x0000ff;
        label.stroke = 0;
        label.bold = false;
        label.italic = false;
        this.addChild(label);
    }

}

2, 输入文本框

import tr = egret.sys.tr;

class Main extends egret.DisplayObjectContainer {

    public constructor() {
        super();
        this.once(egret.Event.ADDED_TO_STAGE, this.start, this);
    }

    private start(event:egret.Event) {

        /**
         * 可以绘制的文本框, 文本框必须放在一个显示对象内, 如下的 container
         * 文本框必须添加一个背景才能肉眼可见, 如下的 shp
         * 可输入文本框的样式 和 显示文本框相似
         */

        var container:egret.Sprite = new egret.Sprite;
        container.graphics.beginFill(0x000000);
        container.graphics.drawRect(0,0,640,1136);
        container.graphics.endFill();
        this.addChild(container)

        var txInput:egret.TextField = new egret.TextField;
        txInput.type = egret.TextFieldType.INPUT;
        txInput.width = 620;
        txInput.height = 100;
        txInput.x = 10;
        txInput.y = 20;
        txInput.textColor = 0x000000;
        txInput.textAlign = egret.HorizontalAlign.CENTER;
        txInput.verticalAlign = egret.VerticalAlign.MIDDLE;
        container.addChild(txInput);

        var shp:egret.Shape = new egret.Shape;
        shp.graphics.beginFill(0xffffff);
        shp.graphics.drawRect(txInput.x, txInput.y, txInput.width, txInput.height);
        shp.graphics.endFill();
        container.addChild(shp);

    }

}

 

8, 文本

标签:shape   div   graphic   var   ddc   不用   ddl   添加   fill   

原文地址:http://www.cnblogs.com/lovling/p/7605963.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!