{"id":176,"date":"2019-12-24T22:20:50","date_gmt":"2019-12-24T14:20:50","guid":{"rendered":"https:\/\/blog.indeex.club\/?p=176"},"modified":"2020-06-20T23:23:19","modified_gmt":"2020-06-20T15:23:19","slug":"45%e5%ba%a6%e5%bd%b1%e5%ad%90%e5%8e%9f%e7%90%86","status":"publish","type":"post","link":"https:\/\/blog.indeex.club\/index.php\/2019\/12\/24\/45%e5%ba%a6%e5%bd%b1%e5%ad%90%e5%8e%9f%e7%90%86\/","title":{"rendered":"45\u5ea6\u5f71\u5b50\u539f\u7406"},"content":{"rendered":"<hr \/>\n<p>\u5f71\u5b50\u5b9e\u73b0\u7684\u65b9\u5f0f\u6709\u5f88\u591a\uff0c\u539f\u7406\u5374\u4e0d\u4e00\u6837\uff0c\u8fd9\u91cc\u4f7f\u7528Typescript\u5b9e\u73b0\u7684\u4e00\u79cd\u65b9\u6848\uff0c\u5f53\u7136\u4e5f\u8bb8\u6709\u66f4\u597d\u7684\u65b9\u6848\u3002\u4ee5\u4e0b\u662f\u5b9e\u73b0\u539f\u7406\uff08\u8bf7\u52ff\u76f4\u63a5\u4f7f\u7528\u4e8e\u9879\u76ee\uff09\uff0c\u5b9e\u73b0\u7684\u539f\u7406\u6bd4\u8f83\u7b80\u5355\uff0c\u4e0d\u518d\u505a\u8be6\u7ec6\u8d58\u8ff0\u3002<\/p>\n<p>\u9996\u5148\u662f\u6784\u9020\u3001\u58f0\u660e\u548c\u57fa\u672c\u7684\u8bbe\u7f6e\uff1a<\/p>\n<pre><code class=\"language-javascript line-numbers\">public static const DIRECTION_RIGHT:number = 1;\npublic static const DIRECTION_LEFT:number = -1;\n\nprivate var vertices:Array&lt;number&gt;;\nprivate var indices:Array&lt;number&gt;;\nprivate var uvtData:Array&lt;number&gt;;\nprivate var bmpd:BitmapData;\nprivate var bodySprite:Shape;\nprivate var direction:number;\nprivate var delay:number;\nprivate var matrix:Matrix\n\npublic EntityShadow(direction:number = DIRECTION_LEFT) {\n    this.direction = direction;\n    this.bodySprite = new Shape();\n    this.vertices = new Array&lt;number&gt;();\n    this.indices = new Array&lt;number&gt;();\n    this.uvtData = new Array&lt;number&gt;();\n    this.matrix = new Matrix();\n\n    this.mouseChildren = false;\n    this.mouseEnabled = false;\n\n    this.indices.push(0, 3, 4);\n    this.indices.push(0, 1, 4);\n    this.indices.push(1, 4, 5);\n    this.indices.push(1, 2, 5);\n\n    this.uvtData.push(1, -1);\n    this.uvtData.push(0, -1);\n    this.uvtData.push(0, 1);\n    this.uvtData.push(1, -1);\n    this.uvtData.push(1, -1);\n    this.uvtData.push(1, 1);\n}\n<\/code><\/pre>\n<p>\u7136\u540e\u662f\u6e32\u67d3\uff1a<\/p>\n<pre><code class=\"language-javascript line-numbers\">public render(oMovieClips:Array):void {\n    if (delay &lt;= 0) { \/\/\u8fd9\u91cc\u53ea\u662f\u4e3a\u4e86\u63d0\u5347\u6548\u7387\n        this.delay = 2;\n        this.dispose();\n\n        for each (var omc:OMovieClip in oMovieClips) {\/\/\u81ea\u5b9a\u4e49\u7684sprite\u5e8f\u5217\u52a8\u753bMovieClip\n            if (omc.bitmapData != null) {\n                matrix.b = 0;\n                matrix.c = 0;\n                matrix.d = 1;\n                matrix.tx = omc.x;\n                matrix.ty = omc.y;\n                if (!omc.isMirro) { \/\/\u4f4d\u56fe\u955c\u50cf\n                    matrix.a = 1;\n                    bodySprite.graphics.beginBitmapFill(omc.bitmapData, matrix);\n                    bodySprite.graphics.drawRect(omc.x, omc.y, omc.bitmapData.width, omc.bitmapData.height);\n                    bodySprite.graphics.endFill();\n                } else {\n                    matrix.a = -1;\n                    bodySprite.graphics.beginBitmapFill(omc.bitmapData, matrix);\n                    bodySprite.graphics.drawRect(omc.x - omc.bitmapData.width, omc.y, omc.bitmapData.width, omc.bitmapData.height);\n                    bodySprite.graphics.endFill();\n                }\n            }\n        }\n\n        this.update(bodySprite);\n    } else {\n        this.delay--;\n    }\n}\n<\/code><\/pre>\n<p>\u7136\u540e\u5bf9\u4f4d\u56fe\u62c9\u4f38\u64cd\u4f5c\uff1a<\/p>\n<pre><code class=\"language-javascript line-numbers\">private update(display:DisplayObject):void {\n    var rect:Rectangle = display.getRect(display);\n    if (rect.width &gt; 0 &amp;&amp; rect.height &gt; 0) {\n        var tempH:Number = rect.height;\n\n        this.bmpd = new BitmapData(rect.width, rect.height, true, 0xFFFFFF);\n        this.bmpd.lock();\n        this.bmpd.draw(display, new Matrix(1, 0, 0, .95, -rect.x, -rect.y));\n\n        this.bmpd.applyFilter(this.bmpd, bmpd.rect, GlobalConst.ZERO_POINT, GlobalConst.ALPHA_BLACK_COLORMATRIXFILTER);\n        this.bmpd.unlock();\n\n        this.vertices.splice(0, vertices.length);\n\n        this.vertices.push(0, 0);\n        this.vertices.push(tempH * this.direction, 0);\n        this.vertices.push(0, rect.height);\n        this.vertices.push(rect.width, 0);\n        this.vertices.push(rect.width + tempH * this.direction, 0);\n        this.vertices.push(rect.width, rect.height);\n\n        this.graphics.beginBitmapFill(bmpd, null, false);\n        this.graphics.drawTriangles(vertices, indices, uvtData);\n        this.graphics.endFill();\n        this.x = rect.x;\n        this.y = rect.y;\n    }\n}\n<\/code><\/pre>\n<p>\u8fd9\u91cc\u662f\u4ee5120*120\u7684\u77e9\u9635\u6f14\u793a\u3002<\/p>\n<p>\u6700\u540e\u662f\u9500\u6bc1\u64cd\u4f5c\uff1a<\/p>\n<pre><code class=\"language-javascript line-numbers\">public dispose():void {\n    this.graphics.clear();\n    this.bodySprite.graphics.clear();\n    if (this.bmpd != null)\n        this.bmpd.dispose();\n}\n<\/code><\/pre>\n<p>\u5927\u6982\u5b9e\u73b0\u5c31\u662f\u8fd9\u6837\uff0c\u6bd4\u5176\u4ed6\u5b9e\u73b0\u65b9\u5f0f\u597d\u7406\u89e3\uff0c\u800c\u4e14\u635f\u8017\u4e5f\u5c11\u5f88\u591a\u3002<\/p>\n<p>code enjoy! \ud83d\ude04\ud83d\ude04\ud83d\ude01<\/p>\n<p>\u4f5c\u8005\uff1aindeex<\/p>\n<p>\u94fe\u63a5\uff1a<a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/indeex.cc\/\">https:\/\/indeex.cc<\/a><\/p>\n<p>\u8457\u4f5c\u6743\u5f52\u4f5c\u8005\u6240\u6709\u3002\u5546\u4e1a\u8f6c\u8f7d\u8bf7\u8054\u7cfb\u4f5c\u8005\u83b7\u5f97\u6388\u6743\uff0c\u975e\u5546\u4e1a\u8f6c\u8f7d\u8bf7\u6ce8\u660e\u51fa\u5904\u3002<\/p>\n<hr \/>\n","protected":false},"excerpt":{"rendered":"<p>\u5f71\u5b50\u5b9e\u73b0\u7684\u65b9\u5f0f\u6709\u5f88\u591a\uff0c\u539f\u7406\u5374\u4e0d\u4e00\u6837\uff0c\u8fd9\u91cc\u4f7f\u7528Typescript\u5b9e\u73b0\u7684\u4e00\u79cd\u65b9\u6848\uff0c\u5f53\u7136\u4e5f\u8bb8\u6709\u66f4\u597d\u7684\u65b9\u6848<a href=\"https:\/\/blog.indeex.club\/index.php\/2019\/12\/24\/45%e5%ba%a6%e5%bd%b1%e5%ad%90%e5%8e%9f%e7%90%86\/\" class=\"read-more\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[4],"_links":{"self":[{"href":"https:\/\/blog.indeex.club\/index.php\/wp-json\/wp\/v2\/posts\/176"}],"collection":[{"href":"https:\/\/blog.indeex.club\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.indeex.club\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.indeex.club\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.indeex.club\/index.php\/wp-json\/wp\/v2\/comments?post=176"}],"version-history":[{"count":1,"href":"https:\/\/blog.indeex.club\/index.php\/wp-json\/wp\/v2\/posts\/176\/revisions"}],"predecessor-version":[{"id":179,"href":"https:\/\/blog.indeex.club\/index.php\/wp-json\/wp\/v2\/posts\/176\/revisions\/179"}],"wp:attachment":[{"href":"https:\/\/blog.indeex.club\/index.php\/wp-json\/wp\/v2\/media?parent=176"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.indeex.club\/index.php\/wp-json\/wp\/v2\/categories?post=176"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.indeex.club\/index.php\/wp-json\/wp\/v2\/tags?post=176"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}