{"id":411,"date":"2018-04-02T14:13:32","date_gmt":"2018-04-02T06:13:32","guid":{"rendered":"http:\/\/blog.xrhoujie.com\/?p=411"},"modified":"2018-04-08T15:58:36","modified_gmt":"2018-04-08T07:58:36","slug":"create-js%e7%a7%bb%e5%8a%a8%e4%b8%8epc%e9%80%82%e9%85%8d%e5%85%bc%e5%ae%b9%e6%80%a7%e5%a4%84%e7%90%86","status":"publish","type":"post","link":"http:\/\/blog.xrhoujie.com\/?p=411","title":{"rendered":"Create.js\u79fb\u52a8\u4e0ePC\u9002\u914d\u517c\u5bb9\u6027\u5904\u7406"},"content":{"rendered":"<p>\u5927\u5bb6\u597d\uff0c\u4eca\u5929\u8ddf\u5927\u5bb6\u5206\u4eab\u4e00\u4e0b \u5728\u6211\u4eeccreate.js\u4e2d\u5173\u4e8e\u5404\u79cd\u5206\u8fa8\u7387\u8bbe\u5907\u7684\u5168\u5c4f\u9002\u914d\u662f\u5982\u4f55\u5904\u7406\u7684\uff0c\u6b63\u5982\u5927\u5bb6\u6240\u77e5\u9053\u7684\u90a3\u6837\uff0ch5\u6e38\u620f\u672c\u8eab\u5bf9\u4e8e\u517c\u5bb9\u6027\u8fd9\u5757\u6bd4\u8f83\u5403\u529b\uff0c\u6240\u4ee5\u66f4\u52a0\u8003\u9a8c\u4e00\u4e2a\u524d\u7aef\u7684\u6280\u672f\u6808\u80fd\u529b\uff0c\u8bdd\u4e0d\u591a\u8bf4 \u65e5\u5e38\u914d\u56fe<\/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>\u9996\u5148\u6211\u4eec\u65b0\u5efa\u4e00\u4e2ahtml\u6587\u4ef6\uff0c\u5f15\u5165createjs\u7684cdn\u5e93\uff0c<\/p>\n<p>\u6bd4\u5982\u8fd9\u6837<\/p>\n<div>\n<div>&lt;!DOCTYPE html&gt;<\/div>\n<div>&lt;html&gt;<\/div>\n<div>&lt;head&gt;<\/div>\n<div>&lt;metacharset=&#8221;utf-8&#8243;&gt;<\/div>\n<div>&lt;linkrel=&#8221;stylesheet&#8221;href=&#8221;css\/base.css&#8221;&gt;<\/div>\n<div>&lt;metaname=&#8221;viewport&#8221;content=&#8221;width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no&#8221;\/&gt;<\/div>\n<div><\/div>\n<div>\/\/ create.js engine<\/div>\n<div>&lt;scriptsrc=&#8221;https:\/\/code.createjs.com\/createjs-2015.11.26.min.js&#8221;&gt;&lt;\/script&gt;<\/div>\n<div><\/div>\n<\/div>\n<div>\n<div>&lt;style&gt;<\/div>\n<div><\/div>\n<div>canvas#myCanvas {<\/div>\n<div>display: block;<\/div>\n<div>position: absolute;<\/div>\n<div>top: 0;<\/div>\n<div>left: 0;<\/div>\n<div>width: 100%;<\/div>\n<div>height: 100%;<\/div>\n<div>}<\/div>\n<div><\/div>\n<div>&lt;\/style&gt;<\/div>\n<div>&lt;\/head&gt;<\/div>\n<div>&lt;body&gt;<\/div>\n<div><\/div>\n<div>&lt;canvas id=&#8221;myCanvas&#8221; width=&#8221;960&#8243; height=&#8221;540&#8243;&gt;&lt;\/canvas&gt;<\/div>\n<div><\/div>\n<div>&lt;\/body&gt;<\/div>\n<div>&lt;\/html&gt;<\/div>\n<\/div>\n<div><\/div>\n<div>ok\u554a\uff0c\u524d\u671f\u51c6\u5907\u5de5\u4f5c\u6211\u4eec\u5df2\u7ecf\u51c6\u5907\u597d\u4e86 \u73b0\u5728 \u6211\u4eec\u5f00\u59cb\u7801\u4ee3\u7801\uff0c<\/div>\n<div><\/div>\n<div>\u9996\u5148\u6211\u4eec\u5148\u5b9a\u4e49\u4e00\u4e2a\u5165\u53e3\u6587\u4ef6<\/div>\n<div><\/div>\n<div>\n<div>\n<div>window.addEventListener(&#8220;load&#8221;, init); \/\/\u76d1\u542cload\u52a0\u8f7d\u5b8c\u6210\u540e\u56de\u8c03\u51fd\u6570 init\uff0c\u8fdb\u884c\u6e38\u620f\u521d\u59cb\u5316\uff0c<\/div>\n<\/div>\n<div>\n<div>\n<div>function init() {<\/div>\n<div>var stage=new createjs.Stage(&#8220;myCanvas&#8221;);\u00a0 \u00a0\/\/\u628a\u821e\u53f0\u6dfb\u52a0\u5230canvas\u753b\u5e03\u4e0a<\/div>\n<div>if (createjs.Touch.isSupported() ==true) {<\/div>\n<div>createjs.Touch.enable(stage)\u00a0 \u00a0 \u00a0 \/\/\u821e\u53f0\u4e0a\u5f00\u542f\u70b9\u51fb\u4e8b\u4ef6\uff08\u517c\u5bb9\u79fb\u52a8\u7aef\u5904\u7406\uff09<\/div>\n<div>}<\/div>\n<div>\n<div>\n<div>window.addEventListener(&#8220;resize&#8221;, handleResize); \/\/ \u68c0\u6d4b\u8bbe\u5907\u8c03\u6574\u4e0e\u53d8\u5316 \u56de\u8c03handleResize\u51fd\u6570\uff0c<\/div>\n<div>\n<div>\n<div>handleResize();<\/div>\n<div>function handleResize(event) {<\/div>\n<div>var w=window.innerWidth;\u00a0 \/\/\u8bbe\u5907\u7a97\u53e3\u5bbd\u5ea6<\/div>\n<div>var h=window.innerHeight;\u00a0\u00a0\/\/\u8bbe\u5907\u7a97\u53e3\u9ad8\u5ea6<\/div>\n<div>stage.canvas.width = w;\u00a0\u00a0\/\/\u821e\u53f0\u5bbd\u5ea6\u7b49\u4e8e\u8bbe\u5907\u5bbd\u5ea6<\/div>\n<div>stage.canvas.height = h; \/\/\u821e\u53f0\u9ad8\u5ea6\u7b49\u4e8e\u8bbe\u5907\u9ad8\u5ea6<\/div>\n<div>\/\/ \u753b\u9762\u66f4\u65b0<\/div>\n<div>stage.update();\u00a0 \u00a0\/\/\u821e\u53f0\u8fdb\u884c\u66f4\u65b0\u6e32\u67d3<\/div>\n<div>}<\/div>\n<div>\u4e3a\u4e86\u80fd\u8ba9\u6548\u679c\u66f4\u52a0\u76f4\u89c2\u6211\u4eec\u505a\u4e86\u4e00\u4e2a\u5706\u5f62 \u8ba9\u4ed6\u4e0d\u65ad\u7684\u8fdb\u884cx+ = 30 \uff0cy + = 5\u8fd0\u52a8\uff0c<\/div>\n<div>\n<div>\n<div>var shape = new createjs.Shape();\u00a0 \/\/ \u521b\u5efa\u56fe\u5f62\u5bb9\u5668<\/div>\n<div>shape.graphics.beginFill(&#8220;DarkGreen&#8221;).drawCircle(0, 0, 80);\u00a0 \/\/\u7ed8\u5236\u5706\u5f62\uff0c\u989c\u8272<\/div>\n<div>stage.addChild(shape);\u00a0 \/\/\u56fe\u5f62\u6dfb\u52a0\u5230\u821e\u53f0\u4e0a<\/div>\n<div>createjs.Ticker.addEventListener(&#8220;tick&#8221;, handleTick);<\/div>\n<div><\/div>\n<div>\/\/\u5fc3\u8df3 == requireAnimationFrame<\/div>\n<div><\/div>\n<div>function handleTick(event) {<\/div>\n<div>shape.x+=30;\u00a0 \u00a0\/\/\u6bcf\u79d2\u949fx+30<\/div>\n<div>shape.y+=5;\u00a0 \u00a0 \/\/\u6bcf\u79d2\u949fx+5<\/div>\n<div>if (shape.x&gt;window.innerWidth) shape.x=0;\u00a0 \u00a0\/\/\u5982\u679c\u56fe\u5f62\u8d85\u51fa\u5c4f\u5e55\u5bbd\u5ea6 \u56de\u52300<\/div>\n<div>if (shape.y&gt;window.innerHeight) shape.y=0; \/\/\u5982\u679c\u56fe\u5f62\u8d85\u51fa\u5c4f\u5e55\u9ad8\u5ea6 \u56de\u52300<\/div>\n<div>stage.update();\u00a0 \/\/\u66f4\u65b0\u821e\u53f0<\/div>\n<div>}<\/div>\n<div>}<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div>\u60f3\u770b\u6548\u679c\u7684 \u8bf7\u72e0\u72e0\u7684\u70b9\u51fbdemo\u5730\u5740 \uff1a\u00a0https:\/\/github.com\/894658027\/HTML5-Games\/tree\/master\/CreateJs\/Create.js%E9%80%9A%E7%94%A8%E7%BB%84%E5%BB%BA\/%E5%85%A8%E5%B1%8F%E9%80%82%E9%85%8D<\/div>\n<\/div>\n<div><\/div>\n<div>\u53c8\u662f\u4ee3\u7801\u6ee1\u6ee1\u7684\u4e00\u5929\uff0c\u4e0b\u5468\u89c1 \u62dc\u62dc~<\/div>\n<div><\/div>\n<div>github\u6548\u679c\u5730\u5740 \uff1ahttps:\/\/github.com\/894658027\/HTML5-Games\/tree\/master\/CreateJs\/template\/adapterScreen<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u5927\u5bb6\u597d\uff0c\u4eca\u5929\u8ddf\u5927\u5bb6\u5206\u4eab\u4e00\u4e0b \u5728\u6211\u4eeccreate.js\u4e2d\u5173\u4e8e\u5404\u79cd\u5206\u8fa8\u7387\u8bbe\u5907\u7684\u5168\u5c4f\u9002\u914d\u662f\u5982\u4f55\u5904\u7406\u7684\uff0c\u6b63\u5982\u5927\u5bb6\u6240\u77e5\u9053 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":179,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[27],"_links":{"self":[{"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts\/411"}],"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=411"}],"version-history":[{"count":3,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts\/411\/revisions"}],"predecessor-version":[{"id":425,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts\/411\/revisions\/425"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/media\/179"}],"wp:attachment":[{"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=411"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=411"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=411"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}