{"id":681,"date":"2020-01-04T17:17:04","date_gmt":"2020-01-04T09:17:04","guid":{"rendered":"http:\/\/blog.xrhoujie.com\/?p=681"},"modified":"2020-01-02T10:36:00","modified_gmt":"2020-01-02T02:36:00","slug":"egret%e5%9f%ba%e7%a1%80-%e5%9d%90%e6%a0%87%e8%bd%ac%e6%8d%a2","status":"publish","type":"post","link":"http:\/\/blog.xrhoujie.com\/?p=681","title":{"rendered":"egret\u57fa\u7840-\u5750\u6807\u8f6c\u6362"},"content":{"rendered":"<p><code><br \/>\nclass Tolocal extends egret.DisplayObjectContainer {<br \/>\n    private static shared:Tolocal;<br \/>\n    public static getInstance(){<br \/>\n        if(!Tolocal.shared){<br \/>\n            Tolocal.shared = new Tolocal();<br \/>\n        }else{<br \/>\n            return Tolocal.shared<br \/>\n        }<br \/>\n    }<br \/>\n    public constructor() {<br \/>\n        super();<br \/>\n        this.addEventListener(egret.Event.ADDED_TO_STAGE, this.starGame, this)<br \/>\n    }<br \/>\n    private container: egret.DisplayObjectContainer<br \/>\n    private circle: egret.Shape<br \/>\n    private starGame(): void {<br \/>\n        this.container = new egret.DisplayObjectContainer();<br \/>\n        this.container.x = 200;<br \/>\n        this.container.y = 200;<br \/>\n        this.addChild(this.container);<br \/>\n        \/\/\u753b\u4e00\u4e2a\u7ea2\u8272\u7684\u5706\uff0c\u6dfb\u52a0\u5230 container \u4e2d<br \/>\n        this.circle = new egret.Shape();<br \/>\n        this.circle.graphics.beginFill(0xff0000);<br \/>\n        this.circle.graphics.drawCircle(25, 25, 25);<br \/>\n        this.circle.graphics.endFill();<br \/>\n        this.container.addChild(this.circle);<br \/>\n        \/\/\u7ed9\u5706\u589e\u52a0\u70b9\u51fb\u4e8b\u4ef6<br \/>\n        this.circle.touchEnabled = true;<br \/>\n        this.circle.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onClick, this);<br \/>\n    }<br \/>\n    private onClick(): void {<br \/>\n        \/\/\u628a\u821e\u53f0\u5de6\u4e0a\u89d2\u7684\u5750\u6807(0,0)\u8f6c\u6362\u4e3a container \u5185\u90e8\u7684\u5750\u6807<br \/>\n        var targetPoint: egret.Point = this.container.globalToLocal(100, 150);<br \/>\n        \/\/\u5c06\u5c40\u90e8\u7684circle\u5750\u6807\u8f6c\u6362\u4e3a\u5168\u5c40\u7684\u5750\u6807<br \/>\n        console.log(targetPoint.x,targetPoint.y)<br \/>\n        \/\/\u91cd\u65b0\u5b9a\u4f4d\u5706\uff0c\u53ef\u4ee5\u770b\u5230\u5706\u5f62\u79fb\u5230\u4e86\u5c4f\u5e55\u7684\u5de6\u4e0a\u89d2<br \/>\n        this.circle.x = targetPoint.x;<br \/>\n        this.circle.y = targetPoint.y;<br \/>\n    }<br \/>\n}<br \/>\n<\/code><\/p>\n<p><code><br \/>\n  this.addChild( Tolocal.getInstance() );<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>class Tolocal extends egret.DisplayObjectContainer { pr [&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\/681"}],"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=681"}],"version-history":[{"count":1,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts\/681\/revisions"}],"predecessor-version":[{"id":682,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts\/681\/revisions\/682"}],"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=681"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=681"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=681"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}