<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>animateCC &#8211; 萧邦的博客</title>
	<atom:link href="https://www.zlhlab.top/tag/animatecc/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.zlhlab.top</link>
	<description>If not me who, If not now when</description>
	<lastBuildDate>Wed, 24 Jan 2018 06:46:06 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.6</generator>
	<item>
		<title>createjs stagegl与animateCC协作</title>
		<link>https://www.zlhlab.top/createjs-stagegl%e4%b8%8eanimatecc%e5%8d%8f%e4%bd%9c/</link>
		
		<dc:creator><![CDATA[萧邦]]></dc:creator>
		<pubDate>Fri, 19 Jan 2018 15:19:28 +0000</pubDate>
				<category><![CDATA[技术]]></category>
		<category><![CDATA[animateCC]]></category>
		<category><![CDATA[createjs]]></category>
		<category><![CDATA[stagegl]]></category>
		<guid isPermaLink="false">https://www.zlhlab.top/?p=507</guid>

					<description><![CDATA[最近在完成一个H5互动游戏采用与AnimateCC协作。由于Animate CC2017导出的createjs库默认是2015版的，里面的整个场景使用的stage。]]></description>
										<content:encoded><![CDATA[<p>最近在完成一个H5互动游戏采用与AnimateCC协作。由于Animate CC2017导出的createjs库默认是2015版的，里面的整个场景使用的stage。</p>
<p>基于这个版本做了初版本尝试，图片资源10M存在问题，iPhone6上只能达到的帧率 6 fps左右。加入手指点击之后，整体性能更差了。性能方面是一个很严重的问题。</p>
<p>于是下面开启了 stagegl 性能优化之路。</p>
<h4>1. 下载createjs各关联库</h4>
<p><code>CreateJS</code> 实际是由<code>easeljs.js</code>、<code>soundjs.js</code>、<code>preloadjs.js``和tweenjs.js</code> 4个部分组成。</p>
<p>Animate CC2017导出的createjs库默认是2015版的。引用的库文件改为 引用git地址中的4个库文件，即可支持stagegl。</p>
<blockquote><p>
  git 地址：<a href="https://github.com/CreateJS" title="https://github.com/CreateJS" target="_blank">https://github.com/CreateJS</a>
</p></blockquote>
<h4>2. 修改代码支持stagegl</h4>
<p>导出原始代码：</p>
<pre class="line-numbers prism-highlight" data-start="1"><code class="language-javascript">// Regular 2d Canvas content
var stage = new createjs.Stage("canvasId");
</code></pre>
<p>代码修改后：</p>
<pre class="line-numbers prism-highlight" data-start="1"><code class="language-javascript">// StageGL Canvas content
var stage = new createjs.StageGL("canvasId");
</code></pre>
<h4>1.  使用预加载</h4>
<p>默认到处会使用预加载，如下：</p>
<pre class="line-numbers prism-highlight" data-start="1"><code class="language-javascript">var loader = new createjs.LoadQueue(false);
loader.installPlugin(createjs.Sound);
loader.addEventListener("fileload", handleFileLoad);
loader.addEventListener("progress",loadProgressHandler);
loader.addEventListener("complete", handleComplete);
loader.loadManifest(lib.properties.manifest);
</code></pre>
<p>可以在manifest中追加预加载素材。在 <code>loadProgressHandler</code>中针对进度进行进度条展示。</p>
<h4>4. 增加音效</h4>
<p>音效的使用，如下：</p>
<h5>1、 首先进行音频文件加载和绑定：</h5>
<pre class="line-numbers prism-highlight" data-start="1"><code class="language-javascript">createjs.Sound.alternateExtensions = ["mp3"];
createjs.Sound.registerSound('src/carstart.mp3', 'carstart');
createjs.Sound.registerSound('src/carmove.mp3', 'carmove');
</code></pre>
<h5>2、 进行音效播放</h5>
<pre class="line-numbers prism-highlight" data-start="1"><code class="language-javascript">createjs.Sound.paused = false;
createjs.Sound.play('carmove', {loop: -1});
</code></pre>
<h5>3、音效的停止</h5>
<pre class="line-numbers prism-highlight" data-start="1"><code class="language-javascript">createjs.Sound.stop();
createjs.Sound.paused = true;
</code></pre>
<h4>5. 屏幕与位置适配</h4>
<p>An默认到处的是左上角作为坐标原点。移动端使用，需要针对设备像素进行比例缩放。以下是以全屏进行等比缩放，超出宽度进行向左偏移居中。</p>
<pre class="line-numbers prism-highlight" data-start="1"><code class="language-javascript">stage.updateViewport &amp;&amp; stage.updateViewport(750, 1206);
stage.addChild(exportRoot);
stage.enableDOMEvents(false);
</code></pre>
<p>宽高以最大比例缩放，超出宽度向左偏移：</p>
<pre class="line-numbers prism-highlight" data-start="1"><code class="language-javascript">lastW = iw; lastH = ih; lastS = sRatio;
var maxScale = Math.max( yRatio, xRatio);
anim_container.style.transform = 'scale(' + maxScale +')';
anim_container.style.webkitTransform = 'scale(' + maxScale +')';
anim_container.style.marginLeft = - (maxScale * 750 - iw)/ 2 + 'px';
</code></pre>
<h4>6. 其他优化</h4>
<blockquote>
<ol>
<li>Animate CC发布设置，jpg与png图片分开导出，限制每张精灵图最大尺寸 2048 x 2018;</li>
<li>使用TingPng 进行图片压缩；</li>
<li>强烈建议使用 stagegl 替代 stage；</li>
<li>其他优化，建议查看官网、官方博客或者ajex中文博客。</li>
</ol>
</blockquote>
<p>优化之后整体游戏可以达到 40fps+，手势点击事件也不影响游戏性能了。整体状况ok。</p>
<p>Animate CC2018 出来了，有时间再摸索一下新特性。</p>
<h4>文章参考地址如下：</h4>
<ul>
<li>createjs官网：<a href="https://createjs.com/" title="https://createjs.com/" target="_blank">https://createjs.com/</a></li>
<li>createks官方博客：<a href="http://blog.createjs.com/getting-started-with-stagegl/" title="http://blog.createjs.com/getting-started-with-stagegl/" target="_blank">http://blog.createjs.com/getting-started-with-stagegl/</a></li>
<li>ajex中文博客：<a href="http://www.ajexoop.com/wordpress/" title="http://www.ajexoop.com/wordpress/" target="_blank">http://www.ajexoop.com/wordpress/</a></li>
</ul>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
