<?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>stagegl &#8211; 萧邦的博客</title>
	<atom:link href="https://www.zlhlab.top/tag/stagegl/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.zlhlab.top</link>
	<description>If not me who, If not now when</description>
	<lastBuildDate>Thu, 22 Feb 2018 13:03:39 +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>
		<item>
		<title>加速动力火车  驶向新年大奖</title>
		<link>https://www.zlhlab.top/animate-cc%e4%b8%8ecreatejs-stagegl%e8%bf%9b%e8%a1%8ch5%e5%b0%8f%e6%b8%b8%e6%88%8f%e5%bc%80%e5%8f%91/</link>
		
		<dc:creator><![CDATA[萧邦]]></dc:creator>
		<pubDate>Thu, 18 Jan 2018 09:02:53 +0000</pubDate>
				<category><![CDATA[H5]]></category>
		<category><![CDATA[stagegl]]></category>
		<guid isPermaLink="false">https://www.zlhlab.top/?p=509</guid>

					<description><![CDATA[2018我们再度前行，iPhone X等你拿~]]></description>
										<content:encoded><![CDATA[<h4>项目背景：</h4>
<p>这个项目是个丰田金融做的第三期互动H5活动。H5采用小狗+火车为第一人称视角的小游戏。由于偏向伪3d，进行技术可行性分析，有以下两种方案实现方案：</p>
<p>方案一： 可以采用<code>three.js</code>库文件，进行给场景动态增加元素、维护游戏场景；<br />
方案二： 使用Animate CC的<code>createjs</code>库制作H5，后面增加点击，根据点击数动态修改帧率进行场景切换。</p>
<p>确认的设计稿整体偏卡通风格，项目设计和制作时间很紧张，所以采用了第二套方案。</p>
<h4>项目技术点</h4>
<p>项目关键点在于性能优化，主要优化方向：</p>
<blockquote><p>
  1、压缩项目资源文件，初次资源文件达到 10M+ &#8211;&gt; 进行CC导出jpg、png分离，以及tingPng进行图片压缩，整体资源文件 1.3M；<br />
  2、修改默认导出的stage，进行支持stagegl GPU渲染。
</p></blockquote>
<p>其他主要功能包括如下：</p>
<blockquote><p>
  1、微信授权；<br />
  2、雪花动效、场景微动效等；<br />
  3、font-spider实现字体压缩；<br />
  4、点击数、里程数、时钟、游戏音效等游戏控制管理；<br />
  4、游戏排行榜功能；<br />
  5、留资抽奖功能。
</p></blockquote>
<h4>项目设计</h4>
<p><img decoding="async" src="https://www.zlhlab.top/wp-content/uploads/2018/01/%E4%B8%B0%E7%94%B0%E9%87%91%E8%9E%8D3%E6%9C%9F%E7%81%AB%E8%BD%A6.jpg" alt=""></p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
