{"id":391,"date":"2018-01-14T20:52:29","date_gmt":"2018-01-14T12:52:29","guid":{"rendered":"http:\/\/blog.xrhoujie.com\/?p=391"},"modified":"2021-10-19T10:41:33","modified_gmt":"2021-10-19T02:41:33","slug":"cocos-creator%e8%b7%b3%e4%b8%80%e8%b7%b3%e5%be%ae%e4%bf%a1%e5%b0%8f%e6%b8%b8%e6%88%8f","status":"publish","type":"post","link":"http:\/\/blog.xrhoujie.com\/?p=391","title":{"rendered":"cocos Creator\u8df3\u4e00\u8df3(\u5fae\u4fe1\u5c0f\u6e38\u620f)"},"content":{"rendered":"<p>\u968f\u7740\u5fae\u4fe1\u5c0f\u6e38\u620f\uff08\u8df3\u4e00\u8df3\uff09\u7684\u51fa\u73b0\u4e00\u4e0b\u5b50\u706b\u4e86\u8d77\u6765\uff0c\u542c\u8bf4\u8bd5\u73a9\u7528\u6237\u5df2\u7ecf\u8d85\u8fc7\u4e861.7\u4ebf\u5927\u5173\uff0c\u8fd9\u662f\u8981\u641e\u4e8b\u60c5\u554a\uff01\u6211\u6709\u9884\u611f\uff0c\u968f\u7740\u5fae\u4fe1\u5c0f\u6e38\u620f\u7684\u63a8\u51fa\uff0c\u540e\u9762\u80fd\u591f\u5e26\u6765\u4e86\u4e00\u6279h5\u5c0f\u6e38\u620f\u7684\u72c2\u6f6e\uff0c\u5e94\u8be5\u8fd8\u662f\u6709\u6f5c\u529b\u7684\u3002<\/p>\n<p>\u4e0d\u8bf4\u5e9f\u8bdd\u4e86\uff0c\u76f4\u63a5\u6b63\u5982\u4e3b\u9898\uff0c\u524d\u51e0\u5929\u7814\u7a76\u4e86\u4e00\u4e0b\u8df3\u4e00\u8df3\u53d1\u73b0\u8fd8\u662f\u633a\u6709\u8da3\u513f\u7684\uff0c\u9ebb\u96c0\u867d\u5c0f\u4e94\u810f\u4ff1\u5168\uff0c\u6d89\u53ca\u4e00\u4e9b\u7b97\u6cd5\uff0c\u6bd4\u5982\u68cb\u5b50\u8df3\u8dc3\u7684\u529b\u5ea6\u63a7\u5236\uff0c\u8df3\u8dc3\u7684\u5f27\u5ea6\u6570\uff0c\u8fd8\u6709\u8df3\u8dc3\u65f6\u5019\u6709\u4e2a\u4e8c\u6b21\u65b9\u66f2\u7ebf\uff0c\u8fd8\u7528\u5230\u4e86\u7c92\u5b50\uff0c\u8fd8\u6709\u56fe\u5f62\u5b66\u76f8\u5173\u7684\u77e5\u8bc6\uff08ps Creator\u6ca1\u67093d\u6982\u5ff5\uff0c\u53ea\u80fd\u7528\u659c\u5207\u7684xy\u6765\u641e\u54af\uff09\uff0c\u4e0e\u5236\u9020\u56de\u6536 \u5bf9\u8c61\u6c60 \u3002<\/p>\n<p>\u65e5\u5e38\u535a\u5ba2\u4e0a\u8f66\u56fe\u9547\u697c\u3002<\/p>\n<p>&nbsp;<\/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>come on \u5750\u7a33\u4e86\u53d1\u8f66\u3002<\/p>\n<p>\u4eca\u5929\u4e3b\u8981\u4ece\u56db\u4e2a\u89d2\u5ea6\u6765\u8fdb\u884c\u5256\u6790\u8df3\u4e00\u8df3\uff0c\u5206\u522b\u662f \u624b\u6307\u6309\u4e0b\u65f6\uff0c\u624b\u6307\u91ca\u653e\u65f6\uff0cblock\u7684\u4ea7\u751f\u4e0e\u56de\u6536\u5bf9\u8c61\u6c60\uff0c\u68c0\u6d4b\u4e0e\u7ed3\u675f\u6e38\u620f\u903b\u8f91\u5904\u7406\u3002<\/p>\n<p>\u6309\u4e0b\u72b6\u6001\uff1a\u9996\u5148\u8fd9\u5757\u6211\u4eec\u6765\u62c6\u5206\u4e24\u5757\u6765\u8bb2\uff0c<\/p>\n<p>1.player\uff1a\u9996\u5148\u6211\u4eec\u6839\u636e\u6309\u4e0b\u65f6\u7684\u72b6\u6001\uff0c\u80fd\u591f\u770b\u51fa \u8fd9\u91cc\u7684player\u505a\u4e86\u4e00\u4e2a\u84c4\u529b\u7684\u52a8\u4f5c\uff0c\u662f\u901a\u8fc7\u6539\u53d8scaleY\u8fdb\u884c\u7684\uff0c\u8fd9\u91cc\u9762\u7528\u4e86run&#8217;Action\u6765\u8fdb\u884c\u8865\u95f4\u64cd\u4f5c\uff0c\u516c\u5f0f\u4e3a\uff1ascale * dt \/ scle\u00a0 &lt; Maxdt\u00a0 \u53ef\u4ee5\u7406\u89e3\u4e3a \u6309\u4e0b\u65f6scaleY\u5c0f\u4e8e1\uff0c\u5e76\u4e14\u5927\u4e8e\u5e95\u6570\uff0c(\u4e0d\u80fd\u8ba9\u4f4e\u4e8e\u5e95\u6570\u5426\u5219\u4f1a\u51fa\u73b0player\u602a\u5f02\u53d8\u5f62)<\/p>\n<p>2.jump player\uff1a\u8fd9\u6b21\u6211\u4eec\u6765\u8bf4\u5f39\u8df3\uff0c\u6211\u4eec\u5148\u8981\u8003\u8651\u7684\u662f\u8df3\u8dc3\u503c\u5f97\u8ba1\u7b97\u516c\u5f0f\uff0cthis.speed += dt * this.this.power\u00a0 \u65e2\u5e95\u6570 += dt\u6309\u4e0b\u65f6\u957f * \u84c4\u529b\u503c\uff0c\u6211\u4eec\u5f97\u5230\u4e86\u5e95\u6570\u540e\uff0c\u5e26\u5165<\/p>\n<p>this.jumpDistance += this.speed * dt ; \u8df3\u8dc3\u8ddd\u79bb += \u5e95\u6570 * \u6309\u4e0b\u65f6\u957f\uff0c<\/p>\n<p>\u677e\u5f00\u72b6\u6001\uff1a\u8fd9\u91cc\u4e5f\u62c6\u5206\u4e24\u5757\u8bb2\u3002<\/p>\n<p>1.\u5f88\u660e\u663e\u4ed6\u5728\u677e\u5f00\u65f6\u5019player\u5728\u7a7a\u4e2d\u8fdb\u884c\u4e86\u4e00\u4e2a360\u7ffb\u8f6c\u7684\u52a8\u4f5c\uff0c\u8fd9\u91cc\u4ee3\u7801\u4e3a<\/p>\n<div>\n<div>cc.rotateBy(0.5,this.direction*360);<\/div>\n<\/div>\n<div><\/div>\n<div>\n<div>2.\u7ffb\u8f6c\u540e\u660e\u663e\u770b\u5230\u6211\u4eec\u7684player\u7684scale\u53d8\u56de\u6765\u4e86scale\u4e3a1\u3002<\/div>\n<\/div>\n<div><\/div>\n<div>block\u5904\u7406\uff1a<\/div>\n<div>\n<div>\n<div>let n = Math.floor(Math.random() * this.blockList.length);<\/div>\n<div>let blockNode=cc.instantiate(this.blockList[n]);<\/div>\n<div>this.blockLayer.addChild(blockNode);<\/div>\n<div>let block=blockNode.getComponent(Block);<\/div>\n<div>let scale=block.minScale+Math.random() * (block.maxScale-block.minScale);<\/div>\n<div>let distance=block.minDistance+Math.random() * (block.maxDistance-block.minDistance);<\/div>\n<div>blockNode.scale=scale;<\/div>\n<div>if (this.player.direction&gt;0) {<\/div>\n<div>blockNode.x=this.currBlock.node.x+distance;<\/div>\n<div>blockNode.y=this.currBlock.node.y+distance*this.arrayRatio;<\/div>\n<div>} else {<\/div>\n<div>blockNode.x=this.currBlock.node.x-distance;<\/div>\n<div>blockNode.y=this.currBlock.node.y+distance*this.arrayRatio;<\/div>\n<div>}<\/div>\n<div>this.currBlock=this.nextBlock;<\/div>\n<div>this.nextBlock=block;<\/div>\n<div>returnblock;<\/div>\n<\/div>\n<\/div>\n<div>\u968f\u673a\u4ece\u6570\u7ec4\u5bf9\u8c61\u6c60\u91cc\u9762\u53d6\u51fa\u4e00\u4e2a\u4e0b\u6807\uff0c\u901a\u8fc7\u4e0b\u6807\u7d22\u5f15\u5bf9\u5e94\u56fe\u7247\u7684url\u5730\u5740\uff0c\u5728\u8fdb\u884caddChild \u6dfb\u52a0\u5230\u821e\u53f0\u4e0a\uff08\u8ddd\u79bb\u4e3a \u6700\u5c0f\u8ddd\u79bb + \u968f\u673a\u6570 * \uff08\u6700\u5927\u00a0 &#8211; \u6700\u5c0f\uff09\uff09\u4ece\u800c\u4fdd\u8bc1\u56fe\u7247\u4e0d\u4f1a\u8d85\u51fa\u5c4f\u5e55scale\u4e3a\u76f8\u540c\u7b97\u6cd5\uff0c\u518d\u6b21\u8fdb\u884c\u5339\u914d\u8282\u70b9\u7684\u4f4d\u7f6e\uff0c\u6700\u540e\u8fd4\u56de\u65b9\u5757\u3002<\/div>\n<div><\/div>\n<div>\u518d\u7136\u540e\u5c31\u662f\u8fdb\u884c\u5224\u65ad\uff0c\u5148\u5c06\u4e16\u754c\u5750\u6807\u8f6c\u5230\u5c40\u90e8\u5750\u6807\u4f4d\u7f6e\uff0c\u901a\u8fc7u\u6765\u8fdb\u884c\u5224\u65ad\u662f\u5728ringt\u00a0 or left \u5e76\u5c06\u8bb0\u5f55\u5b58\u50a8\uff0c\u8fdb\u884c\u4fbf\u5229\u64cd\u4f5c\uff0c<\/div>\n<div><\/div>\n<div>\n<p>\u68c0\u6d4b\uff1aplayer\u7684\u4f4d\u7f6e\u662f\u5426\u5728\u00a0 nearWrap.left\u00a0 &lt; player.loacl &lt; nearWrap.right &amp;&amp;nearWrap.bottom &lt; player.loacl\u00a0 &lt; nearWrap.top,\u5982\u679c\u662f\u90a3\u4e48\u4f60\u6210\u529f\u4e86\uff0c\u76f4\u63a5\u8fd4\u56degetPosition,\u8fd9\u91cc\u8f6c\u79fb\u5750\u6807\u7528<\/p>\n<div>\n<div>convertToNodeSpaceAR\u51fd\u6570<\/div>\n<div>\uff0c\u5982\u679c\u4e0d\u662f\u90a3\u4e48\u76f4\u63a5\u8c03\u906e\u7f69\u5c42\u4e0e\u5f97\u5206\u9762\u677f\u5f39\u51fa\uff0cgameOver\uff0c\u6253\u5b8c\u6536\u5de5\u3002<\/div>\n<\/div>\n<\/div>\n<div><\/div>\n<div>\u6e38\u620fgithunb\u5730\u5740 :\u00a0\u00a0https:\/\/github.com\/894658027\/HTML5-Games\/tree\/master\/cocosCreator\/jump-jump\/jump<\/div>\n<div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u968f\u7740\u5fae\u4fe1\u5c0f\u6e38\u620f\uff08\u8df3\u4e00\u8df3\uff09\u7684\u51fa\u73b0\u4e00\u4e0b\u5b50\u706b\u4e86\u8d77\u6765\uff0c\u542c\u8bf4\u8bd5\u73a9\u7528\u6237\u5df2\u7ecf\u8d85\u8fc7\u4e861.7\u4ebf\u5927\u5173\uff0c\u8fd9\u662f\u8981\u641e\u4e8b\u60c5\u554a\uff01\u6211\u6709\u9884\u611f\uff0c\u968f [&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\/391"}],"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=391"}],"version-history":[{"count":8,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts\/391\/revisions"}],"predecessor-version":[{"id":823,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts\/391\/revisions\/823"}],"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=391"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=391"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=391"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}