{"id":404,"date":"2018-02-13T17:52:52","date_gmt":"2018-02-13T09:52:52","guid":{"rendered":"http:\/\/blog.xrhoujie.com\/?p=404"},"modified":"2019-01-18T18:39:58","modified_gmt":"2019-01-18T10:39:58","slug":"cocos-creator%e8%ae%ba%e6%8b%96%e6%8b%bd%e7%9a%84%e4%b8%89%e7%a7%8d%e6%96%b9%e5%bc%8f","status":"publish","type":"post","link":"http:\/\/blog.xrhoujie.com\/?p=404","title":{"rendered":"cocos Creator\u8bba\u62d6\u62fd\u7684\u4e09\u79cd\u65b9\u5f0f"},"content":{"rendered":"<p>\u65e5\u5e38\u9547\u697c\u56fe\u7247<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-358\" src=\"http:\/\/blog.xrhoujie.com\/wp-content\/uploads\/2017\/11\/timg.jpeg\" alt=\"\" width=\"211\" height=\"124\" \/><\/p>\n<p>\u7b2c\u4e00\u79cd-touchmove<\/p>\n<p>\u7a0b\u5e8f\u6267\u884c<\/p>\n<div>\n<div>this.touchPt.on(&#8216;touchmove&#8217;, onTouchMove, this.touchPt);<\/div>\n<div><\/div>\n<\/div>\n<div>this.touchPt\u6307\u7684\u662f\u62d6\u62fd\u7684\u7269\u4f53\uff0c(\u4e8b\u4ef6\u76d1\u542c\u65b9\u5f0f\uff0c\u6267\u884c\u51fd\u6570\uff0c\u56de\u8c03\u51fd\u6570)<\/div>\n<div><\/div>\n<div>\n<div>\n<div>function onTouchMove(touch,event) {<\/div>\n<div>varpt=this.parent.convertTouchToNodeSpaceAR(touch); \/\/\u8f6c\u6362\u5750\u6807\u5230\u5c40\u90e8\u5750\u6807<\/div>\n<div>this.x=pt.x;<\/div>\n<div>this.y=pt.y;<\/div>\n<div>}<\/div>\n<\/div>\n<\/div>\n<div>\u7b2c\u4e8c\u79cd-cc.Node.EventType.TOUCH_MOVE\uff0ccc.Node.EventType.TOUCH_END\u91c7\u7528\u8282\u70b9\u7684\u65b9\u5f0f\u8fdb\u884c\uff0c\u68c0\u6d4b\u79fb\u52a8\uff0c\u79fb\u52a8\u7ed3\u675f\uff0c\u4ee3\u7801\u5982\u4e0b\uff0c<\/div>\n<div>\n<div>\n<div>varself=this;<\/div>\n<div>letgetTouch=cc.find(&#8216;Canvas\/text-Label&#8217;);<\/div>\n<div>getTouch.on(cc.Node.EventType.TOUCH_MOVE, function (event) {<\/div>\n<div>this.opacity=100;<\/div>\n<div>vardelta=event.touch.getDelta();<\/div>\n<div>this.x+=delta.x;<\/div>\n<div>this.y+=delta.y;<\/div>\n<div>}, getTouch);<\/div>\n<div>getTouch.on(cc.Node.EventType.TOUCH_END, function () {<\/div>\n<div>this.opacity=255;<\/div>\n<div>}<\/div>\n<\/div>\n<\/div>\n<div>\u505a\u4e86\u4e00\u4e2a\u7269\u4f53\u62d6\u62fd\u65f6\u900f\u660e\u7684\u7684\u53d8\u5316\uff0c<\/div>\n<div><\/div>\n<div>\u7b2c\u4e09\u79cd-\u6bd4\u8f83\u968f\u610f\uff0c\u53ef\u4ee5\u6df7\u642d\uff0c\u5373<\/div>\n<div><\/div>\n<div>\n<div>varself=this;<\/div>\n<div><\/div>\n<div>\/\/\u62d6\u62fd\u751f\u6548\u4ee3\u7801<\/div>\n<div><\/div>\n<div>functiononTouchMove(touch,event) {<\/div>\n<div>varpt=this.parent.convertTouchToNodeSpaceAR(touch);<\/div>\n<div>this.x=pt.x;<\/div>\n<div>this.y=pt.y;<\/div>\n<div>}<\/div>\n<div><\/div>\n<div>\/\/\u62d6\u62fd\u7269\u4f53\u653e\u7f6e\u6761\u4ef6<\/div>\n<div><\/div>\n<div>functionendMove(){<\/div>\n<div>this.reactWidthMax=654;this.reactWidthMin=578;this.reactHeightMin=-25;this.reactHeightMax=176;<\/div>\n<div>if(this.y&lt;this.reactHeightMax&amp;&amp;this.y&gt;this.reactHeightMin&amp;&amp;this.x&lt;this.reactWidthMax&amp;&amp;this.x&gt;this.reactWidthMin){<\/div>\n<div>self.jumpStop=cc.audioEngine.playMusic(self.backSound, true, 0.5);<\/div>\n<div>}else{<\/div>\n<div>this.x=this.y=40;<\/div>\n<div>cc.audioEngine.stop(self.jumpStop);<\/div>\n<div>}<\/div>\n<div>}<\/div>\n<\/div>\n<div><\/div>\n<div>\/\/\u62d6\u62fd\u68c0\u6d4b\u72b6\u6001<\/div>\n<div><\/div>\n<div>\n<div>this.touchPt.on(&#8216;touchmove&#8217;, onTouchMove, this.touchPt); \/\/\u79fb\u52a8<\/div>\n<div>this.touchPt.on(&#8216;touchend&#8217;, endMove, this.touchPt);\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \/\/\u79fb\u52a8\u7ed3\u675f<\/div>\n<div><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u65e5\u5e38\u9547\u697c\u56fe\u7247 \u7b2c\u4e00\u79cd-touchmove \u7a0b\u5e8f\u6267\u884c this.touchPt.on(&#8216;touchm [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[30],"tags":[],"_links":{"self":[{"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts\/404"}],"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=404"}],"version-history":[{"count":1,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts\/404\/revisions"}],"predecessor-version":[{"id":405,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts\/404\/revisions\/405"}],"wp:attachment":[{"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=404"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=404"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=404"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}