{"id":707,"date":"2020-06-22T19:25:57","date_gmt":"2020-06-22T11:25:57","guid":{"rendered":"http:\/\/blog.xrhoujie.com\/?p=707"},"modified":"2020-06-22T19:25:57","modified_gmt":"2020-06-22T11:25:57","slug":"%e6%89%93%e5%ad%97%e6%9c%ba%e6%95%88%e6%9e%9c","status":"publish","type":"post","link":"http:\/\/blog.xrhoujie.com\/?p=707","title":{"rendered":"\u6253\u5b57\u673a\u6548\u679c"},"content":{"rendered":"<p><code><br \/>\n\/**<br \/>\n* \u6253\u5b57\u673a\u6548\u679c\uff0c\u652f\u63011\u5c42\u7684richtext\u63a7\u5236\u6807\u7b7ecolor\u548csize<br \/>\n* Auth: MakeBestGame<br \/>\n*<br \/>\n* @namespace effectPrinter[creatorComponent]<br \/>\n* @example<br \/>\n* \u767b\u8bb0\u4e86\u2018fastForward\u2019\u4e8b\u4ef6\uff0c\u53ef\u4ee5\u901a\u8fc7<br \/>\n* cc.systemEvent.emit('fastForward', 0.01);<br \/>\n* \u4ee50.01\u79d2\u7684\u901f\u5ea6\u64ad\u653e<br \/>\n*<br \/>\n*\/<\/code><\/p>\n<p>cc.Class({<br \/>\nextends: cc.Component,<\/p>\n<p>properties: {<br \/>\ndelay: {<br \/>\ndefault: 0.1,<br \/>\ntooltip: &#8216;\u6253\u5b57\u5b57\u95f4\u9694\u65f6\u95f4\uff0c\u5355\u4f4d\uff1a\u79d2&#8217;,<br \/>\n},<br \/>\n_string: {<br \/>\ndefault: &#8221;,<br \/>\n},<br \/>\nstring: {<br \/>\ntooltip: &#8216;\u6253\u5370\u5185\u5bb9\u6587\u5b57&#8217;,<br \/>\nget() {<br \/>\nreturn this._string;<br \/>\n},<br \/>\nset(value) {<br \/>\nthis._string = value;<br \/>\nthis.reset();<br \/>\n},<br \/>\n},<br \/>\nfinish: {<br \/>\ndefault: null,<br \/>\ntype: cc.Component.EventHandler,<br \/>\ntooltip: &#8216;\u6253\u5b57\u5b8c\u6210\u56de\u8c03&#8217;,<br \/>\n},<br \/>\n},<\/p>\n<p>onLoad() {<br \/>\nlet com = this.node.getComponent(cc.Label);<br \/>\nif (!com) {<br \/>\ncom = this.node.getComponent(cc.RichText);<br \/>\n}<br \/>\nthis._labelCom = com;<br \/>\ncc.systemEvent.on(<br \/>\n&#8216;fastForward&#8217;,<br \/>\n(d) =&gt; {<br \/>\nthis.delay = d;<br \/>\n},<br \/>\nthis.node,<br \/>\n);<br \/>\n},<\/p>\n<p>reset() {<br \/>\nthis._stringArr = this._string.split(&#8221;);<br \/>\nthis._t = 0;<br \/>\nif (this._labelCom) {<br \/>\nthis._labelCom.string = &#8221;;<br \/>\n}<br \/>\ndelete this._rememberAdd;<br \/>\n},<br \/>\nupdate(dt) {<br \/>\nif (!this._labelCom) return;<br \/>\nif (!this._stringArr || this._stringArr.length &lt;= 0) return; this._t += dt; if (this._t &gt;= this.delay) {<br \/>\nlet char = this._stringArr.shift();<\/p>\n<p>if (char === &#8216;&lt;&#8216;) { \/\/ richtext\u63a7\u5236\u5b57\u7b26 let s = char; let end; while (end !== &#8216;&gt;&#8217;) {<br \/>\nend = this._stringArr.shift();<br \/>\ns += end;<br \/>\nif (this._stringArr.length &lt;= 0) break;<br \/>\n}<br \/>\nconst isEnd = s.indexOf(&#8216; {<br \/>\nif (isEnd === -1 &amp;&amp; s.indexOf(x) !== -1) {<br \/>\nchar = this._stringArr.shift();<br \/>\nthis._labelCom.string += char;<br \/>\nthis._rememberAdd = &#8220;;<br \/>\nthis._labelCom.string += this._rememberAdd;<br \/>\n}<br \/>\n});<br \/>\n} else {<br \/>\nif (this._rememberAdd) {<br \/>\n\/\/ \u5148\u53bb\u6389\u524d\u9762<br \/>\nthis._labelCom.string = this._labelCom.string.substring(0, this._labelCom.string.length &#8211; this._rememberAdd.length);<br \/>\n}<br \/>\nthis._labelCom.string += char;<br \/>\nif (this._rememberAdd) {<br \/>\n\/\/ \u5148\u53bb\u6389\u524d\u9762<br \/>\nthis._labelCom.string += this._rememberAdd;<br \/>\n}<br \/>\n}<br \/>\nthis._t = 0;<br \/>\nconsole.log(this._stringArr.length)<br \/>\nif (this._stringArr.length === 0) {<br \/>\nthis.node.emit(&#8216;finshEnd&#8217;);<br \/>\n}<br \/>\n}<br \/>\n},<br \/>\n});<\/p>\n<p>\u5f15\u7528\u7684\u65f6\u5019 \u76f4\u63a5\u83b7\u53d6\u8282\u70b9\u7684\u6587\u672c\u7ec4\u4ef6\uff0c\u6dfb\u52a0\u6587\u672c\u5185\u5bb9\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/** * \u6253\u5b57\u673a\u6548\u679c\uff0c\u652f\u63011\u5c42\u7684richtext\u63a7\u5236\u6807\u7b7ecolor\u548csize * Auth: MakeBes [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":307,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[30],"tags":[32],"_links":{"self":[{"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts\/707"}],"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=707"}],"version-history":[{"count":1,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts\/707\/revisions"}],"predecessor-version":[{"id":708,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts\/707\/revisions\/708"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/media\/307"}],"wp:attachment":[{"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=707"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=707"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=707"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}