{"id":676,"date":"2019-12-08T17:02:17","date_gmt":"2019-12-08T09:02:17","guid":{"rendered":"http:\/\/blog.xrhoujie.com\/?p=676"},"modified":"2019-12-08T17:02:17","modified_gmt":"2019-12-08T09:02:17","slug":"egret%e5%9f%ba%e7%a1%80-%e6%96%87%e6%9c%ac%e7%bc%96%e8%be%91","status":"publish","type":"post","link":"http:\/\/blog.xrhoujie.com\/?p=676","title":{"rendered":"egret\u57fa\u7840-\u6587\u672c\u7f16\u8f91"},"content":{"rendered":"<p><code><br \/>\nclass TextTest extends egret.DisplayObjectContainer {<\/p>\n<p>    private static shared:TextTest;<br \/>\n    public static getInstace(){<br \/>\n        if(!TextTest.shared){<br \/>\n            TextTest.shared = new TextTest()<br \/>\n        }else{<br \/>\n           return TextTest.shared<br \/>\n        }<br \/>\n    }<br \/>\n    public constructor() {<br \/>\n        super();<br \/>\n        this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);<br \/>\n    }<br \/>\n    private onAddToStage(event: egret.Event) {<br \/>\n        this.drawText();<br \/>\n        \/\/ this.drawInput()<br \/>\n        \/\/ this.inputType()<br \/>\n        \/\/ RES.getResByUrl(\"resource\/cartoon-font.fnt\", this.onLoadComplete, this, RES.ResourceItem.TYPE_FONT);<br \/>\n    }<br \/>\n    private infoText: egret.TextField;<\/p>\n<p>    private drawText() {<br \/>\n        this.infoText = new egret.TextField();<br \/>\n        this.infoText.y = 400;<br \/>\n        this.infoText.text = \"\u8fd9\u662f\u4e00\u6761\u666e\u901a\u6587\u672c\";<br \/>\n        this.infoText.textColor = 0x0000ff;<br \/>\n        this.infoText.fontFamily = 'Impact'<br \/>\n        this.infoText.width = 100;<br \/>\n        this.infoText.height = 100;<br \/>\n        this.infoText.size = 20<br \/>\n        this.infoText.strokeColor = 0x000000;<br \/>\n        this.infoText.stroke = 2;<\/p>\n<p>        this.infoText.bold = true;<br \/>\n        this.infoText.italic = true;<\/p>\n<p>        \/\/    this.infoText.textAlign = egret.HorizontalAlign.RIGHT;<br \/>\n        \/\/ this.infoText.textAlign = egret.HorizontalAlign.LEFT;<br \/>\n        \/\/ this.infoText.textAlign = egret.HorizontalAlign.CENTER;<br \/>\n        \/\/ \u7eb5\u5217\u5bf9\u9f50<br \/>\n        \/\/ this.infoText.verticalAlign = egret.VerticalAlign.BOTTOM;<br \/>\n        \/\/\u5782\u76f4\u5c45\u4e2d\u5bf9\u9f50<br \/>\n        \/\/ this.infoText.verticalAlign = egret.VerticalAlign.MIDDLE;<\/p>\n<p>        this.addChild(this.infoText);<br \/>\n    }<br \/>\n    private drawInput() {<br \/>\n        var textIput: egret.TextField = new egret.TextField();<br \/>\n        textIput.type = egret.TextFieldType.INPUT;<br \/>\n        this.addChild(textIput);<\/p>\n<p>        var button: egret.Shape = new egret.Shape();<br \/>\n        button.graphics.beginFill(0x00cc00);<br \/>\n        button.graphics.drawRect(0, 0, 100, 40);<br \/>\n        button.graphics.endFill();<br \/>\n        button.y = 50;<br \/>\n        this.addChild(button);<\/p>\n<p>        button.touchEnabled = true;<br \/>\n        button.addEventListener(egret.TouchEvent.TOUCH_BEGIN, (e) => {<br \/>\n            textIput.setFocus();<br \/>\n        }, this);<br \/>\n    }<br \/>\n    private inputType() {<br \/>\n        var text: egret.TextField = new egret.TextField();<br \/>\n        text.type = egret.TextFieldType.INPUT;<br \/>\n        \/\/\u8bbe\u7f6e\u8f93\u5165\u6587\u672c\u7684\u6837\u5f0f\u4e3a\u6587\u672c<br \/>\n        text.inputType = egret.TextFieldInputType.TEXT;<br \/>\n        text.text = \"Input text:\";<br \/>\n        text.width = 300;<br \/>\n        this.addChild(text);<\/p>\n<p>        var pass: egret.TextField = new egret.TextField();<br \/>\n        pass.type = egret.TextFieldType.INPUT;<br \/>\n        \/\/\u8bbe\u7f6e\u8f93\u5165\u6587\u672c\u663e\u793a\u4e3a\u5bc6\u7801<br \/>\n        pass.inputType = egret.TextFieldInputType.PASSWORD;<br \/>\n        \/\/\u8bbe\u7f6e\u5bc6\u7801\u663e\u793a<br \/>\n        pass.displayAsPassword = true;<br \/>\n        pass.text = \"Password\";<br \/>\n        pass.y = 100;<br \/>\n        pass.width = 300;<br \/>\n        this.addChild(pass);<\/p>\n<p>        var tel: egret.TextField = new egret.TextField();<br \/>\n        tel.type = egret.TextFieldType.INPUT;<br \/>\n        \/\/\u8bbe\u7f6e\u8f93\u5165\u7535\u8bdd\u53f7\u6837\u5f0f<br \/>\n        tel.inputType = egret.TextFieldInputType.TEL;<br \/>\n        tel.text = \"Telephone number:\"<br \/>\n        tel.y = 200;<br \/>\n        tel.width = 300;<br \/>\n        this.addChild(tel);<br \/>\n    }<br \/>\n    private _bitmapText: egret.BitmapText;<br \/>\n    private onLoadComplete(font: egret.BitmapFont): void {<br \/>\n        this._bitmapText = new egret.BitmapText();<br \/>\n        this._bitmapText.font = font;<br \/>\n        this._bitmapText.x = 50;<br \/>\n        this._bitmapText.y = 300;<br \/>\n        this.addChild(this._bitmapText);<br \/>\n    }<br \/>\n}<br \/>\n<\/code><\/p>\n<p><code><br \/>\n this.addChild( TextTest.getInstace() );<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>class TextTest extends egret.DisplayObjectContainer { p [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":469,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[15],"_links":{"self":[{"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts\/676"}],"collection":[{"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=676"}],"version-history":[{"count":1,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts\/676\/revisions"}],"predecessor-version":[{"id":677,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts\/676\/revisions\/677"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/media\/469"}],"wp:attachment":[{"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=676"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=676"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=676"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}