setInitialState();
main(performance.now()); //开始循环
-})();
+})();
+```
+
+另一个选择是简单地做一些事情不那么频繁。如果您的更新循环的一部分难以计算但对时间不敏感,则可以考虑缩小其频率,理想情况下,在延长的时间段内将其扩展成块。这是一个隐含的例子,在火炮博物馆的炮兵游戏中,他们[调整垃圾发生率](http://blog.artillery.com/2012/10/browser-garbage-collection-and-framerate.html)来优化垃圾收集。显然,清理资源不是时间敏感的(特别是如果整理比垃圾本身更具破坏性)。
+
+这也可能适用于您自己的一些任务。那些是当可用资源成为关注点时的好候选人。
+
+## 概要
+
+我知道上述的任何一种,或许没有适合你的游戏。正确的决定完全取决于你愿意(和不愿意)做出的权衡。主要关心的是切换到另一个选项。幸运的是,我没有任何经验,但我听说这是一个令人难以置信的游戏的 Whack-a-Mole。
-另一个选择是简单地做一些事情不那么频繁。如果您的更新循环的一部分难以计算但对时间不敏感,则可以考虑缩小其频率,理想情况下,在延长的时间段内将其扩展成块。这是一个隐含的例子,在火炮博物馆的炮兵游戏中,他们调整垃圾发生率来优化垃圾收集。显然,清理资源不是时间敏感的(特别是如果整理比垃圾本身更具破坏性)。
+像 Web 这样的受管理平台,要记住的一件重要的事情是,您的循环可能会在相当长的一段时间内停止执行。当用户取消选择您的标签并且浏览器休眠(或减慢)其`requestAnimationFrame`回调间隔时,可能会发生这种情况。你有很多方法来处理这种情况,这可能取决于你的游戏是单人游戏还是多人游戏。一些选择是:
-这也可能适用于您自己的一些任务。那些是当可用资源成为关注点时的好候选人。
+- 考虑差距“暂停”并跳过时间。
-概要
+ - 你可能会看到这对大多数多人游戏来说都是有问题的。
-我知道上述的任何一种,或许没有适合你的游戏。正确的决定完全取决于你愿意(和不愿意)做出的权衡。主要关心的是切换到另一个选项。幸运的是,我没有任何经验,但我听说这是一个令人难以置信的游戏的 Whack-a-Mole。
+- 你可以模拟差距赶上。
-像 Web 这样的受管理平台,要记住的一件重要的事情是,您的循环可能会在相当长的一段时间内停止执行。当用户取消选择您的标签并且浏览器休眠(或减慢)其requestAnimationFrame
回调间隔时,可能会发生这种情况。你有很多方法来处理这种情况,这可能取决于你的游戏是单人游戏还是多人游戏。一些选择是:
+ - 这可能是长时间丢失和/或复杂更新的问题。
-
- - 考虑差距“暂停”并跳过时间。
+- 您可以从联机设备或服务器恢复游戏状态。
-
- - 你可能会看到这对大多数多人游戏来说都是有问题的。
-
-
- - 你可以模拟差距赶上。
-
-
- - 您可以从联机设备或服务器恢复游戏状态。
-
- - 除非联机设备/服务器的游戏状态已经过期,或者这是一个没有没服务器的纯单机游戏。
-
-
-
+ - 除非联机设备/服务器的游戏状态已经过期,或者这是一个没有没服务器的纯单机游戏。
-一旦你的主循环被开发出来,你已经决定了一套适合你的游戏的假设和权衡,现在只需要用你的决定来计算任何适用的物理,AI,声音,网络同步,以及你游戏可能需要。
+一旦你的主循环被开发出来,你已经决定了一套适合你的游戏的假设和权衡,现在只需要用你的决定来计算任何适用的物理,AI,声音,网络同步,以及你游戏可能需要。
diff --git a/files/zh-cn/games/examples/index.md b/files/zh-cn/games/examples/index.md
index c12429037b2862..3d9c7d74841dac 100644
--- a/files/zh-cn/games/examples/index.md
+++ b/files/zh-cn/games/examples/index.md
@@ -5,113 +5,107 @@ tags:
- 游戏
translation_of: Games/Examples
---
-{{GamesSidebar}}
+{{GamesSidebar}}
-这个页面列出了许多令人印象深刻的 web 技术演示,你可以从中获得灵感和乐趣。这里证明了可以利用 JavaScript,WebGL 和相关的技术做些什么。前两个部分列出了可以玩的游戏,其中在第二个部分中列出的演示不一定是可交互的或是游戏。
+这个页面列出了许多令人印象深刻的 web 技术演示,你可以从中获得灵感和乐趣。这里证明了可以利用 JavaScript,WebGL 和相关的技术做些什么。前两个部分列出了可以玩的游戏,其中在第二个部分中列出的演示不一定是可交互的或是游戏。
-免费/演示游戏
+## 免费/演示游戏
-
- - Beloola
- - 一个连接充满激情的人们的网络虚拟现实(WebVR)平台。可以同时在 2D 屏幕和虚拟现实头盔显示器(设置/转为 VR 模式)上体验。
- - Tanx
- - 一个多人坦克对战游戏,由PlayCanvas开发。
- - Hyper Vanguard Force
- - 一个优雅的纵向卷轴太空射击游戏。
- - Swooop
- - 一个飞行游戏:控制你的飞机并收集宝石。也是由PlayCanvas所开发。
- - Save the Day
- - 在受灾区域驾驶你的救援直升机以拯救被困的受灾者(ga.me.)。
- - Polycraft
- - 一个海难生存游戏。探索岛屿、打败怪物。
- - HexGL
- - 一个快节奏、未来主义的赛车游戏。
- - Dead Trigger 2
- - 经典的僵尸溅射游戏,使用Unity3D开发。
- - Angry Bots
- - 一个未来风格的外星人式的第三人称射击游戏,使用Unity3D开发。
- - Nutmeg
- - 可爱的复古卷轴平台动作游戏。
- - Back to Candyland
- - 一个 match-3(Candy Crush)风格的游戏。
- - Biolab Disaster
- - 横向卷轴平台射击游戏。
- - X-Type
- - 纵向卷轴太空射击游戏演示。
- - Xibalba
- - 复古(Doom 风格)的第一人称射击游戏。
- - Gorescript
- - 另一个复古风格的第一人称射击游戏。
- - The Wizard
- - 一个回合制的地下城解谜游戏。
- - Hextris
- - 类似于俄罗斯方块的六边形解谜游戏。
- - 2048
- - 一个滑动数字方块的解谜游戏。
- - BananaBread
- - 多玩家的 3D 第一人称射击游戏,使用 Emscripten,WebGL 和 WebRTC 开发。
- - Monster Madness
- - 一个基于 WebGL 和 asm.js 的多人在线射击游戏,由 Nom Nom Games 和 Trendy entertainment 开发。
- - Auralux
- - 基于 WebGL 和 asm.js 的策略游戏:捕获所有的太阳以获取胜利!
- - BrowserQuest
- - 由 Little Workshop 和 Mozilla 开发的 MMORPG。
-
+- [Beloola](http://www.beloola.com)
+ - : 一个连接充满激情的人们的网络虚拟现实(WebVR)平台。可以同时在 2D 屏幕和虚拟现实头盔显示器(设置/转为 VR 模式)上体验。
+- [Tanx](http://playcanv.as/p/aP0oxhUr)
+ - : 一个多人坦克对战游戏,由[PlayCanvas](https://playcanvas.com/)开发。
+- [Hyper Vanguard Force](https://robertsspaceindustries.com/comm-link/transmission/14704-Hyper-Vanguard-Force)
+ - : 一个优雅的纵向卷轴太空射击游戏。
+- [Swooop](http://playcanv.as/p/JtL2iqIH)
+ - : 一个飞行游戏:控制你的飞机并收集宝石。也是由[PlayCanvas](https://playcanvas.com/)所开发。
+- [Save the Day](https://ga.me/games/save-the-day)
+ - : 在受灾区域驾驶你的救援直升机以拯救被困的受灾者(ga.me.)。
+- [Polycraft](https://ga.me/games/polycraft)
+ - : 一个海难生存游戏。探索岛屿、打败怪物。
+- [HexGL](http://hexgl.bkcore.com/)
+ - : 一个快节奏、未来主义的赛车游戏。
+- [Dead Trigger 2](http://beta.unity3d.com/jonas/DT2/)
+ - : 经典的僵尸溅射游戏,使用[Unity3D](http://unity3d.com/)开发。
+- [Angry Bots](http://beta.unity3d.com/jonas/AngryBots/)
+ - : 一个未来风格的外星人式的第三人称射击游戏,使用[Unity3D](http://unity3d.com/)开发。
+- [Nutmeg](http://sandbox.photonstorm.com/html5/nutmeg/)
+ - : 可爱的复古卷轴平台动作游戏。
+- [Back to Candyland](http://www.zibbo.com/game/match-3-games-top/back-to-candyland-episode-1)
+ - : 一个 match-3(Candy Crush)风格的游戏。
+- [Biolab Disaster](http://playbiolab.com/)
+ - : 横向卷轴平台射击游戏。
+- [X-Type](http://phoboslab.org/xtype/)
+ - : 纵向卷轴太空射击游戏演示。
+- [Xibalba](http://phoboslab.org/xibalba/)
+ - : 复古(Doom 风格)的第一人称射击游戏。
+- [Gorescript](https://timeinvariant.github.io/gorescript/play/)
+ - : 另一个复古风格的第一人称射击游戏。
+- [The Wizard](http://hypnoticowl.com/games/the-wizard/)
+ - : 一个回合制的地下城解谜游戏。
+- [Hextris](http://hextris.io/)
+ - : 类似于俄罗斯方块的六边形解谜游戏。
+- [2048](https://gabrielecirulli.github.io/2048/)
+ - : 一个滑动数字方块的解谜游戏。
+- [BananaBread](/en-US/demos/detail/bananabread)
+ - : 多玩家的 3D 第一人称射击游戏,使用 Emscripten,WebGL 和 WebRTC 开发。
+- [Monster Madness](https://hacks.mozilla.org/2013/12/monster-madness-creating-games-on-the-web-with-emscripten/)
+ - : 一个基于 WebGL 和 asm.js 的多人在线射击游戏,由 Nom Nom Games 和 Trendy entertainment 开发。
+- [Auralux](http://www.auraluxgame.com/game/)
+ - : 基于 WebGL 和 asm.js 的策略游戏:捕获所有的太阳以获取胜利!
+- [BrowserQuest](http://browserquest.mozilla.org/)
+ - : 由 Little Workshop 和 Mozilla 开发的 MMORPG。
-商业游戏
+## 商业游戏
-
- - Oort Online
- - 一个大型多人网游:在游戏中探索、建造和战斗(目前仍在开发中)。
- - A Wizard's Lizard
- - 自上而下的塞尔达式的探索/RPG游戏。
- - QbQbQb
- - 一个科幻主题的解谜游戏。
- - Elliot Quest
- - 复古的 8-bit 画面风格冒险游戏。
-
+- [Oort Online](http://oortonline.com/)
+ - : 一个大型多人网游:在游戏中探索、建造和战斗(目前仍在开发中)。
+- [A Wizard's Lizard](http://www.wizardslizard.com/)
+ - : 自上而下的塞尔达式的探索/RPG 游戏。
+- [QbQbQb](http://qbqbqb.rezoner.net/)
+ - : 一个科幻主题的解谜游戏。
+- [Elliot Quest](http://elliotquest.com/)
+ - : 复古的 8-bit 画面风格冒险游戏。
-混合演示
+## 混合演示
-
- - WaveGL
- - 音频资源的 WebGL 可视化展示。
- - Canvas Airport Simulation
- - 可以显示飞机在机场起飞和降落的地图动画,也可以显示航线。
- - Animation Physics
- - 地形和汽车的 3D 渲染,其中的物理计算使用了ammo.js 。
- - Volumetric Particle Flow
- - 流体的物理模拟。
- - Explosion and chain reaction
- - 会引发更多爆炸的爆炸粒子。
- - Canvas generated planet
- - 一个具有小行星带的星球。
- - Digital Fireworks
- - 在 canvas 上渲染出的焰火动画效果。
- - Autumn
- - 秋叶飘落,光源在其后闪烁。使用Three.js开发。
- - Fire walk with me
- - 翻腾的火云效果。
- - Rainbow Firestorm
- - 下雨般的七彩粒子,在由圆组成的地形上跳跃。
- - Crowd Simulation
- - 模拟想到达他们相反方向的拥挤人群。
- - SVG Masking Experiment
- - 一台 X 光机,由 SVG 蒙版创建。
- - Realistic Water Simulation
- - 如海浪的流水。
- - Dungeon demo
- - 基于 Haxor 的地下城场景,拥有可行走的人物。
- - Massive Assault tech demo
- - 渲染出的具有未来派的军用车辆的群岛。
- - Flight Stream
- - 具有模拟航线的 3D 球体。
- - WebGL filters
- - 用于向 HTML 元素添加效果的 WebGL 过滤器演示。
- - SVG isometic tiles
- - Generating isometric tiles with SVG matricies.
- - ThreeJS App Player
- - 你可以在其中载入和运行 Three.js 的示例。
- - WebGL + Three.js Demo
- - 警告:可能造成眩晕。
-
+- [WaveGL](http://greweb.me/wavegl/)
+ - : 音频资源的 WebGL 可视化展示。
+- [Canvas Airport Simulation](http://codepen.io/jackrugile/pen/CdKGx/)
+ - : 可以显示飞机在机场起飞和降落的地图动画,也可以显示航线。
+- [Animation Physics](http://alteredqualia.com/xg/examples/animation_physics_terrain.html)
+ - : 地形和汽车的 3D 渲染,其中的物理计算使用了[ammo.js](https://github.com/kripken/ammo.js) 。
+- [Volumetric Particle Flow](http://david.li/flow/)
+ - : 流体的物理模拟。
+- [Explosion and chain reaction](http://codepen.io/artzub/pen/gszpJ/)
+ - : 会引发更多爆炸的爆炸粒子。
+- [Canvas generated planet](http://codepen.io/AshKyd/pen/sylFw)
+ - : 一个具有小行星带的星球。
+- [Digital Fireworks](http://codepen.io/zadvorsky/pen/FAmuL)
+ - : 在 canvas 上渲染出的焰火动画效果。
+- [Autumn](http://oos.moxiecode.com/js_webgl/autumn/)
+ - : 秋叶飘落,光源在其后闪烁。使用[Three.js](https://github.com/mrdoob/three.js)开发。
+- [Fire walk with me](http://inear.se/fireshader/)
+ - : 翻腾的火云效果。
+- [Rainbow Firestorm](http://codepen.io/jackrugile/pen/AokpF)
+ - : 下雨般的七彩粒子,在由圆组成的地形上跳跃。
+- [Crowd Simulation](http://visualiser.fr/babylon/crowd/)
+ - : 模拟想到达他们相反方向的拥挤人群。
+- [SVG Masking Experiment](http://codepen.io/noeldelgado/pen/ByxQjL)
+ - : 一台 X 光机,由 SVG 蒙版创建。
+- [Realistic Water Simulation](https://www.shadertoy.com/view/Ms2SD1)
+ - : 如海浪的流水。
+- [Dungeon demo](http://www.haxor.xyz/demos/1.0/dungeon/)
+ - : 基于 Haxor 的地下城场景,拥有可行走的人物。
+- [Massive Assault tech demo](http://massiveassaultnetwork.com/html5/)
+ - : 渲染出的具有未来派的军用车辆的群岛。
+- [Flight Stream](https://callumprentice.github.io/apps/flight_stream/index.html)
+ - : 具有模拟航线的 3D 球体。
+- [WebGL filters](http://pixelscommander.com/polygon/htmlgl/demo/filters.html)
+ - : 用于向 HTML 元素添加效果的 WebGL 过滤器演示。
+- [SVG isometic tiles](http://codepen.io/AshKyd/pen/zxmgzV)
+ - : Generating isometric tiles with SVG matricies.
+- [ThreeJS App Player](https://jsfiddle.net/jetienne/rkth90c9/)
+ - : 你可以在其中载入和运行 Three.js 的示例。
+- [WebGL + Three.js Demo](/en-US/demos/detail/escher-puzzle/launch)
+ - : 警告:可能造成眩晕。
diff --git a/files/zh-cn/games/index.md b/files/zh-cn/games/index.md
index 8521cd5d06ebca..18637d4eafba41 100644
--- a/files/zh-cn/games/index.md
+++ b/files/zh-cn/games/index.md
@@ -12,72 +12,66 @@ tags:
- Web
translation_of: Games
---
-{{GamesSidebar}}
-
-游戏是在计算机上最风靡的活动之一。新技术不断发展已使开发出能在任何符合标准的浏览器上运行更好更炫的游戏成为可能。
-
-{{EmbedGHLiveSample("web-tech-games/index.html", '100%', 820)}}
-
-开发网页游戏
-
-欢迎来到 MDN 游戏开发中心!在网站的这个模块我们为想要开发游戏的 web 开发者提供了资源。你可以在主菜单的左边找到很多有用的教程和技术文档,放轻松去探索吧。
-
-我们同样包含了参考书库,因此你可以轻易的找到有关游戏开发所有常用的 API 以及有用的引擎和工具清单和游戏案例.
-
-
-
备注: 在你开始尝试创建一个网页游戏之前你至少要掌握基础的核心 web 技术 —— 例如 HTML、CSS 和 Javascript。如果你是一个完全的初学者, 这里 将会是一个很好的学习领域。
-
-
-将本地游戏移植到 Web
-
-如果你是一个本地游戏开发者 (例如你用 C++开发游戏),并且你对如何将本地游戏移植到 Web 感兴趣,你应该更多的学习关于我们的Emscripten 工具—— 这是一个 LLVM JavaScript 编译器。它能获取 LLVM 字节码 (例如用 Clang 编译 C/C++或者其他语言生成的字节码)并且将它们编译成asm.js以在 Web 上运行。
-
-开始,查看以下:
-
-
-
-示例
-
-有关网页游戏示例的列表,请参阅我们的示例页。也可以查看 openwebgames.com 以获得更多有用的资源和示例!
-
-参见
-
-
- - Build New Games
- - 这是一个以大量开放式网页游戏开发教程为特色的协作网站。最近还不是很活跃,但还是拥有一些不错的资源。
- - Creative JS
- - 一个令人印象深刻的 JavaScript 技术和实验的集合,并不全是游戏技术,但还是对开发有帮助。最近并不非常活跃,但仍然拥有一些不错的资源。
- - Game programming patterns
- - 在线书籍,作者 Bob Nystrom,其中讨论了游戏开发环境中的编程模式,旨在帮助游戏开发人员生成更有效,更高效的代码。
- - Artillery blog
- - HTML5 游戏公司 Artillery 在他们的博客上发表的一些有用的文章。
- - Building games for Firefox OS
- - 使用 HTML5 创建 2D 游戏的快速指南,针对在 Firefox OS 和其他移动平台上分发。
- - Gamedev.js Weekly
- - 关于 HTML5 游戏开发的每周新闻,每星期五发送。包含最新的文章,教程,工具和资源。
- - HTML5 Game Devs Forum
- - 开发者,架构师,发布者的论坛。提出问题,获得帮助,帮助他人。
-
-
-
- - HTML5 游戏引擎
- - 眼下最流行的 HTML5 游戏框架列表,包含评分,特色和案例。
- - JSBreakouts
- - 比较在不同的框架中的 JavaScript Breakout clones,以帮助您作出正确的选择。
- - Tuts 与游戏开发
- - 关于游戏开发的教程和案例。
- - #BBG IRC chat
- - 实时在线与开发者直接对话。
- - HTML5 Gamedev Starter
- - Starter 针对游戏开发新手,在网络上提供一个策划列表链接到各种,有用的资源。
- - js13kGames
- - 针对 HTML5 游戏开发人员的 JavaScript 编码竞赛,文件大小限制设置为 13 千字节。所有提交的游戏都以可读的形式在 GitHub 上提供。
- - Mozilla Hacks blog
- - 在 Mozilla Hacks 博客包含关于游戏类别的有趣的游戏开发的相关文章。
- - Visual-js game engine
- - 2d / 3d / webSocket 定向游戏引擎。只有 window 下的工具。托管在 bitbucket 项目网站。
-
+{{GamesSidebar}}
+
+游戏是在计算机上最风靡的活动之一。新技术不断发展已使开发出能在任何符合标准的浏览器上运行更好更炫的游戏成为可能。
+
+{{EmbedGHLiveSample("web-tech-games/index.html", '100%', 820)}}
+
+## 开发网页游戏
+
+欢迎来到 MDN 游戏开发中心!在网站的这个模块我们为想要开发游戏的 web 开发者提供了资源。你可以在主菜单的左边找到很多有用的教程和技术文档,放轻松去探索吧。
+
+我们同样包含了参考书库,因此你可以轻易的找到有关游戏开发所有常用的 API 以及有用的[引擎和工具](/zh-CN/docs/Games/Tools/Engines_and_tools)清单和[游戏案例](/zh-CN/docs/Games/Examples).
+
+> **备注:** 在你开始尝试创建一个网页游戏之前你至少要掌握基础的核心 web 技术 —— 例如 HTML、CSS 和 Javascript。如果你是一个完全的初学者, [这里](/zh-CN/docs/Learn) 将会是一个很好的学习领域。
+
+## 将本地游戏移植到 Web
+
+如果你是一个本地游戏开发者 (例如你用 C++开发游戏),并且你对如何将本地游戏移植到 Web 感兴趣,你应该更多的学习关于我们的[Emscripten](http://kripken.github.io/emscripten-site/index.html) 工具—— 这是一个 LLVM JavaScript 编译器。它能获取 LLVM 字节码 (例如用 Clang 编译 C/C++或者其他语言生成的字节码)并且将它们编译成[asm.js](/en-US/docs/Games/Tools/asm.js)以在 Web 上运行。
+
+开始,查看以下:
+
+- [关于 Emscripten](https://kripken.github.io/emscripten-site/docs/introducing_emscripten/about_emscripten.html)——简介和高级特性。
+- [下载和安装](https://kripken.github.io/emscripten-site/docs/getting_started/downloads.html)——安装工具链。
+- [Emscripten 教程](https://kripken.github.io/emscripten-site/docs/getting_started/Tutorial.html)——指导你如何开始。
+
+## 示例
+
+有关网页游戏示例的列表,请参阅我们的[示例页](/zh-CN/docs/Games/Examples)。也可以查看 [openwebgames.com](http://www.openwebgames.com/) 以获得更多有用的资源和示例!
+
+## 参见
+
+- [Build New Games](http://buildnewgames.com/)
+ - : 这是一个以大量开放式网页游戏开发教程为特色的协作网站。最近还不是很活跃,但还是拥有一些不错的资源。
+- [Creative JS](http://creativejs.com/)
+ - : 一个令人印象深刻的 JavaScript 技术和实验的集合,并不全是游戏技术,但还是对开发有帮助。最近并不非常活跃,但仍然拥有一些不错的资源。
+- [Game programming patterns](http://gameprogrammingpatterns.com/)
+ - : 在线书籍,作者 Bob Nystrom,其中讨论了游戏开发环境中的编程模式,旨在帮助游戏开发人员生成更有效,更高效的代码。
+- [Artillery blog](http://blog.artillery.com/)
+ - : HTML5 游戏公司 Artillery 在他们的博客上发表的一些有用的文章。
+- [Building games for Firefox OS](https://leanpub.com/buildinggamesforfirefoxos/)
+ - : 使用 HTML5 创建 2D 游戏的快速指南,针对在 Firefox OS 和其他移动平台上分发。
+- [Gamedev.js Weekly](http://gamedevjsweekly.com/)
+ - : 关于 HTML5 游戏开发的每周新闻,每星期五发送。包含最新的文章,教程,工具和资源。
+- [HTML5 Game Devs Forum](http://www.html5gamedevs.com/)
+ - : 开发者,架构师,发布者的论坛。提出问题,获得帮助,帮助他人。
+
+
+
+- [HTML5 游戏引擎](http://html5gameengine.com/)
+ - : 眼下最流行的 HTML5 游戏框架列表,包含评分,特色和案例。
+- [JSBreakouts](http://www.jsbreakouts.org/)
+ - : 比较在不同的框架中的 JavaScript Breakout clones,以帮助您作出正确的选择。
+- [Tuts 与游戏开发](http://gamedevelopment.tutsplus.com/)
+ - : 关于游戏开发的教程和案例。
+- [#BBG IRC chat](http://webchat.freenode.net/?channels=bbg)
+ - : 实时在线与开发者直接对话。
+- [HTML5 Gamedev Starter](http://html5devstarter.enclavegames.com/)
+ - : Starter 针对游戏开发新手,在网络上提供一个策划列表链接到各种,有用的资源。
+- [js13kGames](http://js13kgames.com/)
+ - : 针对 HTML5 游戏开发人员的 JavaScript 编码竞赛,文件大小限制设置为 13 千字节。所有提交的游戏都以可读的形式在 GitHub 上提供。
+- [Mozilla Hacks blog](https://hacks.mozilla.org/category/games/)
+ - : 在 Mozilla Hacks 博客包含关于游戏类别的有趣的游戏开发的相关文章。
+- [Visual-js game engine](Games/Visual-js_game_engine)
+ - : 2d / 3d / webSocket 定向游戏引擎。只有 window 下的工具。托管在 bitbucket 项目网站。
diff --git a/files/zh-cn/games/introduction/index.md b/files/zh-cn/games/introduction/index.md
index b51cb0cebe8ff6..9d88f9e2aae325 100644
--- a/files/zh-cn/games/introduction/index.md
+++ b/files/zh-cn/games/introduction/index.md
@@ -8,108 +8,69 @@ tags:
translation_of: Games/Introduction
original_slug: Games/简介
---
-{{GamesSidebar}}
+{{GamesSidebar}}
-现代的 web 已经高速发展成为一个可行可靠的平台,它不仅能够用来创建高质量的酷炫游戏,同时也能够用来发布和传播这些游戏。
+现代的 web 已经高速发展成为一个可行可靠的平台,它不仅能够用来创建高质量的酷炫游戏,同时也能够用来发布和传播这些游戏。
-采用现代网页技术和较新的浏览器,完全有可能做出令人印象深刻的顶级页面游戏。它能够制作的游戏种类可以和桌面端以及原生系统相当。我们这里所说的,并不是很久之前就采用 Flash®制作出的简单卡牌游戏或者多人社交游戏。而是牛逼的 3D 动作射击游戏,RPG 游戏等等。得益于 JavaScript 实时编译技术性能的大幅提升,以及新开放的 API。在制作运行在浏览器(或者是基于类似 Firefox OS 的 HTML5技术支持的设备)上的游戏时,我们不用妥协。
+采用现代网页技术和较新的浏览器,完全有可能做出令人印象深刻的顶级页面游戏。它能够制作的游戏种类可以和桌面端以及原生系统相当。我们这里所说的,并不是很久之前就采用 Flash® 制作出的简单卡牌游戏或者多人社交游戏。而是牛逼的 3D 动作射击游戏,RPG 游戏等等。得益于 [JavaScript](/zh-CN/docs/JavaScript) 实时编译技术性能的大幅提升,以及新开放的 API。在制作运行在浏览器(或者是基于类似 [Firefox OS](/zh-CN/docs/Mozilla/Firefox_OS) 的 [HTML5](/zh-CN/docs/HTML/HTML5)技术支持的设备)上的游戏时,我们不用妥协。
+## HTML5 游戏平台
+你可以真正地为你的游戏考虑下 Web 来作为更好的目标平台。我们总是喜欢说,"the Web is the platform." 让我们浏览下 Web 平台的核心部分:
-HTML5 游戏平台
+| 功能 | 技术 |
+| -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| **音频** | [Web Audio API](/zh-CN/docs/Web/API/Web_Audio_API) |
+| **图形** | [WebGL](/zh-CN/docs/WebGL) ([OpenGL ES](http://www.khronos.org/opengles/) 2.0) |
+| **输入** | [Touch events](/zh-CN/docs/DOM/Touch_events), [Gamepad API](/zh-CN/docs/Web/API/Gamepad_API/Using_the_Gamepad_API), 设备传感器,[WebRTC](/zh-CN/docs/WebRTC), [Full Screen API](/zh-CN/docs/Web/API/Fullscreen_API), [Pointer Lock API](/zh-CN/docs/API/Pointer_Lock_API) |
+| **语言** | [JavaScript](/zh-CN/docs/JavaScript) (或是 C/C++ 使用 [Emscripten](https://github.com/kripken/emscripten/wiki) 来编译成 JavaScript) |
+| **网络** | [WebRTC](/zh-CN/docs/WebRTC) 和/或 [WebSockets](/zh-CN/docs/Web/API/WebSockets_API) |
+| **存储** | [IndexedDB](/zh-CN/docs/IndexedDB) 或是 "云 (存储)" |
+| **Web** | [HTML](/zh-CN/docs/HTML), [CSS](/zh-CN/docs/CSS), [SVG](/zh-CN/docs/SVG), [Social API](/zh-CN/docs/Mozilla/Projects/Social_API) (还有其他很多很多东西!) |
-你可以真正地为你的游戏考虑下 Web 来作为更好的目标平台。我们总是喜欢说,"the Web is the platform." 让我们浏览下 Web 平台的核心部分:
+## 商业案例
-
+作为一名游戏开发者,无论你是独立的个人还是大型游戏工作室,你想知道你的下一个游戏项目瞄准 Web 是有意义的 。让我们看看 Web 是如何帮到你的。
-商业案例
+1. Web 触手可及;它无处不在。如今可以看到,用 HTML5 构建的游戏运行在智能手机,平板,个人电脑和智能电视。
+2. 提高营销和曝光度。你不限于在某商店推广你的游戏。相反,你可以像其他媒体一样在 Web 宣传和推广你的游戏,利用网络的固有性和共享性接触新客户。
+3. 你可以掌握最重要的事项:支付。你不必交付超过收入的 30% 给他人,仅仅就因为你的游戏在他们的生态系统。相反,你可以管理任何你想要的和使用任何你喜欢的付款处理服务。
+4. 拥有更多控制权的是,只要你愿意,你可以随时更新游戏。 不必着急等待审核通过,仅当其他公司的某某人决定你的关键 bug 修复是否会在今天或明天交付。
+5. 掌握你的数据分析!不必依靠别人作出所有决定,你需要什么分析,你可以收集自己的 -- 或选择你最喜欢的第三方平台,来收集有关你的销售和游戏产生的信息。
+6. 你可以用你的方式更密切地管理你的客户关系。 再也不用苦苦等待只能通过应用商店有限的机制来过滤客户的反馈。用你想要的方式与客户交流, 没有中间人。
+7. 你的玩家可以随时随地玩你的游戏。因为 Web 是无处不在的,你的顾客可以在手机,平板,家庭手提,个人电脑或其他设备上关注游戏动态。
-作为一名游戏开发者,无论你是独立的个人还是大型游戏工作室,你想知道你的下一个游戏项目瞄准 Web 是有意义的 。让我们看看 Web 是如何帮到你的。
+## 针对游戏开发者的 Web 技术
-
- -
-
Web 触手可及;它无处不在。如今可以看到,用 HTML5 构建的游戏运行在智能手机,平板,个人电脑和智能电视。
-
- - 提高营销和曝光度。你不限于在某商店推广你的游戏。相反,你可以像其他媒体一样在 Web 宣传和推广你的游戏,利用网络的固有性和共享性接触新客户。
- - 你可以掌握最重要的事项:支付。你不必交付超过收入的 30% 给他人,仅仅就因为你的游戏在他们的生态系统。相反,你可以管理任何你想要的和使用任何你喜欢的付款处理服务。
- - 拥有更多控制权的是,只要你愿意,你可以随时更新游戏。 不必着急等待审核通过,仅当其他公司的某某人决定你的关键 bug 修复是否会在今天或明天交付。
- - 掌握你的数据分析!不必依靠别人作出所有决定,你需要什么分析,你可以收集自己的 -- 或选择你最喜欢的第三方平台,来收集有关你的销售和游戏产生的信息。
- - 你可以用你的方式更密切地管理你的客户关系。 再也不用苦苦等待只能通过应用商店有限的机制来过滤客户的反馈。用你想要的方式与客户交流, 没有中间人。
- - 你的玩家可以随时随地玩你的游戏。因为 Web 是无处不在的,你的顾客可以在手机,平板,家庭手提,个人电脑或其他设备上关注游戏动态。
-
+技术同行们,让我们发掘出所有关于 Web 的 APIs,将它们呈现给所有的游戏开发者们。下面是一个比较完整的列表,可以一窥 Web 究竟能够做些什么:
-针对游戏开发者的 Web 技术
-
-技术同行们,让我们发掘出所有关于 Web 的 APIs,将它们呈现给所有的游戏开发者们。下面是一个比较完整的列表,可以一窥 Web 究竟能够做些什么:
-
-
-
- - Full Screen API
- - 这个简单的 API 能够让你的游戏占据整个屏幕,从而使玩家沉浸在动作中
- - Gamepad API
- - 如果你想你的用户能够使用游戏手柄或其他游戏控制器来控制游戏,你需要这个 API
- - HTML and CSS
- - 二者合璧,可以构建,设计并对你的游戏界面布局,HTML 有一个提供 2D 图形的元素,即{{HTMLElement("canvas")}}
- - HTML audio
- - {{HTMLElement("audio")}} 元素可以用来播放一些简单的音效和音乐。如果你想要更多的参与,可以学习Web Audio API 来深入了解音频处理的力量!
- - IndexedDB
- - 一个强大的数据存储 API,用来在电脑或者设备上保存用户自己的数据。一个很好的方法用来保存游戏的状态和其它最近的信息,这样在需要的时候不用每次重新下载。也可以用来让你的游戏即使用户没有链接到网络也能继续玩 (例如在飞机上的数小时)。
- - JavaScript
- - JavaScript 是网络上使用的编程语言,在现代浏览器中正在快速发展,而且一直在快速发展。使用它的力量为您的游戏编写代码,或者使用Emscripten或Asm.js等技术轻松移植您现有的游戏。
- - Pointer Lock API
- - 指针锁定 API 允许您在游戏界面中锁定鼠标或其他指针设备,以便您不用绝对定位光标就可以获得坐标变化值,从而准确地判断用户正在做什么,并且还可以防止用户意外地进入另一块屏幕或别的什么地方,从而导致误操作。
- - SVG (可缩放矢量图形)
- - 无论用户显示器的大小或分辨率如何,都可以构建平滑缩放的矢量图形。
- - Typed Arrays
- - JavaScript 中的类型数组可以让您访问原始二进制数据;这使您可以操纵 GL 纹理,游戏数据或其他任何东西,即使它不是原生 JavaScript 数据格式。
- - Web Audio API
- - 这个 API 用于控制 JavaScript 代码中的音频的回放,合成和处理,使您可以创建出色的音效,以及实时播放和操作音乐。
- - WebGL
- - 允许您从 Web 内容创建高性能,硬件加速的 3D(和 2D)图形。这是一个 Web 支持的OpenGL ES 2.0 实现。
- - WebRTC
- - WebRTC(实时通信)API 使您能够控制音频和视频数据,包括远程会议以及两个用户之间来回传输其他应用程序数据。希望你的玩家能够在殴打怪物的同时互相交流?这是你的 API,快使用它吧。
- - WebSockets
- - WebSocket API 使您可以将您的应用程序或站点连接到服务器,实时传输数据。构建完美的多人游戏动作,聊天服务等必备。
- - Web Workers
- - Workers API 能够让您生成运行 JavaScript 代码的后台线程,以充分利用现代的多核 CPU。
- - XMLHttpRequest 和 File API
- - XMLHttpRequest 和 File API 的组合使您可以从 Web 服务器发送和接收任何类型的数据。比如下载新的游戏关卡,文件,以及传递非实时游戏状态信息等。
-
-
+- [Full Screen API](/zh-CN/docs/Web/API/Fullscreen_API)
+ - : 这个简单的 API 能够让你的游戏占据整个屏幕,从而使玩家沉浸在动作中
+- [Gamepad API](/zh-CN/docs/Web/API/Gamepad_API/Using_the_Gamepad_API)
+ - : 如果你想你的用户能够使用游戏手柄或其他游戏控制器来控制游戏,你需要这个 API
+- [HTML](/zh-CN/docs/HTML) and [CSS](/zh-CN/docs/CSS)
+ - : 二者合璧,可以构建,设计并对你的游戏界面布局,HTML 有一个提供 2D 图形的元素,即{{HTMLElement("canvas")}}
+- [HTML audio](/zh-CN/docs/HTML/Element/audio)
+ - : {{HTMLElement("audio")}} 元素可以用来播放一些简单的音效和音乐。如果你想要更多的参与,可以学习[Web Audio API](/zh-CN/docs/Web/API/Web_Audio_API) 来深入了解音频处理的力量!
+- [IndexedDB](/zh-CN/docs/IndexedDB)
+ - : 一个强大的数据存储 API,用来在电脑或者设备上保存用户自己的数据。一个很好的方法用来保存游戏的状态和其它最近的信息,这样在需要的时候不用每次重新下载。也可以用来让你的游戏即使用户没有链接到网络也能继续玩 (例如在飞机上的数小时)。
+- [JavaScript](/zh-CN/docs/JavaScript)
+ - : JavaScript 是网络上使用的编程语言,在现代浏览器中正在快速发展,而且一直在快速发展。使用它的力量为您的游戏编写代码,或者使用[Emscripten](https://github.com/kripken/emscripten/wiki)或[Asm.js](http://asmjs.org/spec/latest/)等技术轻松移植您现有的游戏。
+- [Pointer Lock API](/zh-CN/docs/API/Pointer_Lock_API)
+ - : 指针锁定 API 允许您在游戏界面中锁定鼠标或其他指针设备,以便您不用绝对定位光标就可以获得坐标变化值,从而准确地判断用户正在做什么,并且还可以防止用户意外地进入另一块屏幕或别的什么地方,从而导致误操作。
+- [SVG](/zh-CN/docs/SVG) (可缩放矢量图形)
+ - : 无论用户显示器的大小或分辨率如何,都可以构建平滑缩放的矢量图形。
+- [Typed Arrays](/zh-CN/docs/JavaScript/Typed_arrays)
+ - : JavaScript 中的类型数组可以让您访问原始二进制数据;这使您可以操纵 GL 纹理,游戏数据或其他任何东西,即使它不是原生 JavaScript 数据格式。
+- [Web Audio API](/zh-CN/docs/Web/API/Web_Audio_API)
+ - : 这个 API 用于控制 JavaScript 代码中的音频的回放,合成和处理,使您可以创建出色的音效,以及实时播放和操作音乐。
+- [WebGL](/zh-CN/docs/WebGL)
+ - : 允许您从 Web 内容创建高性能,硬件加速的 3D(和 2D)图形。这是一个 Web 支持的[OpenGL ES](https://www.khronos.org/opengles/) 2.0 实现。
+- [WebRTC](/zh-CN/docs/WebRTC)
+ - : WebRTC(实时通信)API 使您能够控制音频和视频数据,包括远程会议以及两个用户之间来回传输其他应用程序数据。希望你的玩家能够在殴打怪物的同时互相交流?这是你的 API,快使用它吧。
+- [WebSockets](/zh-CN/docs/Web/API/WebSockets_API)
+ - : WebSocket API 使您可以将您的应用程序或站点连接到服务器,实时传输数据。构建完美的多人游戏动作,聊天服务等必备。
+- [Web Workers](/zh-CN/docs/DOM/Using_web_workers)
+ - : Workers API 能够让您生成运行 JavaScript 代码的后台线程,以充分利用现代的多核 CPU。
+- [XMLHttpRequest](/zh-CN/docs/DOM/XMLHttpRequest) 和 [File API](/zh-CN/docs/Web/API/File_and_Directory_Entries_API)
+ - : XMLHttpRequest 和 File API 的组合使您可以从 Web 服务器发送和接收任何类型的数据。比如下载新的游戏关卡,文件,以及传递非实时游戏状态信息等。
diff --git a/files/zh-cn/games/introduction_to_html5_game_development/index.md b/files/zh-cn/games/introduction_to_html5_game_development/index.md
index 37fb345dc179c9..660449b9067025 100644
--- a/files/zh-cn/games/introduction_to_html5_game_development/index.md
+++ b/files/zh-cn/games/introduction_to_html5_game_development/index.md
@@ -7,93 +7,60 @@ tags:
translation_of: Games/Introduction_to_HTML5_Game_Development_(summary)
original_slug: Games/Introduction_to_HTML5_Game_Gevelopment_(summary)
---
-{{GamesSidebar}}
+{{GamesSidebar}}
-优点
+## 优点
-
- - 使用 HTML5 构建的游戏可以在智能手机,平板电脑,个人电脑和智能电视上工作。
- - 通过网络以及其他媒体广告宣传您的游戏。
- - 付款。收取你想要的,并使用任何你喜欢的付款处理服务。
- - 随时更新游戏。
- - 收集您自己的分析!
- - 更密切地与客户联系。
- - 玩家可随时随地玩游戏。
-
+1. 使用 HTML5 构建的游戏可以在智能手机,平板电脑,个人电脑和智能电视上工作。
+2. 通过网络以及其他媒体广告宣传您的游戏。
+3. 付款。收取你想要的,并使用任何你喜欢的付款处理服务。
+4. 随时更新游戏。
+5. 收集您自己的分析!
+6. 更密切地与客户联系。
+7. 玩家可随时随地玩游戏。
-网络技术
+## 网络技术
-
+| **Function** | **Technology** |
+| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| **Audio** | [Web Audio API](/en-US/docs/Web_Audio_API) |
+| **Graphics** | [WebGL](/en-US/docs/WebGL) ([OpenGL ES](http://www.khronos.org/opengles/) 2.0) |
+| **Input** | [Touch events](/en-US/docs/DOM/Touch_events), [Gamepad API](/en-US/docs/API/Gamepad/Using_Gamepad_API), device sensors, [WebRTC](/en-US/docs/WebRTC), [Full Screen API](/en-US/docs/DOM/Using_fullscreen_mode), [Pointer Lock API](/en-US/docs/WebAPI/Pointer_Lock) |
+| **Language** | [JavaScript](/en-US/docs/JavaScript) (or C/C++ using [Emscripten](https://github.com/kripken/emscripten/wiki) to compile to JavaScript) |
+| **Networking** | [WebRTC](/en-US/docs/WebRTC) and/or [WebSockets](/en-US/docs/WebSockets) |
+| **Storage** | [IndexedDB](/en-US/docs/IndexedDB) or the "cloud" |
+| **Web** | [HTML](/en-US/docs/HTML), [CSS](/en-US/docs/CSS), [SVG](/en-US/docs/SVG), [Social API](/en-US/docs/Social_API) (and much more!) |
-
- - Full Screen API
- - 全屏游戏。
- - Gamepad API
- - 使用游戏手柄或其他游戏控制器。
- - HTML and CSS
- - 构建,样式和布局游戏的用户界面。
- - HTML audio
- - 轻松播放简单的音效和音乐。
- - IndexedDB
- - 将用户数据存储在他们自己的计算机或设备上。
- - JavaScript
- - 快速的网页编程语言为您的游戏编写代码。轻松移植您现有的游戏 Emscripten 或 Asm.js
- - Pointer Lock API
- - 在游戏界面中锁定鼠标或其他指针设备。
- - SVG (Scalable Vector Graphics)
- - 构建能够顺利扩展的矢量图形,无论用户显示器的大小或分辨率如何。
- - Typed Arrays
- - 从 JavaScript 中访问原始二进制数据; 操纵 GL 纹理,游戏数据或其他任何东西。
-
+- [Full Screen API](/en-US/docs/DOM/Using_fullscreen_mode)
+ - : 全屏游戏。
+- [Gamepad API](/en-US/docs/API/Gamepad/Using_Gamepad_API)
+ - : 使用游戏手柄或其他游戏控制器。
+- [HTML](/en-US/docs/HTML) and [CSS](/en-US/docs/CSS)
+ - : 构建,样式和布局游戏的用户界面。
+- [HTML audio](/en-US/docs/HTML/Element/audio)
+ - : 轻松播放简单的音效和音乐。
+- [IndexedDB](/en-US/docs/IndexedDB)
+ - : 将用户数据存储在他们自己的计算机或设备上。
+- [JavaScript](/en-US/docs/JavaScript)
+ - : 快速的网页编程语言为您的游戏编写代码。轻松移植您现有的游戏 [Emscripten](https://github.com/kripken/emscripten/wiki) 或 [Asm.js](http://asmjs.org/spec/latest/)
+- [Pointer Lock API](/en-US/docs/WebAPI/Pointer_Lock)
+ - : 在游戏界面中锁定鼠标或其他指针设备。
+- [SVG](/en-US/docs/SVG) (Scalable Vector Graphics)
+ - : 构建能够顺利扩展的矢量图形,无论用户显示器的大小或分辨率如何。
+- [Typed Arrays](/en-US/docs/JavaScript/Typed_arrays)
+ - : 从 JavaScript 中访问原始二进制数据; 操纵 GL 纹理,游戏数据或其他任何东西。
-
- - Web Audio API
- - 实时控制音频的播放,合成和操纵。
- - WebGL
- - 创建高性能,硬件加速的 3D(和 2D)图形。OpenGL ES 2.0.
- - WebRTC
- - 实时通讯控制音频和视频数据,包括电话会议,并在两个用户之间来回传送其他应用数据,如聊天。
- - WebSockets
- - 将您的应用程序或站点连接到一个服务器以实时传输数据。适合多人游戏动作,聊天服务等。
- - Web Workers
- - 生成后台线程为多核处理器运行自己的 JavaScript 代码。
- - XMLHttpRequest and File API
- - 从一个 Web 服务器发送和接收任何您想要的数据,如下载新的游戏级别和艺术品,以便来回传送非实时游戏状态信息。
-
+
+
+- [Web Audio API](/en-US/docs/Web_Audio_API)
+ - : 实时控制音频的播放,合成和操纵。
+- [WebGL](/en-US/docs/WebGL)
+ - : 创建高性能,硬件加速的 3D(和 2D)图形。[OpenGL ES](http://www.khronos.org/opengles/) 2.0.
+- [WebRTC](/en-US/docs/WebRTC)
+ - : 实时通讯控制音频和视频数据,包括电话会议,并在两个用户之间来回传送其他应用数据,如聊天。
+- [WebSockets](/en-US/docs/WebSockets)
+ - : 将您的应用程序或站点连接到一个服务器以实时传输数据。适合多人游戏动作,聊天服务等。
+- [Web Workers](/en-US/docs/DOM/Using_web_workers)
+ - : 生成后台线程为多核处理器运行自己的 JavaScript 代码。
+- [XMLHttpRequest](/en-US/docs/DOM/XMLHttpRequest) and [File API](/en-US/docs/DOM/File_API)
+ - : 从一个 Web 服务器发送和接收任何您想要的数据,如下载新的游戏级别和艺术品,以便来回传送非实时游戏状态信息。
diff --git a/files/zh-cn/games/publishing_games/game_distribution/index.md b/files/zh-cn/games/publishing_games/game_distribution/index.md
index 9319cc665d9fe2..9cdd2e0446ed8e 100644
--- a/files/zh-cn/games/publishing_games/game_distribution/index.md
+++ b/files/zh-cn/games/publishing_games/game_distribution/index.md
@@ -3,125 +3,113 @@ title: Game distribution
slug: Games/Publishing_games/Game_distribution
translation_of: Games/Publishing_games/Game_distribution
---
-{{GamesSidebar}}
+{{GamesSidebar}}
-你已经跟着一两个教程做了一个 HTML5 游戏了——真棒 ! 这篇文章介绍了一些可以让你投放你的游戏的方式。 包括自己建立网站,在公开的应用市场上线,或是发布到 Google Play 或 IOS 的 App Store。
+你已经跟着一两个[教程](/en-US/docs/Games/Workflows/2D_Breakout_game_pure_JavaScript)做了一个 HTML5 游戏了——真棒 ! 这篇文章介绍了一些可以让你投放你的游戏的方式。 包括自己建立网站,在公开的应用市场上线,或是发布到 Google Play 或 IOS 的 App Store。
-HTML5 相较于传统的好处
+## HTML5 相较于传统的好处
-用 HTML5 构筑游戏有许多好处,例如
+用 HTML5 构筑游戏有许多好处,例如
-多平台兼容
+### 多平台兼容
- HTML5 本身是多平台的,所以你只需要写一种代码就可以适配不同的平台。 从小型的智能手机和平板电脑,到笔记本电脑和台式电脑,再到智能电视,智能手表甚至是智能冰箱(如果它内置现代化浏览器的话)。
+HTML5 本身是多平台的,所以你只需要写一种代码就可以适配不同的平台。 从小型的智能手机和平板电脑,到笔记本电脑和台式电脑,再到智能电视,智能手表甚至是智能冰箱(如果它内置现代化浏览器的话)。
- 你并不需要数个开发小组去编写不同平台的代码,你们只需要维护这一种基础代码。 你可以花更多时间去推广游戏和促进游戏收益化。
+你并不需要数个开发小组去编写不同平台的代码,你们只需要维护这一种基础代码。 你可以花更多时间去[推广游戏](/en-US/docs/Games/Techniques/Publishing_games/Game_promotion)和促进[游戏收益化](/en-US/docs/Games/Techniques/Publishing_games/Game_monetization)。
-即时更新
+### 即时更新
- 你不需要花数日去上传你的游戏代码.。如果你发现了漏洞,你可以立即修复它,升级系统和在服务端上传代码以为你的用户更新游戏几乎都是即时的
+你不需要花数日去上传你的游戏代码.。如果你发现了漏洞,你可以立即修复它,升级系统和在服务端上传代码以为你的用户更新游戏几乎都是即时的
-直连,直玩
+### 直连,直玩
- 若是 HTML5 游戏,你无需让大家去应用商店搜索,只需要给他们 URL 链接即可,他们点击链接就可以直接玩游戏,而不需要使用第三方平台或是下载一个很大的安装包来安装游戏。不过你仍需考虑你的游戏的大小是否可能会让用户花一点时间来加载资源,以及你的游戏对网速的需求。总之,如果你把你的游戏按照你的设想构建,并且在开玩之前没有那么多弯弯绕绕,推广它还是很容易的
+若是 HTML5 游戏,你无需让大家去应用商店搜索,只需要给他们 URL 链接即可,他们点击链接就可以直接玩游戏,而不需要使用第三方平台或是下载一个很大的安装包来安装游戏。不过你仍需考虑你的游戏的大小是否可能会让用户花一点时间来加载资源,以及你的游戏对网速的需求。总之,如果你把你的游戏按照你的设想构建,并且在开玩之前没有那么多弯弯绕绕,推广它还是很容易的
-电脑还是手机?
+## 电脑还是手机?
- 我们感兴趣的绝大部分流量——HTML5 游戏玩家——都来自移动设备,所以如果你真的想要成功,你就必须专注于这一点。手机端是 HTML5 真正发光发热的地方,那里没有 Flash,HTML5 便是全部。
+我们感兴趣的绝大部分流量——HTML5 游戏玩家——都来自移动设备,所以如果你真的想要成功,你就必须专注于这一点。手机端是 HTML5 真正发光发热的地方,那里没有 Flash,HTML5 便是全部。
- 要与 PC 端游直接竞争是很困难的,当然你也可以在 PC 端发布你的游戏(见下文的电脑平台)你也应该这么做,因为这可以让你的游戏支持的平台变得多样化,但谨记,电脑游戏的开发者拥有多年的经验,优秀的工具和稳定的发行渠道。许多 HTML5 游戏会与传统电脑游戏面向不同的受众市场。例如,简单的的小游戏比大型的沉浸式游戏更有人气,这类游戏通常设计成用两根手指,甚至一根手指玩,所以你可以拿着设备玩游戏,还可以用第二只手做你目前需要的任何事情。
+要与 PC 端游直接竞争是很困难的,当然你也可以在 PC 端发布你的游戏(见下文的[电脑平台](#电脑平台))你也应该这么做,因为这可以让你的游戏支持的平台变得多样化,但谨记,电脑游戏的开发者拥有多年的经验,优秀的工具和稳定的发行渠道。许多 HTML5 游戏会与传统电脑游戏面向不同的受众市场。例如,简单的的小游戏比大型的沉浸式游戏更有人气,这类游戏通常设计成用两根手指,甚至一根手指玩,所以你可以拿着设备玩游戏,还可以用第二只手做你目前需要的任何事情。
- 话又说回来,电脑平台易于发行游戏,因为有许多好用的打包软件帮助你构造游戏的架构(见下文游戏打包),为你的游戏配置适应电脑端的控制器也是很不错的做法——即使你的游戏主要面向手机用户。用户可以在任何平台畅玩你的游戏,电脑端也应该是其中之一。此外,在电脑端先构建和测试游戏通常更为便捷,然后再到手机端测试 BUG
+话又说回来,电脑平台易于发行游戏,因为有许多好用的打包软件帮助你构造游戏的架构(见下文[游戏打包](#游戏打包)),为你的游戏配置适应电脑端的控制器也是很不错的做法——即使你的游戏主要面向手机用户。用户可以在任何平台畅玩你的游戏,电脑端也应该是其中之一。此外,在电脑端先构建和测试游戏通常更为便捷,然后再到手机端测试 BUG
-发布游戏
+## 发布游戏
-当你要发行游戏时,通常有三种主要的方式可供选择
+当你要发行游戏时,通常有三种主要的方式可供选择
-
+- 自运营
+- 发行商代理
+- 上架商店
-记住你的游戏名应该要足够独特,这样可以在发布之后迅速地推广, 但也要同样朗朗上口,这样人们才不会忘记。
+记住你的游戏名应该要足够独特,这样可以在发布之后迅速地[推广](/en-US/docs/Games/Techniques/Publishing_games/Game_promotion), 但也要同样朗朗上口,这样人们才不会忘记。
-自运营
+### 自运营
-如果你是前端开发者,你应该已经知道要做什么了。一个 HTML5 游戏不过是又一个网站而已.。你可以将它上传到远程服务器,设置一个好记的域名,然后就可以自己开始运营游戏了。
+如果你是前端开发者,你应该已经知道要做什么了。一个 HTML5 游戏不过是又一个网站而已.。你可以将它上传到远程服务器,设置一个好记的域名,然后就可以自己开始运营游戏了。
-如果你想从游戏开发中赚钱,你应该用多种方法保护你的源码,这样其他人不会轻易地取得你的源码并且拿去当成自己的去出售。你可以压缩和精简代码,让它变得更小,更难读,这样他人就不能轻易的复刻你的游戏。一个更好的方法是在网上发布测试版如果你打算打包你的项目并把它出售给 Steam 或者 iTunes。
+如果你想从游戏开发中赚钱,你应该用多种方法保护你的源码,这样其他人不会轻易地取得你的源码并且拿去当成自己的去出售。你可以压缩和精简代码,让它变得更小,更难读,这样他人就不能轻易的复刻你的游戏。一个更好的方法是在网上发布测试版如果你打算打包你的项目并把它出售给 Steam 或者 iTunes。
-如果你只是为了娱乐性质的话,开放源码可以让那些想要从你的作品中学习的人收益。你甚至不需要担心主机提供商,因为你可以在 Github 上托管游戏. 你可以有一个免费的主机,可控制的版本,以及可能的贡献者——如果这个项目足够有趣的话。
+如果你只是为了娱乐性质的话,开放源码可以让那些想要从你的作品中学习的人收益。你甚至不需要担心主机提供商,因为你可以[在 Github 上托管游戏](http://dev.end3r.com/2014/02/host-your-html5-games-on-github-pages/). 你可以有一个免费的主机,可控制的版本,以及可能的贡献者——如果这个项目足够有趣的话。
-发行商和门户网站
+### 发行商和门户网站
-顾名思义,开发商可以帮助你发行游戏,是否交给开发商则取决于你的游戏开发计划:你想在全平台发行么?或你只向购买了游戏的用户开放游戏?这都取决于你,考虑各个选项,试验和结论。你可以在游戏收益化这篇文章中得到更详细的关于发行商的解释。
+顾名思义,开发商可以帮助你发行游戏,是否交给开发商则取决于你的游戏开发计划:你想在全平台发行么?或你只向[购买了游戏](/en-US/docs/Games/Publishing_games/Game_monetization)的用户开放游戏?这都取决于你,考虑各个选项,试验和结论。你可以在[游戏收益化](/en-US/docs/Games/Techniques/Publishing_games/Game_monetization/)这篇文章中得到更详细的关于发行商的解释。
-这里还有许多独立的门户网站收集 HTML5 游戏,例如 HTML5Games.com, MarketJS.com, Clay.io, or Poki 你可以把你的游戏发布上去,它会得到一些自然的推广,因为这些网站吸引了大量的流量。一些网站会把你的文件放在他们的服务器上运营,而其他网站则只链接到你的网站或将你的游戏嵌入他们的网站,这样的曝光可能只是为你的游戏提供宣传,如果你的游戏旁边有广告 (或其他赚钱的选项),它也可能为你的游戏提供收益化。
+这里还有许多独立的门户网站收集 HTML5 游戏,例如 [HTML5Games.com](http://html5games.com/), [MarketJS.com](http://www.marketjs.com/), [Clay.io](http://clay.io/), or [Poki](https://developers.poki.com/) 你可以把你的游戏发布上去,它会得到一些自然的推广,因为这些网站吸引了大量的流量。一些网站会把你的文件放在他们的服务器上运营,而其他网站则只链接到你的网站或将你的游戏嵌入他们的网站,这样的曝光可能只是为你的游戏提供宣传,如果你的游戏旁边有广告 (或其他赚钱的选项),它也可能为你的游戏提供收益化。
-网络和应用商店
+### 网络和应用商店
-你也可以直接把游戏发布到不同的应用商店里,或者是应用市场,要做到这一点,你必须准备好并将其打包为针对您想要针对的每个应用程序生态系统的特定构建格式。见下文应用市场—多样化平台来获取更多关于应用市场的细节
+你也可以直接把游戏发布到不同的应用商店里,或者是应用市场,要做到这一点,你必须准备好并将其打包为针对您想要针对的每个应用程序生态系统的特定构建格式。见下文[应用市场—多样化平台](#应用市场—多样化平台)来获取更多关于应用市场的细节
-应用市场—多样化平台
+## 应用市场—多样化平台
-让我们看看针对不同平台和操作系统的市场/商店有哪些可用选项。
+让我们看看针对不同平台和操作系统的市场/商店有哪些可用选项。
-
-
备注: 这些是最流行的发行平台,但这并不是说这些是唯一的选择。你也可以尝试找到一个对口的平台,并直接向那些对你的游戏感兴趣的观众推广你的游戏。在这里,你的创造力至关重要。
-
+> **备注:** 这些是最流行的发行平台,但这并不是说这些是唯一的选择。你也可以尝试找到一个对口的平台,并直接向那些对你的游戏感兴趣的观众推广你的游戏。在这里,你的创造力至关重要。
-网络商店
+### 网络商店
-最适合 HTML5 的平台是基于 web 的商店。为它们准备一款游戏很容易,因为这样的操作几乎不需要修改游戏本身——通常在包含所有资源的压缩包中添加包含必要信息的清单文件就足够了。
+最适合 HTML5 的平台是基于 web 的商店。为它们[准备一款游戏](http://code.tutsplus.com/tutorials/preparing-for-firefox-os--mobile-18515)很容易,因为这样的操作几乎不需要修改游戏本身——通常在包含所有资源的压缩包中添加包含必要信息的清单文件就足够了。
-
+- [Firefox OS](/pl/docs/Mozilla/Firefox_OS) 是 HTML5 游戏的完美硬件平台,因为系统本身是用 JavaScript 编写的,而且是开源的。您可以快速访问控制硬件的核心应用程序,[Firefox Marketplace](https://marketplace.firefox.com/) 是推广你的游戏的好地方,你也可以更进一步,允许人们直接从网络上安装你的游戏。
+- [The Chrome Web Store](https://chrome.google.com/webstore/) 也是一个吸引人的选择——同样,准备好一个清单文件,压缩你的游戏并填写在线提交表单就足够了。
+- [Tizen](http://www.tizenstore.com/) 还高度重视支持用 JavaScript 编写的应用程序。他们的商店是另一个可用的选择。
-手机应用商店
+### 手机应用商店
- 在移动市场上,iOS 版的苹果应用商店 (Apple App Store)、Android 版的谷歌 Play 以及其他竞争对手。原生商店中已经充斥着销售优秀游戏的成熟开发者,所以你必须具备足够的天赋和幸运才能获得关注。
+在移动市场上,iOS 版的苹果应用商店 (Apple App Store)、Android 版的谷歌 Play 以及其他竞争对手。原生商店中已经充斥着销售优秀游戏的成熟开发者,所以你必须具备足够的天赋和幸运才能获得关注。
-
- - iOS App Store 很难进入,因为游戏必须满足严格的要求,你必须等待一到两周才能被接受。此外,它是最著名的移动商店,有成千上万的应用程序,所以很难从人群中脱颖而出。
- - Google Play's 的要求不那么严格,所以商店被低质量的游戏污染了。由于每天提交的应用程序数量庞大,因此很难被注意到。在这里赚钱也更加困难——大多数来自 iOS 的付费游戏都是在 Android 上作为免费游戏发布的,盈利来自于应用内购买 (IAPs) 或广告。
- - 其他面向 Windows Phone 或黑莓 (Blackberry) 等本土移动平台的商店也在努力分一杯羹,而且远远落后于竞争对手。在那里提交你的游戏是很好的,因为它会更容易被注意到。
-
+- iOS App Store 很难进入,因为游戏必须满足严格的要求,你必须等待一到两周才能被接受。此外,它是最著名的移动商店,有成千上万的应用程序,所以很难从人群中脱颖而出。
+- Google Play's 的要求不那么严格,所以商店被低质量的游戏污染了。由于每天提交的应用程序数量庞大,因此很难被注意到。在这里赚钱也更加困难——大多数来自 iOS 的付费游戏都是在 Android 上作为免费游戏发布的,盈利来自于应用内购买 (IAPs) 或广告。
+- 其他面向 Windows Phone 或黑莓 (Blackberry) 等本土移动平台的商店也在努力分一杯羹,而且远远落后于竞争对手。在那里提交你的游戏是很好的,因为它会更容易被注意到。
-如果你想了解更多关于不同类型的应用程序商店的信息,你可以在维基百科上查看手机软件发布平台列表。
+如果你想了解更多关于不同类型的应用程序商店的信息,你可以在维基百科上查看[手机软件发布平台列表](https://en.wikipedia.org/wiki/List_of_mobile_software_distribution_platforms)。
-电脑平台
+### 电脑平台
- 为了扩大你的受众,你也可以使用 HTML5 游戏去占据电脑游戏市场——只要记住那些已经占据了大部分市场份额的 AAA 级游戏,并仔细考虑这是否适合你的策略。要正确的在电脑端运行,您应该支持所有三种操作系统:Windows、Mac OS 和 Linux。最大的电脑游戏商店无疑是Steam — 独立开发者可以通过 Greenlight 接触 steam. 请记住,您必须通过为不同的平台上传不同的版本来处理跨平台问题。
+为了扩大你的受众,你也可以使用 HTML5 游戏去占据电脑游戏市场——只要记住那些已经占据了大部分市场份额的 AAA 级游戏,并仔细考虑这是否适合你的策略。要正确的在电脑端运行,您应该支持所有三种操作系统:Windows、Mac OS 和 Linux。最大的电脑游戏商店无疑是[Steam](http://steamcommunity.com/) — 独立开发者可以通过 [Greenlight](https://steamcommunity.com/greenlight/) 接触 steam. 请记住,您必须通过为不同的平台上传不同的版本来处理跨平台问题。
- 在你入驻 Steam 之后,便会有许多类似于Humble Bundle等项目的讨论,这些项目可以把最受欢迎的独立游戏能够呈现给更多人。不过,这更像是一个绝佳的促销机会,而不是一种赚大钱的方式,因为捆绑游戏的价格通常相当低。
+在你入驻 Steam 之后,便会有许多类似于[Humble Bundle](http://www.humblebundle.com/)等项目的讨论,这些项目可以把最受欢迎的独立游戏能够呈现给更多人。不过,这更像是一个绝佳的促销机会,而不是一种赚大钱的方式,因为捆绑游戏的价格通常相当低。
-打包游戏
+## 打包游戏
- 网页是 HTML5 游戏的首选也是最好的选择,但如果你想接触到更广泛的受众并在封闭的生态系统中发行你的游戏,你仍然可以通过打包它来做到这一点。好在你不需要几个独立的团队在不同的平台上致力于同一款游戏——你可以一次性构建它,并使用像 Phonegap 或 CocoonIO 这样的工具为本地商店打包游戏。生成的包通常非常可靠,但是您仍然应该测试它们,并注意要修复的小问题或 bug。
+网页是 HTML5 游戏的首选也是最好的选择,但如果你想接触到更广泛的受众并在封闭的生态系统中发行你的游戏,你仍然可以通过打包它来做到这一点。好在你不需要几个独立的团队在不同的平台上致力于同一款游戏——你可以一次性构建它,并使用像 [Phonegap](/en-US/docs/) 或[ CocoonIO](/en-US/docs/) 这样的工具为本地商店打包游戏。生成的包通常非常可靠,但是您仍然应该测试它们,并注意要修复的小问题或 bug。
-实用工具
+### 实用工具
- 根据您的技能、首选框架或目标平台,可以选择多种工具。关键是为你的特定任务选择最好的工具。
+根据您的技能、首选框架或目标平台,可以选择多种工具。关键是为你的特定任务选择最好的工具。
-
- - Phonegap —基于 Cordova,这是为本地平台构建/打包 JavaScript 应用程序最流行的工具
- - CocoonIO — 为多个本地商店构建 HTML5 游戏的最流行的工具。它对画布上呈现的游戏有自己的性能优化,并支持许多游戏框架。
- - Ejecta — 一个专门用于为 iOS 打包使用the ImpactJS框架创建的游戏的工具,由 ImpactJS 作者构建。它提供了与 ImpactJS 的无缝集成,但只支持一个框架和应用程序商店。
- - NW.js — 这款游戏的前身是 Node-Webkit,它是开发适用于 Windows、Mac 和 Linux 的桌面游戏的首选。这些发行版与 WebKit 引擎打包在一起,可以在任何平台上提供呈现。
-
+- [Phonegap](http://phonegap.com/) —基于 Cordova,这是为本地平台构建/打包 JavaScript 应用程序最流行的工具
+- [CocoonIO](http://cocoon.io/) — 为多个本地商店构建 HTML5 游戏的最流行的工具。它对画布上呈现的游戏有自己的性能优化,并支持许多游戏框架。
+- [Ejecta](http://impactjs.com/ejecta) — 一个专门用于为 iOS 打包使用[the ImpactJS](http://impactjs.com/)框架创建的游戏的工具,由 ImpactJS 作者构建。它提供了与 ImpactJS 的无缝集成,但只支持一个框架和应用程序商店。
+- [NW.js](http://nwjs.io/) — 这款游戏的前身是 Node-Webkit,它是开发适用于 Windows、Mac 和 Linux 的桌面游戏的首选。这些发行版与 WebKit 引擎打包在一起,可以在任何平台上提供呈现。
- 其他替代工具包括:
+其他替代工具包括:
-
- - Intel XDK — 一个很棒的的替代品,类似 CocoonIO。
- - Electron — 或者叫 Atom Shell,是 GitHub 的一个开源跨平台工具。.
- - Manifold.js — 微软团队的这个工具可以从 iOS、Android 和 Windows 创建 HTML5 游戏的本地发行版。
-
+- [Intel XDK](https://software.intel.com/en-us/intel-xdk) — 一个很棒的的替代品,类似 CocoonIO。
+- [Electron](http://electron.atom.io/) — 或者叫 Atom Shell,是 GitHub 的一个开源跨平台工具。.
+- [Manifold.js](http://manifoldjs.com/) — 微软团队的这个工具可以从 iOS、Android 和 Windows 创建 HTML5 游戏的本地发行版。
-总结
+## 总结
- 发行游戏是让你的世界为世界所知的方式,选择很多,但没有上上策。当你发行了游戏之后,便是专注于推广的时候了——让人们知道你的游戏的存在。没有推广,它们甚至都可能不知道有这个游戏,更别说玩了。
+发行游戏是让你的世界为世界所知的方式,选择很多,但没有上上策。当你发行了游戏之后,便是专注于[推广](/en-US/docs/Games/Techniques/Publishing_games/Game_promotion/)的时候了——让人们知道你的游戏的存在。没有推广,它们甚至都可能不知道有这个游戏,更别说玩了。
diff --git a/files/zh-cn/games/publishing_games/game_monetization/index.md b/files/zh-cn/games/publishing_games/game_monetization/index.md
index ee34dfefd70387..d1fa7048c35158 100644
--- a/files/zh-cn/games/publishing_games/game_monetization/index.md
+++ b/files/zh-cn/games/publishing_games/game_monetization/index.md
@@ -9,88 +9,88 @@ tags:
translation_of: Games/Publishing_games/Game_monetization
original_slug: Games/Publishing_games/游戏货币化
---
-{{GamesSidebar}}
+{{GamesSidebar}}
-当你花时间创造一个游戏的时候,从发布和促销中赚钱是你应该考虑的事。如果你正做出大量努力去成为一个能够以此为生的独立游戏开发者,接下去,看看你有哪些选择。技术手段已经足够成熟; 接下来只是选择正确的方法。
+当你花时间创造一个游戏的时候,从[发布](/en-US/docs/Games/Techniques/Publishing_games/Game_distribution)和[促销](/en-US/docs/Games/Techniques/Publishing_games/Game_promotion)中赚钱是你应该考虑的事。如果你正做出大量努力去成为一个能够以此为生的独立游戏开发者,接下去,看看你有哪些选择。技术手段已经足够成熟; 接下来只是选择正确的方法。
-付费游戏
+## 付费游戏
-你可能想到的第一个,也是最明显的选择便是以面向 AAA 级游戏的方式销售游戏——即固定的预付款。即使数字市场是关键,你也不需要打印封面,也不需要将游戏放在实体店的盒子里,但要想以固定的价格销售游戏赚取可观的利润,你必须将时间和金钱投入到市场营销中去。只有最好的游戏才能做到收支平衡,或者赚得比制作成本还要多,你仍然需要很多的运气。
+你可能想到的第一个,也是最明显的选择便是以面向 AAA 级游戏的方式销售游戏——即固定的预付款。即使数字市场是关键,你也不需要打印封面,也不需要将游戏放在实体店的盒子里,但要想以固定的价格销售游戏赚取可观的利润,你必须将时间和金钱投入到市场营销中去。只有最好的游戏才能做到收支平衡,或者赚得比制作成本还要多,你仍然需要很多的运气。
-你为你的游戏收取多少费用取决于市场,游戏的质量和许多其他小因素。一款街机 iOS 游戏售价为 0.99 美元,但一款更长的 rpg 风格的 Steam 桌面游戏售价为 20 美元;两个价格都可以。你必须跟随市场,做自己的研究——迅速从错误中吸取教训是很重要的。
+你为你的游戏收取多少费用取决于市场,游戏的质量和许多其他小因素。一款街机 iOS 游戏售价为 0.99 美元,但一款更长的 rpg 风格的 Steam 桌面游戏售价为 20 美元;两个价格都可以。你必须跟随市场,做自己的研究——迅速从错误中吸取教训是很重要的。
-应用内购买内容
+## 应用内购买内容
-你可以提供一款带有应用内购买功能(IAP)的免费游戏,而不是让人们预先为你的游戏付费。在这种情况下,玩家不需要花一分钱就可以获得游戏——将游戏交给玩家,但要提供游戏内的货币、奖金或福利。具体的例子可以包括奖金水平,更好的武器或咒语,或补充所需的能量发挥。设计一个好的 IAP 系统本身就是一门艺术。
+你可以提供一款带有应用内购买功能(IAP)的免费游戏,而不是让人们预先为你的游戏付费。在这种情况下,玩家不需要花一分钱就可以获得游戏——将游戏交给玩家,但要提供游戏内的货币、奖金或福利。具体的例子可以包括奖金水平,更好的武器或咒语,或补充所需的能量发挥。设计一个好的 IAP 系统本身就是一门艺术。
-记住,你需要下载数千次游戏才能使 IAPs 有效——只有一小部分玩家会真正为 IAPs 付费。多小?情况各不相同,但大约每千人中就有一个人处于平均水平。玩你的游戏的人越多,别人就越有可能付钱,所以你的收入很大程度取决于你的推广方式。
+记住,你需要下载数千次游戏才能使 IAPs 有效——只有一小部分玩家会真正为 IAPs 付费。多小?情况各不相同,但大约每千人中就有一个人处于平均水平。玩你的游戏的人越多,别人就越有可能付钱,所以你的收入很大程度取决于你的[推广](/en-US/docs/Games/Techniques/Publishing_games/Game_promotion)方式。
-免费增值模式
+### 免费增值模式
-带有 IAPs 功能的游戏通常被称为免费增值游戏——免费增值游戏可以免费取得与游玩,但你可以为额外的 (高级) 功能、虚拟物品或其他好处付费。在大公司专注于创造游戏后,这个词本身就带有负面含义,其主要目的是为了从玩家那里获得尽可能多的钱,而不是提供一种有趣的体验。最糟糕的情况是,你可以用真金实银来获得相对于其他玩家的优势,或限制玩家进入游戏的下一阶段,除非玩家付费。“为赢付费”这个术语是被创造出来的,并且这种方法不受许多玩家和开发者的欢迎。如果你想要实现 IAPs,那就试着用玩家喜欢的东西来为游戏增加价值,而不是把它拿出来然后收费。
+带有 IAPs 功能的游戏通常被称为免费增值游戏——免费增值游戏可以免费取得与游玩,但你可以为额外的 (高级) 功能、虚拟物品或其他好处付费。在大公司专注于创造游戏后,这个词本身就带有负面含义,其主要目的是为了从玩家那里获得尽可能多的钱,而不是提供一种有趣的体验。最糟糕的情况是,你可以用真金实银来获得相对于其他玩家的优势,或限制玩家进入游戏的下一阶段,除非玩家付费。“为赢付费”这个术语是被创造出来的,并且这种方法不受许多玩家和开发者的欢迎。如果你想要实现 IAPs,那就试着用玩家喜欢的东西来为游戏增加价值,而不是把它拿出来然后收费。
-扩展包 (Add-on) 和可下载内容 (DLC)
+### 扩展包 (Add-on) 和可下载内容 (DLC)
-扩展包和可下载内容是为已经发行的游戏提供额外价值的好方法,但请记住,您必须提供体面的、有趣的内容来吸引人们购买它。一套全新的带有新角色、武器和故事的关卡对于 DLC 来说是一个很好的素材,但要想获得足够的销量,游戏本身必须是受欢迎的,否则就不会有玩家愿意将他们辛苦赚来的钱花在这上面。
+扩展包和可下载内容是为已经发行的游戏提供额外价值的好方法,但请记住,您必须提供体面的、有趣的内容来吸引人们购买它。一套全新的带有新角色、武器和故事的关卡对于 DLC 来说是一个很好的素材,但要想获得足够的销量,游戏本身必须是受欢迎的,否则就不会有玩家愿意将他们辛苦赚来的钱花在这上面。
-推广
+## 推广
-除了积极销售游戏以外,你也可以尝试被动销售 — 投放广告和开展相关活动或许有益于推广你的游戏,但你的游戏必须让人上瘾,这并不像听起来那么容易。你仍然需要计划好,在某种程度上,你也需要一些运气。如果你的游戏像病毒一样传播开来,人们开始分享它,你就能从广告中获得大量的下载和收益。
+除了积极销售游戏以外,你也可以尝试被动销售 — 投放广告和开展相关活动或许有益于[推广](/en-US/docs/Games/Techniques/Publishing_games/Game_promotion)你的游戏,但你的游戏必须让人上瘾,这并不像听起来那么容易。你仍然需要计划好,在某种程度上,你也需要一些运气。如果你的游戏像病毒一样传播开来,人们开始分享它,你就能从广告中获得大量的下载和收益。
-有许多公司提供广告系统——你注册后,允许他们展示广告,以换取一定比例的利润。谷歌 AdSense 被认为是最有效的一个,但它不是为游戏而设计的,使用它来达到这个目的是一个非常糟糕的做法。不要冒着让你的账户被封禁,资产被冻结的风险,游戏开发者们更青睐门户网站,如LeadBolt。他们提供了易于实现的系统,以在您的游戏显示广告并与您分享收益。
+有许多公司提供广告系统——你注册后,允许他们展示广告,以换取一定比例的利润。谷歌 AdSense 被认为是最有效的一个,但它不是为游戏而设计的,使用它来达到这个目的是一个非常糟糕的做法。不要冒着让你的账户被封禁,资产被冻结的风险,游戏开发者们更青睐门户网站,如[LeadBolt](https://www.leadbolt.com/)。他们提供了易于实现的系统,以在您的游戏显示广告并与您分享收益。
-视频广告正变得越来越受欢迎,特别是以预播放的形式——它们会在游戏开始时显示,而此时游戏还在加载中。至于在游戏中放置广告的位置,这完全取决于你自己。它应该尽可能的微妙,以避免过多地惹恼玩家,但又足够的可见性让玩家点击它或至少注意到它。通过屏幕在游戏会话之间添加广告是一种流行的方法。
+视频广告正变得越来越受欢迎,特别是以预播放的形式——它们会在游戏开始时显示,而此时游戏还在加载中。至于在游戏中放置广告的位置,这完全取决于你自己。它应该尽可能的微妙,以避免过多地惹恼玩家,但又足够的可见性让玩家点击它或至少注意到它。通过屏幕在游戏会话之间添加广告是一种流行的方法。
-授权证书
+## 授权证书
-有一种方法可以作为自己的盈利模式,即出售游戏发行许可。越来越多的门户网站有兴趣在他们的网站上展示你的游戏。他们遵循各种策略来通过你的游戏赚钱,但你不必担心所有这些,因为出售许可通常是一次性的交易。你得到了钱,他们就可以创造性地使用你的游戏来赚钱。
+有一种方法可以作为自己的盈利模式,即出售游戏发行许可。越来越多的门户网站有兴趣在他们的网站上展示你的游戏。他们遵循各种策略来通过你的游戏赚钱,但你不必担心所有这些,因为出售许可通常是一次性的交易。你得到了钱,他们就可以创造性地使用你的游戏来赚钱。
-一开始寻找发行商是件困难的事情 — 你可以在HTML5 Gamedevs forums联络他们.。如果你很有名,他们可能会联系你。大多数交易都是通过电子邮件与出版商一方的专业人士进行沟通的。一些出版商的网站很容易获得这些信息,而另一些则很难找到。当接触出版商的时候,尽量友好而直接——他们都是很忙的人。
+一开始寻找发行商是件困难的事情 — 你可以在[HTML5 Gamedevs forums](http://www.html5gamedevs.com/)联络他们.。如果你很有名,他们可能会联系你。大多数交易都是通过电子邮件与出版商一方的专业人士进行沟通的。一些出版商的网站很容易获得这些信息,而另一些则很难找到。当接触出版商的时候,尽量友好而直接——他们都是很忙的人。
-独家许可
+### 独家许可
-独家性许可是针对一个发行商的一种许可类型——你创造了一款游戏,并将其所有权利出售给了一个实体,同时还拥有重新发行该游戏的权利 — Softgames就是这样一家发行商。 在出版商拥有版权的情况下,你不能再以任何形式出售它——这就是独家交易价值不菲的原因。到底是多少?这取决于游戏的质量,游戏类型,发行商,以及其他许多因素,但通常价格在 2000 到 5000 美元之间。一旦你卖出了独家授权,你就不用再参与推广这款游戏了,因为你赚不到更多钱,所以只有在你确信这款游戏足够盈利的情况下,你才会参与这样的交易。
+独家性许可是针对一个发行商的一种许可类型——你创造了一款游戏,并将其所有权利出售给了一个实体,同时还拥有重新发行该游戏的权利 — [Softgames](http://www.softgames.de/)就是这样一家发行商。 在出版商拥有版权的情况下,你不能再以任何形式出售它——这就是独家交易价值不菲的原因。到底是多少?这取决于游戏的质量,游戏类型,发行商,以及其他许多因素,但通常价格在 2000 到 5000 美元之间。一旦你卖出了独家授权,你就不用再参与推广这款游戏了,因为你赚不到更多钱,所以只有在你确信这款游戏足够盈利的情况下,你才会参与这样的交易。
-独家许可
+### 独家许可
-这种方法不那么严格——您可以将许可证出售给多个发布者。这是最受欢迎的方法,因为对于每一个新的发行商 (总会有的),你都可以以非独家的条款出售你的游戏。请记住,有了这个许可,发行商就不能再对其进行重新发行了——这通常被称为站点锁定交易,因为他们购买了在自己的门户网站上发布游戏的权利。非独家许可的通常成本约为 500 美元。
+这种方法不那么严格——您可以将许可证出售给多个发布者。这是最受欢迎的方法,因为对于每一个新的发行商 (总会有的),你都可以以非独家的条款出售你的游戏。请记住,有了这个许可,发行商就不能再对其进行重新发行了——这通常被称为站点锁定交易,因为他们购买了在自己的门户网站上发布游戏的权利。非独家许可的通常成本约为 500 美元。
-定期付费
+### 定期付费
-此外,用户还可以通过购买服务来月付你的游戏而不是一次性付款,每一款游戏每月都能为你提供一定的钱——大约 20-50 美元。你可以决定是一次性付清一段时间还是每月付一次。记住它可以被随时取消,所以它不是一个通解。
+此外,用户还可以通过购买服务来月付你的游戏而不是一次性付款,每一款游戏每月都能为你提供一定的钱——大约 20-50 美元。你可以决定是一次性付清一段时间还是每月付一次。记住它可以被随时取消,所以它不是一个通解。
-推广收入
+### 推广收入
-你可以在自己的游戏中发布广告,并试图找到流量来赚取一些钱,但你也可以与发行商达成收益分成协议。他们将负责吸引流量,并将分享收益——通常是每月 73 开或者五五开的交易。
+你可以在自己的游戏中发布广告,并试图找到流量来赚取一些钱,但你也可以与发行商达成收益分成协议。他们将负责吸引流量,并将分享收益——通常是每月 73 开或者五五开的交易。
-请记住,许多新的、低质量的发行商会希望你的游戏获得广告收入而不是授权,因为这对他们来说更便宜,并且你可能只会在整个交易中获得每款游戏约 2 美元的收益。在与新出版商打交道时要小心——有时候,降低已知出版商的许可成本比冒着被未知出版商骗钱的风险要好。
+请记住,许多新的、低质量的发行商会希望你的游戏获得广告收入而不是授权,因为这对他们来说更便宜,并且你可能只会在整个交易中获得每款游戏约 2 美元的收益。在与新出版商打交道时要小心——有时候,降低已知出版商的许可成本比冒着被未知出版商骗钱的风险要好。
-发行商从你的游戏中获取收益分成,以及/或许可可能需要实现他们自己的 API,这可能需要额外的工作,所以你也要考虑到这一点。
+发行商从你的游戏中获取收益分成,以及/或许可可能需要实现他们自己的 API,这可能需要额外的工作,所以你也要考虑到这一点。
-品牌
+### 品牌
-你可以出售你的游戏的品牌使用权,也可以用你自己的游戏来招揽其他人的品牌。在第一种情况下,它几乎类似于非独占许可,但是你的客户通常会购买代码的权限并构建自己的游戏。在第二种情况下,它就像一个自由的交易,但你将会在代码中加入客户的品牌图形,或有时会按照他们的指示实现需求。举个例子,如果你有一个游戏,玩家点击食物,你可以把食物换成客户的产品来给他们做广告。这个模型中的价格根据品牌、客户和工作量的不同而有很大的差异。
+你可以出售你的游戏的品牌使用权,也可以用你自己的游戏来招揽其他人的品牌。在第一种情况下,它几乎类似于非独占许可,但是你的客户通常会购买代码的权限并构建自己的游戏。在第二种情况下,它就像一个自由的交易,但你将会在代码中加入客户的品牌图形,或有时会按照他们的指示实现需求。举个例子,如果你有一个游戏,玩家点击食物,你可以把食物换成客户的产品来给他们做广告。这个模型中的价格根据品牌、客户和工作量的不同而有很大的差异。
-其他不以游戏为主题的变现手段
+## 其他不以游戏为主题的变现手段
-在开发 HTML5 游戏时,你还可以通过其他方式赚钱,而这甚至不需要与游戏相关。
+在开发 HTML5 游戏时,你还可以通过其他方式赚钱,而这甚至不需要与游戏相关。
-销售资源
+### 销售资源
-如果你是一名平面设计师,你可以出售你所创造的游戏的资产,或一些全新的专为这一目的的在线商店,如Envato Market. 虽然卖的钱并不多,但如果你是一个著名的设计师,它就是一个额外的被动收入流。
+如果你是一名平面设计师,你可以出售你所创造的游戏的资产,或一些全新的专为这一目的的在线商店,如[Envato Market](http://market.envato.com/). 虽然卖的钱并不多,但如果你是一个著名的设计师,它就是一个额外的被动收入流。
-撰写文章和教程
+### 撰写文章和教程
-你可以写一些关于你的游戏的文章,甚至可以从中获得报酬。可以同时取得游戏推广和收益化的双赢,如果你不滥用它与太多的广告,读者将享受阅读他们以及学习一两个东西。如果你专注于先分享知识,并将游戏作为例子来使用,这应该是可以的。浏览Tuts+ Game Development 或相似的网站来找寻协作机会
+你可以写一些关于你的游戏的文章,甚至可以从中获得报酬。可以同时取得游戏[推广](/en-US/docs/Games/Techniques/Publishing_games/Game_promotion)和收益化的双赢,如果你不滥用它与太多的广告,读者将享受阅读他们以及学习一两个东西。如果你专注于先分享知识,并将游戏作为例子来使用,这应该是可以的。浏览[Tuts+ Game Development](http://gamedevelopment.tutsplus.com/) 或相似的网站来找寻协作机会
-周边商品
+### 周边商品
-你可以售卖 T 恤,贴纸或其他周边 — 有些开发者从这些商品中赚的钱比从游戏本身中赚的钱还多,但它只适用于像愤怒的小鸟这样非常受欢迎且易于识别的游戏。不过,这也可能是另一种小的被动收入来源。你的收入越多样化,你的生意就越稳定。
+你可以售卖 T 恤,[贴纸](https://www.stickermule.com/user/1070634890/stickers)或其他周边 — 有些开发者从这些商品中赚的钱比从游戏本身中赚的钱还多,但它只适用于像愤怒的小鸟这样非常受欢迎且易于识别的游戏。不过,这也可能是另一种小的被动收入来源。你的收入越多样化,你的生意就越稳定。
-捐助
+### 捐助
-当其他方法都失败时,你可以尝试在你的游戏页面上放置一个捐赠按钮并寻求社区的支持。有时候它是有效的,但前提是玩家了解你并觉得它能够帮助你。这就是为什么小心管理你的社区是如此重要。这在js13kGames比赛中很管用 — 每个参与者都得到了一件免费的 t 恤,有些人甚至还退了一些钱,以帮助它在未来几年继续运行下去。
+当其他方法都失败时,你可以尝试在你的游戏页面上放置一个捐赠按钮并寻求社区的支持。有时候它是有效的,但前提是玩家了解你并觉得它能够帮助你。这就是为什么小心管理你的社区是如此重要。这在[js13kGames](http://js13kgames.com/)比赛中很管用 — 每个参与者都得到了一件免费的 t 恤,有些人甚至还退了一些钱,以帮助它在未来几年继续运行下去。
-小结
+## 小结
-赚钱的方法有很多种——所有适用于“普通”AAA 级游戏世界的东西,或多或少都可以应用于休闲 HTML5 游戏。然而,你也可以专注于销售许可证,做品牌,或者从广告中获得收入分成。你要走哪条路完全取决于你自己。
+赚钱的方法有很多种——所有适用于“普通”AAA 级游戏世界的东西,或多或少都可以应用于休闲 HTML5 游戏。然而,你也可以专注于销售许可证,做品牌,或者从广告中获得收入分成。你要走哪条路完全取决于你自己。
diff --git a/files/zh-cn/games/publishing_games/game_promotion/index.md b/files/zh-cn/games/publishing_games/game_promotion/index.md
index 6f0985c800330a..a894a1209c9be3 100644
--- a/files/zh-cn/games/publishing_games/game_promotion/index.md
+++ b/files/zh-cn/games/publishing_games/game_promotion/index.md
@@ -3,77 +3,77 @@ title: Game promotion
slug: Games/Publishing_games/Game_promotion
translation_of: Games/Publishing_games/Game_promotion
---
-{{GamesSidebar}}
+{{GamesSidebar}}
-开发与发行你的游戏并不是全部.。你应该让大家知道你有个大家会喜欢玩的游戏。这儿有很多方法去推广你的游戏——大部分方法是免费的,所以即使即使你正努力以一名零预算的独立开发者的身份谋生,你也可以让人们知道你的新游戏.。推广游戏也对之后的游戏收益化大有裨益,所以正确地推广游戏是很重要的。
+开发与发行你的游戏并不是全部.。你应该让大家知道你有个大家会喜欢玩的游戏。这儿有很多方法去推广你的游戏——大部分方法是免费的,所以即使即使你正努力以一名零预算的独立开发者的身份谋生,你也可以让人们知道你的新游戏.。推广游戏也对之后的[游戏收益化](/en-US/docs/Games/Techniques/Publishing_games/Game_monetization)大有裨益,所以正确地推广游戏是很重要的。
-竞赛
+## 竞赛
- 参加竞赛不仅将提升您的游戏开发技能,让你认识新朋友、学习开发,它还将让你参与到社区之中。如果你在比赛中做了一个好的游戏并赢得了一些奖品,你的游戏就会自然而然地被组织者和其他参与者推广开来。你会变得富有和出名,至少他们是这么说的。
- 许多优秀的游戏都是从一个游戏制作比赛上的 demo 开始的。如果你的想法和执行力都足够好,你就会成功。另外,比赛通常要求游戏有一个固定的主题,所以如果你一筹莫展,你也可以围绕这个主题进行创作。
+参加竞赛不仅将提升您的游戏开发技能,让你认识新朋友、学习开发,它还将让你参与到社区之中。如果你在比赛中做了一个好的游戏并赢得了一些奖品,你的游戏就会自然而然地被组织者和其他参与者推广开来。你会变得富有和出名,至少他们是这么说的。
+许多优秀的游戏都是从一个游戏制作比赛上的 demo 开始的。如果你的想法和执行力都足够好,你就会成功。另外,比赛通常要求游戏有一个固定的主题,所以如果你一筹莫展,你也可以围绕这个主题进行创作。
-网站与博客
+## 网站与博客
- 你应该创建自己的网站,包含所有关于游戏的信息,这样人们就可以看到你在做什么。你能包含的信息越多越好 — 包括截图,简报,预告,宣传资料,需求,可用的平台,赞助以及其他。让你的用户在网上直接玩你的游戏——或者说测试版可以让你得到许多电子。同时,为了让你的用户能够更好的玩游戏,你应该做些网站优化(SEO)
+你应该创建自己的网站,包含所有关于游戏的信息,这样人们就可以看到你在做什么。你能包含的信息越多越好 — 包括截图,简报,预告,宣传资料,需求,可用的平台,赞助以及其他。让你的用户在网上直接玩你的游戏——或者说测试版可以让你得到许多电子。同时,为了让你的用户能够更好的玩游戏,你应该做些网站优化(SEO)
- 你也应该在博客公布所有与你游戏开发有关的动作,写下你的开发历程,严重的 bug,有趣的事情,经验教训,以及作为游戏开发者的起起伏伏。坚持发布信息有助于他人从中学习,提高你在社区中的声誉,改进你的网站优化。另一种选择是发布每月报告——总结你所有进展的报告——它能够帮助你看到你在整个月都完成了什么,还有什么需要去做,并不断提醒人们你的游戏即将发行——创造口碑总是好的。
+你也应该在博客公布所有与你游戏开发有关的动作,写下你的开发历程,严重的 bug,有趣的事情,经验教训,以及作为游戏开发者的起起伏伏。坚持发布信息有助于他人从中学习,提高你在社区中的声誉,改进你的网站优化。另一种选择是发布[每月报告](http://dev.end3r.com/?s=monthly+report)——总结你所有进展的报告——它能够帮助你看到你在整个月都完成了什么,还有什么需要去做,并不断提醒人们你的游戏即将发行——创造口碑总是好的。
-社交媒体
+## 社交媒体
- 你的社交媒体的风格很重要 — 选择正确的标签,交朋结友,参与交流,帮助其他开发者。保持真诚,这是你与人结交的关键,因为没有人喜欢无聊的新闻发布或者硬广告.。一旦游戏完成,你的社区会帮助你宣传你的小宝贝游戏的
+你的社交媒体的风格很重要 — 选择正确的[标签](https://twitter.com/hashtag/gamedev),交朋结友,参与交流,帮助其他开发者。保持真诚,这是你与人结交的关键,因为没有人喜欢无聊的新闻发布或者硬广告.。一旦游戏完成,你的社区会帮助你宣传你的小宝贝游戏的
-你应该至少使用推特(Twitter)和脸书(Facebook)之中的一个,并且入驻一个合适的论坛,最出名的就是 HTML5GameDevs.com. 分享你的游戏开发信息,回答别人的问题,这样人们会在心里衡量你所做的一切并且知道你做的很好.。记住也别逢人就说你的游戏——你可不是行走的广告
+你应该至少使用推特(Twitter)和脸书(Facebook)之中的一个,并且入驻一个合适的论坛,最出名的就是 [HTML5GameDevs.com](http://www.html5gamedevs.com/). 分享你的游戏开发信息,回答别人的问题,这样人们会在心里衡量你所做的一切并且知道你做的很好.。记住也别逢人就说你的游戏——你可不是行走的广告
-发展你的粉丝,你可以与他们交流,分享一些小贴士,提供一些福利,在比赛中分发奖品,或者只是抱怨天气或者浏览器的问题,举止冷静,慷慨大方,做你自己,去帮助别人,你就会得到尊重。
+发展你的粉丝,你可以与他们交流,分享一些小贴士,提供一些福利,在比赛中分发奖品,或者只是抱怨天气或者浏览器的问题,举止冷静,慷慨大方,做你自己,去帮助别人,你就会得到尊重。
-游戏门户网站
+## 游戏门户网站
-设立门户网站主要与收益化挂钩, 但是如果你不打算售卖许可来让人们可以购买你的游戏而是打算发布广告 , 在免费的门户网站上推广游戏会更有效。你可以在公共门户网站,比如HTML5Games.com发布游戏,比起传统的游戏发行平台,它更像一个宣传平台。
+设立门户网站主要与[收益化](/en-US/docs/Games/Techniques/Publishing_games/Game_monetization)挂钩, 但是如果你不打算[售卖许可](/en-US/docs/Games/Techniques/Publishing_games/Game_monetization#Licensing)来让人们可以购买你的游戏而是打算[发布广告](/en-US/docs/Games/Techniques/Publishing_games/Game_monetization#Advertisements) , 在免费的门户网站上推广游戏会更有效。你可以在公共门户网站,比如[HTML5Games.com](http://html5games.com/)发布游戏,比起传统的游戏发行平台,它更像一个宣传平台。
-免费的门户网站带来了流量,但是,只有最好的广告才足够受欢迎,能够从发布的广告中获得一些业绩。另一方面,如果你没有预算和有限的时间,门户网站也是一个完美的工具,它可以让更多人看到你的游戏
+免费的门户网站带来了流量,但是,只有最好的广告才足够受欢迎,能够从发布的广告中获得一些业绩。另一方面,如果你没有预算和有限的时间,门户网站也是一个完美的工具,它可以让更多人看到你的游戏
-媒体宣传
+## 媒体宣传
-你可以试着联系媒体去宣传你的游戏,不过要记住,他们每天都在处理成吨的请求,所以如果它们没有及时回复你,请保持耐心,在于他们交流时保持礼貌。一定要先检查他们是否只接纳特定类型的游戏或平台,这样你才不会发送与之无关的内容。如果你方式恰当并且你的游戏很好,那么你就有更多的成功机会
+你可以试着联系媒体去宣传你的游戏,不过要记住,他们每天都在处理成吨的请求,所以如果它们没有及时回复你,请保持耐心,在于他们交流时保持礼貌。一定要先检查他们是否只接纳特定类型的游戏或平台,这样你才不会发送与之无关的内容。如果你方式恰当并且你的游戏很好,那么你就有更多的成功机会
-如果你想了解更多关于联系媒体的礼仪,你可以阅读 How To Contact Press - 由 Pixel Prospector 编写的一篇很棒的指南,还有Video Game Journaliser,他们创建的一个记录媒体联络名单的网站。
+如果你想了解更多关于联系媒体的礼仪,你可以阅读 [How To Contact Press](http://www.pixelprospector.com/how-to-contact-press/) - 由 Pixel Prospector 编写的一篇很棒的指南,还有[Video Game Journaliser](http://videogamejournaliser.com/),他们创建的一个记录媒体联络名单的网站。
-教程
+## 教程
-与其他开发者互通有无是很好的 — 毕竟你可能也曾在网上的一两篇文章上学到了些东西,所以你要花时间把这些知识传递出去。谈论或写一些你取得的成就或克服的问题是人们会感兴趣的事情。你可以拿你自己的游戏做例子,特别是当你展示你已经实现的事情. 这样每个人都会受益——人们学习新的技能,你的游戏会得到推广,如果你足够幸运,你甚至可以因为编写教程而获得报酬
+与其他开发者互通有无是很好的 — 毕竟你可能也曾在网上的一两篇文章上学到了些东西,所以你要花时间把这些知识传递出去。谈论或写一些你取得的成就或克服的问题是人们会感兴趣的事情。你可以拿你自己的游戏做例子,特别是当你[展示你已经实现的事情](/en-US/docs/Games/Techniques/Controls_Gamepad_API). 这样每个人都会受益——人们学习新的技能,你的游戏会得到推广,如果你足够幸运,你甚至可以因为编写教程而获得报酬
-像是Tuts+ Game Development 这样的网站可能会更让人开心——他们为文章付稿费。 但并不是所有的主旨都会被接受。当你在写教程的时候,记住要把重点放在给读者提供一些有价值的东西上。他们想要学习一些东西——提供你的专业知识并将你的游戏作为案例研究。专注于一个方面,并试图解释它的全部和细节。如果人们有任何问题,请记得在评论中跟进讨论。
+像是[Tuts+ Game Development](http://gamedevelopment.tutsplus.com/) 这样的网站可能会更让人开心——他们为文章付稿费。 但并不是所有的主旨都会被接受。当你在写教程的时候,记住要把重点放在给读者提供一些有价值的东西上。他们想要学习一些东西——提供你的专业知识并将你的游戏作为案例研究。专注于一个方面,并试图解释它的全部和细节。如果人们有任何问题,请记得在评论中跟进讨论。
-如果您联系的门户网站因你未写过教程而未采纳你的教程,可以在自己的博客先发布教程,这是锻炼你的写作技巧的最简单的方式。
+如果您联系的门户网站因你未写过教程而未采纳你的教程,可以在[自己的博客](/en-US/docs/Games/Publishing_games/Game_promotion#Website_and_blog)先发布教程,这是锻炼你的写作技巧的最简单的方式。
-YouTuber 视频主 (YouTubers)
+## YouTuber 视频主 (YouTubers)
-这是一种趋势 — 别低估了 YouTuber 视频主(YouTubers)们对游戏的影响力,与他们交流,让他们做游戏实况会极大的宣传你的游戏。不过,你也应该现实一点——不要认为仅仅这一点就会让你的下载量或访问量飙升,而且要准备好处理好不好的评论。
+这是一种趋势 — 别低估了 YouTuber 视频主(YouTubers)们对游戏的影响力,与他们交流,让他们做游戏实况会极大的宣传你的游戏。不过,你也应该现实一点——不要认为仅仅这一点就会让你的下载量或访问量飙升,而且要准备好处理好不好的评论。
-有两种方法可以让 Youtubers 选择你的游戏:第一种方法是你直接联系他们,并通过电子邮件或私人信息向他们发送游戏链接。第二种方法更省时 - 如果你很有名,Youtubers 可能会向你索要游戏链接或游戏文件。这个YouTuber 的名单是个很好的开始。
+有两种方法可以让 Youtubers 选择你的游戏:第一种方法是你直接联系他们,并通过电子邮件或私人信息向他们发送游戏链接。第二种方法更省时 - 如果你很有名,Youtubers 可能会向你索要游戏链接或游戏文件。这个[YouTuber 的名单](http://videogamecaster.com/big-list-of-youtubers)是个很好的开始。
-活动
+## 活动
-如果你已经完成了上面列出的所有选项,你仍然可以找到新的、创造性的方式去推广你的游戏——活动便是另一个很好的例子。参加本地和全球的活动,让您能够面对面地与您的粉丝以及开发社区的其他成员见面。别辜负了他们专程花时间来看你的心思。.
+如果你已经完成了上面列出的所有选项,你仍然可以找到新的、创造性的方式去推广你的游戏——活动便是另一个很好的例子。参加本地和全球的活动,让您能够面对面地与您的粉丝以及开发社区的其他成员见面。别辜负了他们专程花时间来看你的心思。.
-会议
+### 会议
-在许多会议上,您可以发表演讲,解释您克服的一些技术困难,或者如何实现特定的 API;其次,以你的游戏为例。专注于知识部分并降低市场营销是很重要的——开发者对这个问题很敏感,如果你只是想向他们推销一些东西,他们可能会对此不满。.
+在许多会议上,您可以发表演讲,解释您克服的一些技术困难,或者如何实现特定的 API;其次,以你的游戏为例。专注于知识部分并降低市场营销是很重要的——开发者对这个问题很敏感,如果你只是想向他们推销一些东西,他们可能会对此不满。.
-展会
+### 展会
-另一个与活动相关的选项是展会 (或博览会)——在这样的活动中,您可以在其他开发者中获得一个摊位,并向所有经过的参与者推广您的游戏。如果你这样做了,那就试着做得独特而有创意,这样你就很容易从人群中脱颖而出。以正确的方式去做,每个人都会谈论你和你的游戏。有一个展台可以让你与你的粉丝直接互动——除了推广部分,你还可以在普通人身上测试你的游戏的新版本,并修复他们发现的任何 bug(或包含任何反馈)。你无法想象人们在玩你的游戏时可能会想到什么,以及你在花费数小时打磨游戏时错过了哪些明显的问题。
+另一个与活动相关的选项是展会 (或博览会)——在这样的活动中,您可以在其他开发者中获得一个摊位,并向所有经过的参与者推广您的游戏。如果你这样做了,那就试着做得独特而有创意,这样你就很容易从人群中脱颖而出。以正确的方式去做,每个人都会谈论你和你的游戏。有一个展台可以让你与你的粉丝直接互动——除了推广部分,你还可以在普通人身上测试你的游戏的新版本,并修复他们发现的任何 bug(或包含任何反馈)。你无法想象人们在玩你的游戏时可能会想到什么,以及你在花费数小时打磨游戏时错过了哪些明显的问题。
-优惠码
+## 优惠码
-如果你是在销售游戏,那么你应该发行优惠码让人们免费游玩你的游戏 (或至少是一个演示版或限时版),并把它们发送到各地——给媒体,Youtuber,作为比赛奖品等等。如果游戏符合某些人的胃口,就相当于为成千上万人打了一次免费广告。如果你幸运的话,它比任何其他东西都能提高人们对你的游戏的兴趣
+如果你是在销售游戏,那么你应该发行优惠码让人们免费游玩你的游戏 (或至少是一个演示版或限时版),并把它们发送到各地——给媒体,Youtuber,作为比赛奖品等等。如果游戏符合某些人的胃口,就相当于为成千上万人打了一次免费广告。如果你幸运的话,它比任何其他东西都能提高人们对你的游戏的兴趣
-培养社区
+## 培养社区
-你可以帮助社区成长,同时推广你自己和你的游戏。发布每周时事通讯,组织在线竞赛或者线下聚会,这些都能让别人知道你对自己的工作充满激情,他们可以依靠你。当你需要帮助的时候,他们会在你身边
+你可以帮助社区成长,同时推广你自己和你的游戏。发布[每周时事通讯](http://gamedevjsweekly.com/),组织[在线竞赛](http://js13kgames.com/)或者[线下聚会](http://gamedevjs.com/),这些都能让别人知道你对自己的工作充满激情,他们可以依靠你。当你需要帮助的时候,他们会在你身边
-总结
+## 总结
-任何推广你的游戏的方法都是好的。你有很多选择,其中大部分都是免费的,所以关键在于你的热情和可用时间。有时候你不得不花更多的时间去推广一款游戏,而不是真正去开发它。记住,如果没有人知道世界上最好的游戏的存在,那么拥有它是没有任何意义的。
+任何推广你的游戏的方法都是好的。你有很多选择,其中大部分都是免费的,所以关键在于你的热情和可用时间。有时候你不得不花更多的时间去推广一款游戏,而不是真正去开发它。记住,如果没有人知道世界上最好的游戏的存在,那么拥有它是没有任何意义的。
-现在让我们进入游戏收益化部分,然后挣口饭吃吧。
+现在让我们进入[游戏收益化](/en-US/docs/Games/Techniques/Publishing_games/Game_monetization)部分,然后挣口饭吃吧。
diff --git a/files/zh-cn/games/publishing_games/index.md b/files/zh-cn/games/publishing_games/index.md
index 373ca8236d3fa7..01eae27136723e 100644
--- a/files/zh-cn/games/publishing_games/index.md
+++ b/files/zh-cn/games/publishing_games/index.md
@@ -8,16 +8,18 @@ tags:
- 获利
translation_of: Games/Publishing_games
---
-{{GamesSidebar}}
HTML5 游戏在发布和分发上具有极大的优势--你可以通过网络自由地发布,推广,获利,并且不受分发商的限制。你可以实现通过多种平台获利。这一系列的案例关注在当你想要发布,推广你的游戏,并当游戏变得有名时获取一些回报。
+{{GamesSidebar}}
-游戏发布
+HTML5 游戏在发布和分发上具有极大的优势--你可以通过网络自由地发布,推广,获利,并且不受分发商的限制。你可以实现通过多种平台获利。这一系列的案例关注在当你想要发布,推广你的游戏,并当游戏变得有名时获取一些回报。
-你按照一个或两个教程(1,2)制作了一个 HTML5 游戏。Game distribution提供了你发布游戏时所需的一切知识。包括如何在线托管游戏,提交游戏到开放的游戏市场,或封闭的游戏市场,如 Google Play,iOS App Store.
+## 游戏发布
-游戏推广
+你按照一个或两个教程([1](/zh-CN/docs/Games/Workflows/2D_Breakout_game_pure_JavaScript),[2](/zh-CN/docs/Games/Workflows/2D_Breakout_game_Phaser))制作了一个 HTML5 游戏。[Game distribution](/zh-CN/docs/Games/Publishing_games/Game_distribution)提供了你发布游戏时所需的一切知识。包括如何在线托管游戏,提交游戏到开放的游戏市场,或封闭的游戏市场,如 Google Play,iOS App Store.
-开发完成游戏并不是结束。你必须让世界知道你制作了一些有趣的东西能使他们乐在其中。这些游戏推广技术— 有些是免费的 — 即使你作为一名 0 预算的独立开发者为生活奔波,你依旧可以让很多人知道你制作的这个新游戏。推广游戏或许能够使你获得收入。高效的推广非常重要。
+## 游戏推广
-游戏获利
+开发完成游戏并不是结束。你必须让世界知道你制作了一些有趣的东西能使他们乐在其中。这些[游戏推广](/zh-CN/docs/Games/Publishing_games/Game_promotion)技术— 有些是免费的 — 即使你作为一名 0 预算的独立开发者为生活奔波,你依旧可以让很多人知道你制作的这个新游戏。推广游戏或许能够使你获得收入。高效的推广非常重要。
-当你开发,发布并推广你的游戏后,你可以考虑通过游戏来获得收入。游戏获利对于考虑从业余转为全职并以此为生的开发者来说是必要的一个手段。现在来看看你的选择,技术已经足够成熟,现在只差一个合适的机会了。
+## 游戏获利
+
+当你开发,发布并推广你的游戏后,你可以考虑通过游戏来获得收入。[游戏获利](/zh-CN/docs/Games/Publishing_games/Game_monetization)对于考虑从业余转为全职并以此为生的开发者来说是必要的一个手段。现在来看看你的选择,技术已经足够成熟,现在只差一个合适的机会了。
diff --git a/files/zh-cn/games/techniques/2d_collision_detection/index.md b/files/zh-cn/games/techniques/2d_collision_detection/index.md
index b394ef4c07ef27..90812ca993ac69 100644
--- a/files/zh-cn/games/techniques/2d_collision_detection/index.md
+++ b/files/zh-cn/games/techniques/2d_collision_detection/index.md
@@ -3,80 +3,76 @@ title: 2D collision detection
slug: Games/Techniques/2D_collision_detection
translation_of: Games/Techniques/2D_collision_detection
---
-{{GamesSidebar}}
+{{GamesSidebar}}
-
-
检测 2D 游戏中的碰撞算法,依赖于可碰撞物体的形状(例如:矩形与矩形,矩形与圆形,圆形与圆形)。通常情况下,你使用的的简单通用形状,会被称为“hitbox”的实体所覆盖,尽管发生的碰撞并不是像素完美契合的,它看起来也足够好,而且可跨多个实体执行碰撞。本文提供了一系列较为通用的 2D 游戏中碰撞侦测技术。
-
+检测 2D 游戏中的碰撞算法,依赖于可碰撞物体的形状(例如:矩形与矩形,矩形与圆形,圆形与圆形)。通常情况下,你使用的的简单通用形状,会被称为“hitbox”的实体所覆盖,尽管发生的碰撞并不是像素完美契合的,它看起来也足够好,而且可跨多个实体执行碰撞。本文提供了一系列较为通用的 2D 游戏中碰撞侦测技术。
-Axis-Aligned Bounding Box
+## Axis-Aligned Bounding Box
-碰撞侦测其中一种简单的形式是,在两个轴对齐的矩形之间碰撞 — 这意味着没有旋转。这个算法是确定两个矩形任意 4 边之间不再有间隔,存在间隔代表没有发生碰撞。
+碰撞侦测其中一种简单的形式是,在两个轴对齐的矩形之间碰撞 — 这意味着没有旋转。这个算法是确定两个矩形任意 4 边之间不再有间隔,存在间隔代表没有发生碰撞。
-var rect1 = {x: 5, y: 5, width: 50, height: 50}
+```js
+var rect1 = {x: 5, y: 5, width: 50, height: 50}
var rect2 = {x: 20, y: 10, width: 10, height: 10}
-if (rect1.x < rect2.x + rect2.width &&
- rect1.x + rect1.width > rect2.x &&
- rect1.y < rect2.y + rect2.height &&
- rect1.height + rect1.y > rect2.y) {
+if (rect1.x < rect2.x + rect2.width &&
+ rect1.x + rect1.width > rect2.x &&
+ rect1.y < rect2.y + rect2.height &&
+ rect1.height + rect1.y > rect2.y) {
// collision detected!
}
-// filling in the values =>
+// filling in the values =>
-if (5 < 30 &&
- 55 > 20 &&
- 5 < 20 &&
- 55 > 10) {
+if (5 < 30 &&
+ 55 > 20 &&
+ 5 < 20 &&
+ 55 > 10) {
// collision detected!
-}
+}
+```
-
+> **备注:** You can see a [live example of Axis-Aligned Bounding Box collision detection](http://jsfiddle.net/knam8/) on jsFiddle, to illustrate how this code would work in practice. [Here is another example without Canvas or external libraries](https://jsfiddle.net/jlr7245/217jrozd/3/).
-圆形碰撞
+## 圆形碰撞
-碰撞测试的另一种形状是两个圆形间的碰撞,该算法是通过获取两个圆心点,并确定圆心距离小于两个圆形的半径和实现的。
+碰撞测试的另一种形状是两个圆形间的碰撞,该算法是通过获取两个圆心点,并确定圆心距离小于两个圆形的半径和实现的。
-var circle1 = {radius: 20, x: 5, y: 5};
+```js
+var circle1 = {radius: 20, x: 5, y: 5};
var circle2 = {radius: 12, x: 10, y: 5};
var dx = circle1.x - circle2.x;
var dy = circle1.y - circle2.y;
var distance = Math.sqrt(dx * dx + dy * dy);
-if (distance < circle1.radius + circle2.radius) {
+if (distance < circle1.radius + circle2.radius) {
// collision detected!
-}
+}
+```
-
+> **备注:** You can see a [live example of Circle collision detection](http://jsfiddle.net/gQ3hD/2/) on jsFiddle, to illustrate how this code would work in practice.
-Separating Axis Theorem
+## Separating Axis Theorem
-This is a collision algorithm that can detect a collision between any two *convex* polygons. It's more complicated to implement than the above methods but is more powerful. The complexity of an algorithm like this means we will need to consider performance optimization, covered in the next section.
+This is a collision algorithm that can detect a collision between any two \*convex\* polygons. It's more complicated to implement than the above methods but is more powerful. The complexity of an algorithm like this means we will need to consider performance optimization, covered in the next section.
-Implementing SAT is out of scope for this page so see the recommended tutorials below:
+Implementing SAT is out of scope for this page so see the recommended tutorials below:
-
- - Separating Axis Theorem (SAT) explanation
- - Collision detection and response
- - Collision detection Using the Separating Axis Theorem
- - SAT (Separating Axis Theorem)
- - Separation of Axis Theorem (SAT) for Collision Detection
-
+1. [Separating Axis Theorem (SAT) explanation](http://www.sevenson.com.au/actionscript/sat/)
+2. [Collision detection and response](http://www.metanetsoftware.com/technique/tutorialA.html)
+3. [Collision detection Using the Separating Axis Theorem](http://gamedevelopment.tutsplus.com/tutorials/collision-detection-using-the-separating-axis-theorem--gamedev-169)
+4. [SAT (Separating Axis Theorem)](http://www.codezealot.org/archives/55)
+5. [Separation of Axis Theorem (SAT) for Collision Detection](http://rocketmandevelopment.com/blog/separation-of-axis-theorem-for-collision-detection/)
-
+## Collision Performance
-While some of these algorithms for collision detection are simple enough to calculate, it can be a waste of cycles to test *every* entity with every other entity. Usually games will split collision into two phases, broad and narrow.
+While some of these algorithms for collision detection are simple enough to calculate, it can be a waste of cycles to test \*every\* entity with every other entity. Usually games will split collision into two phases, broad and narrow.
-Broad Phase
+### Broad Phase
-Broad phase should give you a list of entities that *could* be colliding. This can be implemented with a spacial data structure that will give you a rough idea of where the entity exists and what exist around it. Some examples of spacial data structures are Quad Trees, R-Trees or a Spacial Hashmap.
+Broad phase should give you a list of entities that \*could\* be colliding. This can be implemented with a spacial data structure that will give you a rough idea of where the entity exists and what exist around it. Some examples of spacial data structures are Quad Trees, R-Trees or a Spacial Hashmap.
-Narrow Phase
+### Narrow Phase
-When you have a small list of entities to check you will want to use a narrow phase algorithm (like the ones listed above) to provide a certain answer as to whether there is a collision or not.
+When you have a small list of entities to check you will want to use a narrow phase algorithm (like the ones listed above) to provide a certain answer as to whether there is a collision or not.
diff --git a/files/zh-cn/games/techniques/3d_collision_detection/index.md b/files/zh-cn/games/techniques/3d_collision_detection/index.md
index a442e2f1f87727..b98476c2354ed5 100644
--- a/files/zh-cn/games/techniques/3d_collision_detection/index.md
+++ b/files/zh-cn/games/techniques/3d_collision_detection/index.md
@@ -3,118 +3,120 @@ title: 3D 碰撞检测
slug: Games/Techniques/3D_collision_detection
translation_of: Games/Techniques/3D_collision_detection
---
-{{GamesSidebar}}
本文介绍了用于在 3D 环境中实现不同边界体积碰撞检测的技术。 后续文章将讨论特定 3D 库中的实现。
+{{GamesSidebar}}
-Axis-aligned bounding boxes(AABB 包围盒)
+本文介绍了用于在 3D 环境中实现不同边界体积碰撞检测的技术。 后续文章将讨论特定 3D 库中的实现。
-
+## Axis-aligned bounding boxes(**AABB 包围盒**)
-在游戏中,为了简化物体之间的碰撞检测运算,通常会对物体创建一个规则的几何外形将其包围。其中,AABB(axis-aligned bounding box)包围盒被称为轴对齐包围盒。
+在游戏中,为了简化物体之间的碰撞检测运算,通常会对物体创建一个规则的几何外形将其包围。其中,AABB(axis-aligned bounding box)包围盒被称为轴对齐包围盒。
-与 2D 碰撞检测一样,轴对齐包围盒是判断两个物体是否重叠的最快算法,物体被包裹在一个非旋转的(因此轴对齐的)盒中,并检查这些盒在三维坐标空间中的位置,以确定它们是否重叠。
+与 2D 碰撞检测一样,轴对齐包围盒是判断两个物体是否重叠的最快算法,物体被包裹在一个非旋转的(因此轴对齐的)盒中,并检查这些盒在三维坐标空间中的位置,以确定它们是否重叠。
-
+![](screen_shot_2015-10-16_at_15.11.21.png)
-由于性能原因,轴对齐是有一些约束的。两个非旋转的盒子之间是否重叠可以通过逻辑比较进行检查,而旋转的盒子则需要三角运算,这会导致性能下降。如果你有旋转的物体,可以通过修改边框的尺寸,这样盒子仍可以包裹物体,或者选择使用另一种边界几何类型,比如球体 (球体旋转,形状不会变)。下图是一个 AABB 物体旋转,动态调节盒大小适应物体的例子。
+由于性能原因,轴对齐是有一些约束的。两个非旋转的盒子之间是否重叠可以通过逻辑比较进行检查,而旋转的盒子则需要三角运算,这会导致性能下降。如果你有旋转的物体,可以通过修改边框的尺寸,这样盒子仍可以包裹物体,或者选择使用另一种边界几何类型,比如球体 (球体旋转,形状不会变)。下图是一个 AABB 物体旋转,动态调节盒大小适应物体的例子。
-
+![](rotating_knot.gif)
-
-
备注: 参考这里,使用 Three.js 进行边界体积碰撞检测。
-
+> **备注:** 参考[这里](/en-US/docs/Games/Techniques/3D_collision_detection/Bounding_volume_collision_detection_with_THREE.js),使用 Three.js 进行边界体积碰撞检测。
-点与 AABB
+### 点与 AABB
-如果检测到一个点是否在 AABB 内部就非常简单了 — 我们只需要检查这个点的坐标是否在 AABB 内; 分别考虑到每种坐标轴。如果假设 Px, Py 和 Pz 是点的坐标, BminX–BmaxX, BminY–BmaxY, 和 BminZ–BmaxZ 是 AABB 的每一个坐标轴的范围,我们可以使用以下公式计算两者之间的碰撞是否发生:
+如果检测到一个点是否在 AABB 内部就非常简单了 — 我们只需要检查这个点的坐标是否在 AABB 内; 分别考虑到每种坐标轴。如果假设 _Px_, _Py 和_ _Pz_ 是点的坐标, _BminX_–_BmaxX_, _BminY_–_BmaxY_, 和 _BminZ_–_BmaxZ_ 是 AABB 的每一个坐标轴的范围,我们可以使用以下公式计算两者之间的碰撞是否发生:
-
+
-或者用 JavaScript:
+或者用 JavaScript:
-function isPointInsideAABB(point, box) {
- return (point.x >= box.minX && point.x <= box.maxX) &&
- (point.y >= box.minY && point.y <= box.maxY) &&
- (point.z >= box.minY && point.z <= box.maxZ);
-}
+```js
+function isPointInsideAABB(point, box) {
+ return (point.x >= box.minX && point.x <= box.maxX) &&
+ (point.y >= box.minY && point.y <= box.maxY) &&
+ (point.z >= box.minY && point.z <= box.maxZ);
+}
+```
-AABB 与 AABB
+### AABB 与 AABB
-检查一个 AABB 是否和另一个 AABB 相交类似于检测两个点一样。我们只需要基于每一条坐标轴并利用盒子的边缘去检测。下图显示了我们基于 X 轴的检测 — 当然, AminX–AmaxX 和 BminX–BmaxX 会不会重叠?
+检查一个 AABB 是否和另一个 AABB 相交类似于检测两个点一样。我们只需要基于每一条坐标轴并利用盒子的边缘去检测。下图显示了我们基于 X 轴的检测 — 当然, _AminX_–_AmaxX_ 和 _BminX_–_BmaxX_ 会不会重叠?
-
+![updated version](aabb_test.png)
-在数学上的表示就像这样:
+在数学上的表示就像这样:
-
+
-在 JavaScript 我们可以这样:
+在 JavaScript 我们可以这样:
-function intersect(a, b) {
- return (a.minX <= b.maxX && a.maxX >= b.minX) &&
- (a.minY <= b.maxY && a.maxY >= b.minY) &&
- (a.minZ <= b.maxZ && a.maxZ >= b.minZ);
+```js
+function intersect(a, b) {
+ return (a.minX <= b.maxX && a.maxX >= b.minX) &&
+ (a.minY <= b.maxY && a.maxY >= b.minY) &&
+ (a.minZ <= b.maxZ && a.maxZ >= b.minZ);
}
-
+```
-球体碰撞
+## 球体碰撞
-球体碰撞边缘检测比 AABB 盒子稍微复杂一点,但他的检测仍相当容易的。球体的主要优势是他们不变的旋转,如果包装实体旋转,边界领域仍将是相同的。他们的主要缺点是,除非他们包装的实体实际上是球形,包装的实体通常不是一个完美的球形 (比如用这样的球形包装一个人将导致一些错误,而 AABB 盒子将更合适)。
+球体碰撞边缘检测比 AABB 盒子稍微复杂一点,但他的检测仍相当容易的。球体的主要优势是他们不变的旋转,如果包装实体旋转,边界领域仍将是相同的。他们的主要缺点是,除非他们包装的实体实际上是球形,包装的实体通常不是一个完美的球形 (比如用这样的球形包装一个人将导致一些错误,而 AABB 盒子将更合适)。
-点与球
+### 点与球
-检查是否一个球体包含一个点,我们需要计算点和球体的中心之间的距离。如果这个距离小于或等于球的半径,这个点就在里面。
+检查是否一个球体包含一个点,我们需要计算点和球体的中心之间的距离。如果这个距离小于或等于球的半径,这个点就在里面。
-
+![](point_vs_sphere.png)
-两个点 A 和 B 之间的欧氏距离是
- ,我们的公式指出,球体碰撞检测是:
+两个点 A 和 B 之间的欧氏距离是 ,我们的公式指出,球体碰撞检测是:
-
+
-或者用 JavaScript:
+或者用 JavaScript:
-function isPointInsideSphere(point, sphere) {
+```js
+function isPointInsideSphere(point, sphere) {
// we are using multiplications because is faster than calling Math.pow
var distance = Math.sqrt((point.x - sphere.x) * (point.x - sphere.x) +
(point.y - sphere.y) * (point.y - sphere.y) +
(point.z - sphere.z) * (point.z - sphere.z));
- return distance < sphere.radius;
+ return distance < sphere.radius;
}
-
+```
-
-
备注: 上面的代码有一个平方根,是一个开销昂贵的计算。一个简单的优化,以避免它由半径平方,所以优化方程不涉及distance < sphere.radius * sphere.radius
.
-
+> **备注:** 上面的代码有一个平方根,是一个开销昂贵的计算。一个简单的优化,以避免它由半径平方,所以优化方程不涉及`distance < sphere.radius * sphere.radius`.
-球体与球体
+### 球体与球体
-球体与球体的距离类似于点和球体。我们需要测试是球体的中心之间的距离小于或等于半径的总和。
+球体与球体的距离类似于点和球体。我们需要测试是球体的中心之间的距离小于或等于半径的总和。
-
+![](sphere_vs_sphere.png)
-在数学上,像这样:
+在数学上,像这样:
-
+
-或者 JavaScript:
+或者 JavaScript:
-function intersect(sphere, other) {
+```js
+function intersect(sphere, other) {
// we are using multiplications because it's faster than calling Math.pow
var distance = Math.sqrt((sphere.x - other.x) * (sphere.x - other.x) +
(sphere.y - other.y) * (sphere.y - other.y) +
(sphere.z - other.z) * (sphere.z - other.z));
- return distance < (sphere.radius + other.radius); }
-}
+ return distance < (sphere.radius + other.radius); }
+}
+```
-球体与 AABB
+### 球体与 AABB
-测试一个球和一个 AABB 的碰撞是稍微复杂,但过程仍然简单和快速。一个合乎逻辑的方法是,检查 AABB 每个顶点,计算每一个点与球的距离。然而这是大材小用了,测试所有的顶点都是不必要的,因为我们可以侥幸计算 AABB 最近的点 (不一定是一个顶点) 和球体的中心之间的距离,看看它是小于或等于球体的半径。我们可以通过逼近球体的中心和 AABB 的距离得到这个值。
+测试一个球和一个 AABB 的碰撞是稍微复杂,但过程仍然简单和快速。一个合乎逻辑的方法是,检查 AABB 每个顶点,计算每一个点与球的距离。然而这是大材小用了,测试所有的顶点都是不必要的,因为我们可以侥幸计算 AABB 最近的点 (不一定是一个顶点) 和球体的中心之间的距离,看看它是小于或等于球体的半径。我们可以通过逼近球体的中心和 AABB 的距离得到这个值。
-
+![](sphere_vs_aabb.png)
-在 JavaScript, 我们可以像这样子做:
+在 JavaScript, 我们可以像这样子做:
-function intersect(sphere, box) {
+```js
+function intersect(sphere, box) {
// get box closest point to sphere center by clamping
var x = Math.max(box.minX, Math.min(sphere.x, box.maxX));
var y = Math.max(box.minY, Math.min(sphere.y, box.maxY));
@@ -125,29 +127,24 @@ translation_of: Games/Techniques/3D_collision_detection
(y - sphere.y) * (y - sphere.y) +
(z - sphere.z) * (z - sphere.z));
- return distance < sphere.radius;
+ return distance < sphere.radius;
}
+```
-
-
-使用一个物理引擎
+## 使用一个物理引擎
-3D physics engines provide collision detection algorithms, most of them based on bounding volumes as well. The way a physics engine works is by creating a physical body, usually attached to a visual representation of it. This body has properties such as velocity, position, rotation, torque, etc., and also a physical shape. This shape is the one that is considered in the collision detection calculations.
+**3D physics engines** provide collision detection algorithms, most of them based on bounding volumes as well. The way a physics engine works is by creating a **physical body**, usually attached to a visual representation of it. This body has properties such as velocity, position, rotation, torque, etc., and also a **physical shape**. This shape is the one that is considered in the collision detection calculations.
-We have prepared a live collision detection demo (with source code) that you can take a look at to see such techniques in action — this uses the open-source 3D physics engine cannon.js.
+We have prepared a [live collision detection demo](http://mozdevs.github.io/gamedev-js-3d-aabb/physics.html) (with [source code](https://github.com/mozdevs/gamedev-js-3d-aabb)) that you can take a look at to see such techniques in action — this uses the open-source 3D physics engine [cannon.js](https://github.com/schteppe/cannon.js).
-See also
+## See also
-Related articles on MDN:
+Related articles on MDN:
-
+- [Bounding volumes collision detection with Three.js](/en-US/docs/Games/Techniques/3D_collision_detection/Bounding_volume_collision_detection_with_THREE.js)
+- [2D collision detection](/en-US/docs/Games/Techniques/2D_collision_detection)
-External resources:
+External resources:
-
+- [Simple intersection tests for games](http://www.gamasutra.com/view/feature/3383/simple_intersection_tests_for_games.php) on Gamasutra
+- [Bounding volume](https://en.wikipedia.org/wiki/Bounding_volume) on Wikipedia
diff --git a/files/zh-cn/games/techniques/3d_on_the_web/basic_theory/index.md b/files/zh-cn/games/techniques/3d_on_the_web/basic_theory/index.md
index 25c985dc81b44d..9761a9eb11e991 100644
--- a/files/zh-cn/games/techniques/3d_on_the_web/basic_theory/index.md
+++ b/files/zh-cn/games/techniques/3d_on_the_web/basic_theory/index.md
@@ -8,115 +8,107 @@ tags:
- 顶点
translation_of: Games/Techniques/3D_on_the_web/Basic_theory
---
-{{GamesSidebar}}
+{{GamesSidebar}}
-这篇文章解释了当你开始使用 3D 工作的时候需要的所有有用的基本理论
+这篇文章解释了当你开始使用 3D 工作的时候需要的所有有用的基本理论
-坐标系统
+## 坐标系统
-3D 指的是有关在 3D 空间中所有形状的表示,并且可以使用坐标系统来计算其位置。
+3D 指的是有关在 3D 空间中所有形状的表示,并且可以使用坐标系统来计算其位置。
-
+![Coordinate system](mdn-games-3d-coordinate-system.png)
-WebGL 使用右手坐标系统 — x
轴向右,y
轴向上 z
轴指向屏幕外,在上图可以看到。
+WebGL 使用右手坐标系统 — `x` 轴向右,`y` 轴向上 `z` 轴指向屏幕外,在上图可以看到。
-物体
+## 物体
-使用顶点建立不同类型的物体。 一个顶点是在 3D 坐标系中拥有坐标位置的一个点以及一些额外可以定义它的信息。 每个点都包含这些属性:
+使用顶点建立不同类型的物体。 **一个顶点**是在 3D 坐标系中拥有坐标位置的一个点以及一些额外可以定义它的信息。 每个点都包含这些属性:
-
- - 位置: 在 3D 空间用来辨认 (
x
, y
, z
).
- - 颜色: 包含 RGBA (R, G 和 B 分别是红,绿,蓝和 alpha 通道,alpha 通道控制透明度 — 所有通道值的范围都是
0.0
到 1.0
).
- - 法线: 描述顶点朝向。
- - 纹理: 顶点用来装饰模型表面的一张 2D 图片,它是代替简单颜色的选择之一。
-
+- **位置**: 在 3D 空间用来辨认 (`x`, `y`, `z`).
+- **颜色**: 包含 RGBA (R, G 和 B 分别是红,绿,蓝和 alpha 通道,alpha 通道控制透明度 — 所有通道值的范围都是 `0.0` 到 `1.0`).
+- **法线:** 描述顶点朝向。
+- **纹理**: 顶点用来装饰模型表面的一张 2D 图片,它是代替简单颜色的选择之一。
-你可以使用这些信息建立几何体 — 这是一个立方体的例子:
+你可以使用这些信息建立几何体 — 这是一个立方体的例子:
-
+![Cube](mdn-games-3d-cube.png)
-给定形状的一个面是顶点之间的一个平面。例如,一个立方体有 8 个不同的顶点和 6 个不同的面 每个面由 4 个顶点构成。一条法线定义面的朝向。同时,连接这些点可以创建立方体的边。这个几何体通过点和面构成,材质使用的是一张纹理贴图,这里使用一个纯蓝色或一张图片。该物体的几何形状 (geometry) 由顶点和面构成,而材质 (material) 则是由纹理构成。如果我们将几何体和材质连接起来会得到一个网格 (mesh).
+给定形状的一个面是顶点之间的一个平面。例如,一个立方体有 8 个不同的顶点和 6 个不同的面 每个面由 4 个顶点构成。一条法线定义面的朝向。同时,连接这些点可以创建立方体的边。这个几何体通过点和面构成,材质使用的是一张纹理贴图,这里使用一个纯蓝色或一张图片。该物体的几何形状 (geometry) 由顶点和面构成,而材质 (material) 则是由纹理构成。如果我们将几何体和材质连接起来会得到一个网格 (mesh).
-渲染流程
+## 渲染流程
-渲染流程是个将之前准备好的模型输出到屏幕的过程。3D 渲染流程会接受使用顶点描述 3D 物体的原始数据作为输入用于处理,并计算其片段 (fragment), 然后渲染为像素 (pixels) 输出到屏幕。
+渲染流程是个将之前准备好的模型输出到屏幕的过程。3D 渲染流程会接受使用顶点描述 3D 物体的原始数据作为输入用于处理,并计算其片段 (fragment), 然后渲染为像素 (pixels) 输出到屏幕。
-
+![Rendering pipeline](mdn-games-3d-rendering-pipeline.png)
-上图中用到了如下术语:
+上图中用到了如下术语:
-
- - 原始数据: 渲染流程中的输入 — 用顶点生成,它可能是三角形,点或线。
- - 片段: 一个像素的 3D 投射,有着和像素一样的属性。
- - 像素: 屏幕上的 2D 网格中的点布置的点,包含 RGBA.
-
+- **原始数据**: 渲染流程中的输入 — 用顶点生成,它可能是三角形,点或线。
+- **片段**: 一个像素的 3D 投射,有着和像素一样的属性。
+- **像素**: 屏幕上的 2D 网格中的点布置的点,包含 RGBA.
-顶点和片段处理是可编程的 — 你可以编写自己的着色器 来控制输出。
+顶点和片段处理是可编程的 — 你可以[编写自己的着色器](/zh-CN/docs/Games/Techniques/3D_on_the_web/GLSL_Shaders) 来控制输出。
-顶点处理
+## 顶点处理
-顶点处理是将独立的顶点信息组合成原始数据并设置其在 3D 空间中的坐标,方便显示器识别。就像是对你准备的场景进行拍照 — 你必须先放置物品,设置相机参数,然后开拍。
+顶点处理是将独立的顶点信息组合成原始数据并设置其在 3D 空间中的坐标,方便显示器识别。就像是对你准备的场景进行拍照 — 你必须先放置物品,设置相机参数,然后开拍。
-
+![Vertex processing](mdn-games-3d-vertex-processing.png)
-这个过程分为四步:第一步是筹备世界坐标中的物体,也被称为模型转换 (model transformation). 然后是视图转换 (view transformation) , 这一步只关心位置和 3D 空间中摄像机的朝向设置。摄像机有三个参数 (位置,方向和朝向), 在新创建的场景中必须定义这三个参数。
+这个过程分为四步:第一步是筹备世界坐标中的物体,也被称为**模型转换 (model transformation)**. 然后是**视图转换 (view transformation)** , 这一步只关心位置和 3D 空间中摄像机的朝向设置。摄像机有三个参数 (位置,方向和朝向), 在新创建的场景中必须定义这三个参数。
-
+![Camera](mdn-games-3d-camera.png)
-投射转换(projection transformation), 也被称作透视转换 (perspective transformation), 这一步定义摄像机设置,在此过程会设置哪些在摄像机中可见,配置包含视野 (field of view), 宽高比例 (aspect ratio) 和可选的近裁剪和远裁剪参数。阅读 Three.js 文章摄像机了解更多。
+**投射转换**(projection transformation), 也被称作透视转换 (perspective transformation), 这一步定义摄像机设置,在此过程会设置哪些在摄像机中可见,配置包含视野 (field of view), 宽高比例 (aspect ratio) 和可选的近裁剪和远裁剪参数。阅读 Three.js 文章[摄像机](/en-US/docs/Games/Techniques/3D_on_the_web/Building_up_a_basic_demo_with_Three.js#Camera)了解更多。
-
+![Camera settings](mdn-games-3d-camera-settings.png)
-最后一步是视图窗口转换(viewport transformation), 这一步会将一切都输出给渲染流程中的下一步。
+最后一步是**视图窗口转换**(viewport transformation), 这一步会将一切都输出给渲染流程中的下一步。
-栅格化
+## 栅格化
-栅格化将原始数据 (从顶点信息转换过来的) 转换为一系列的片段。
+栅格化将原始数据 (从顶点信息转换过来的) 转换为一系列的片段。
-
+![Rasterization](mdn-games-3d-rasterization.png)
-那些片段 (2D 像素的 3D 投射) 是对应到像素网格的,所以在渲染合成阶段最后他们会被 2D 的屏幕直接打印到像素点上。
+那些片段 (2D 像素的 3D 投射) 是对应到像素网格的,所以在渲染合成阶段最后他们会被 2D 的屏幕直接打印到像素点上。
-片段合成
+## 片段合成
-片段合成关注关注的是纹理和光照 — 它会基于给定参数计算最终的颜色。
+片段合成关注关注的是纹理和光照 — 它会基于给定参数计算最终的颜色。
-
+![Fragment processing](mdn-games-3d-fragment-processing.png)
-纹理
+### 纹理
-纹理是在 3D 空间中用了是模型看起来更加真实的 2D 图片。纹理是由称为纹素的单个纹理元素组合,和像素组合的原理一样。如果必要的话,在渲染流程中的片段处理阶段添加纹理到模型上允许我们使用包装 (wrapping) 和过滤 (filtering) 进行适配。
+纹理是在 3D 空间中用了是模型看起来更加真实的 2D 图片。纹理是由称为纹素的单个纹理元素组合,和像素组合的原理一样。如果必要的话,在渲染流程中的片段处理阶段添加纹理到模型上允许我们使用包装 (wrapping) 和过滤 (filtering) 进行适配。
-纹理包装允许你在 3D 模型上重复使用 2D 图片。纹理过滤是纹理贴图的原始分辨率和将要呈现的片段的分辨率不同的时候,会根据情况对纹理进行缩放。
+纹理包装允许你在 3D 模型上重复使用 2D 图片。纹理过滤是纹理贴图的原始分辨率和将要呈现的片段的分辨率不同的时候,会根据情况对纹理进行缩放。
-光照
+### 光照
-我们在屏幕上看到的颜色是光照和模型颜色,材质进行交互之后的最终结果。灯光会被吸收和反射,在 WebGL 中实现的标准Phong 光照模型 有一下四种光照参数:
+我们在屏幕上看到的颜色是光照和模型颜色,材质进行交互之后的最终结果。灯光会被吸收和反射,在 WebGL 中实现的标准**Phong 光照模型** 有一下四种光照参数:
-
- - 漫反射: 遥远的直接光照,就像太阳。
- - 高光: 点光源,就像房间的白炽灯或闪光灯。
- - 环境色: 常量灯光,可影响场景中的所有模型。
- - 自发光: 模型自身发出的光。
-
+- **漫反射**: 遥远的直接光照,就像太阳。
+- **高光**: 点光源,就像房间的白炽灯或闪光灯。
+- **环境色**: 常量灯光,可影响场景中的所有模型。
+- **自发光**: 模型自身发出的光。
-输出合成
+## 输出合成
-在输出操作阶段所有来自 3D 空间的原始数据的片段会被转换到 2D 像素网格中,然后打印到屏幕像素上。
+在输出操作阶段所有来自 3D 空间的原始数据的片段会被转换到 2D 像素网格中,然后打印到屏幕像素上。
-
+![Output merging](mdn-games-3d-output-merging.png)
-在输出合成阶段同样可以忽略不必要的信息,例如在屏幕外的模型参数或者被其他模型遮挡的模型,因为是不可见的所以不会被计算。
+在输出合成阶段同样可以忽略不必要的信息,例如在屏幕外的模型参数或者被其他模型遮挡的模型,因为是不可见的所以不会被计算。
-总结
+## 总结
-现在你知道了 3D 操作背后的基本原理。如果你想去练习或者看学习 demo, 看看下面的教程:
+现在你知道了 3D 操作背后的基本原理。如果你想去练习或者看学习 demo, 看看下面的教程:
-
+- [用 Three.js 创建基本 demo](/en-US/docs/Games/Techniques/3D_on_the_web/Building_up_a_basic_demo_with_Three.js)
+- [用 Babylon.js 创建基本 demo](/en-US/docs/Games/Techniques/3D_on_the_web/Building_up_a_basic_demo_with_Babylon.js)
+- [用 PlayCanvas 创建基本 demo](/en-US/docs/Games/Techniques/3D_on_the_web/Building_up_a_basic_demo_with_PlayCanvas)
+- [用 A-Frame 创建基本 demo](/en-US/docs/Games/Techniques/3D_on_the_web/Building_up_a_basic_demo_with_A-Frame)
-继续,去创建一些炫酷 3D 实验吧!
+继续,去创建一些炫酷 3D 实验吧!
diff --git a/files/zh-cn/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_three.js/index.md b/files/zh-cn/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_three.js/index.md
index 5e2d847f1a3c26..32716d1ba99a43 100644
--- a/files/zh-cn/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_three.js/index.md
+++ b/files/zh-cn/games/techniques/3d_on_the_web/building_up_a_basic_demo_with_three.js/index.md
@@ -3,256 +3,268 @@ title: Building up a basic demo with Three.js
slug: Games/Techniques/3D_on_the_web/Building_up_a_basic_demo_with_Three.js
translation_of: Games/Techniques/3D_on_the_web/Building_up_a_basic_demo_with_Three.js
---
-{{GamesSidebar}}
游戏中一个典型的 3D 场景 (最简单的那种) 包含标准的物品比如在坐标轴中的形状,一个实际可看到他们的摄像机,灯光和材质让其看起来不错,动画使其生动等等。 Three.js, 和其他 3D 库一样,提供内置的 helper 函数来帮助你尽可能快地实现通用的 3D 功能 . 在这篇文章我们会带你了解使用 Three 的基本知识,包含设置开发者环境,必要的 HTML 结构,Three.js 对象基础,以及如何创建一个基本的 demo.
+{{GamesSidebar}}
-
+游戏中一个典型的 3D 场景 (最简单的那种) 包含标准的物品比如在坐标轴中的形状,一个实际可看到他们的摄像机,灯光和材质让其看起来不错,动画使其生动等等。 **Three.js**, 和其他 3D 库一样,提供内置的 helper 函数来帮助你尽可能快地实现通用的 3D 功能 . 在这篇文章我们会带你了解使用 Three 的基本知识,包含设置开发者环境,必要的 HTML 结构,Three.js 对象基础,以及如何创建一个基本的 demo.
-环境设置
+> **备注:** 我们选择 Three.js 因为它是最流行的[WebGL](/en-US/docs/Web/API/WebGL_API) 库之一,并且很容易上手。我们不会介绍任何其他更好的 WebGL 库,你可以自由选择其他库做尝试,比如 [CopperLicht](http://www.ambiera.com/copperlicht/index.html), [GLGE](http://www.glge.org/), [OSG.js](http://osgjs.org/), [O3D](https://code.google.com/p/o3d/), 或者其他你喜欢的库。
-开始用 Three.js, 你不需要准备太多,只需:
+## 环境设置
-
- - 确保使用的支持 WebGL 的现代浏览器,例如最新版的 Firefox 或 Chrome.
- - 创建一个目录保存例子。
- - 复制最新的压缩版 Three.js 到你的目录。
- - 用单独的浏览器 tab 打开 Three.js 文档 — 对应参考很有用。
-
+开始用 Three.js, 你不需要准备太多,只需:
-HTML 结构
+- 确保使用的支持 [WebGL](/en-US/docs/Web/API/WebGL_API) 的现代浏览器,例如最新版的 Firefox 或 Chrome.
+- 创建一个目录保存例子。
+- 复制最新的压缩版[ Three.js](http://threejs.org/build/three.min.js) 到你的目录。
+- 用单独的浏览器 tab 打开 [Three.js ](http://threejs.org/docs/)文档 — 对应参考很有用。
-这是将用到的 HTML 结构。
+## HTML 结构
-<!DOCTYPE html>
-<html>
-<head>
- <meta charset="utf-8">
- <title>MDN Games: Three.js demo</title>
- <style>
+这是将用到的 HTML 结构。
+
+```html
+
+
+
+
+ MDN Games: Three.js demo
+
+
+
+
+
+
+
+```
-It contains some basic information like the document {{htmlelement("title")}}, and some CSS to set the width
and height
of the {{htmlelement("canvas")}} element that Three.js will insert on the page to 100% so that it will fill the entire available viewport space. The first {{htmlelement("script")}} element includes the Three.js library in the page, and we will write our example code into the second one. There are two helper variables already included, which store the window's width
and height
.
+It contains some basic information like the document {{htmlelement("title")}}, and some CSS to set the `width` and `height` of the {{htmlelement("canvas")}} element that Three.js will insert on the page to 100% so that it will fill the entire available viewport space. The first {{htmlelement("script")}} element includes the Three.js library in the page, and we will write our example code into the second one. There are two helper variables already included, which store the window's `width` and `height`.
-Before reading on, copy this code to a new text file, and save it in your working directory as index.html
.
+Before reading on, copy this code to a new text file, and save it in your working directory as `index.html`.
-渲染器
+## 渲染器
-A renderer is a tool that displays scenes right in your browser. There are a few different renderers: WebGL is the default one, and the others you can use are Canvas, SVG, CSS and DOM. They differ in a way everything is rendered, so the WebGL implementation will work differently than the CSS one, but the idea is to have it look exactly the same for the end user. Thanks to this approach, a fallback can be used if the primary technology is not supported by the browser.
+A renderer is a tool that displays scenes right in your browser. There are a few different renderers: WebGL is the default one, and the others you can use are Canvas, SVG, CSS and DOM. They differ in a way everything is rendered, so the WebGL implementation will work differently than the CSS one, but the idea is to have it look exactly the same for the end user. Thanks to this approach, a fallback can be used if the primary technology is not supported by the browser.
-var renderer = new THREE.WebGLRenderer({antialias:true});
+```js
+var renderer = new THREE.WebGLRenderer({antialias:true});
renderer.setSize(WIDTH, HEIGHT);
renderer.setClearColor(0xDDDDDD, 1);
document.body.appendChild(renderer.domElement);
-
+```
-We are creating a new WebGL renderer, setting it's size to fit the whole available space on the screen and appending the DOM structure to the page. You probably noticed the antialias
parameter in the first line — this enables the edges of the shapes to be rendered a little more smoothly. The setClearColor()
method sets our background to a light gray colour instead of the default black one.
+We are creating a new WebGL renderer, setting it's size to fit the whole available space on the screen and appending the DOM structure to the page. You probably noticed the `antialias` parameter in the first line — this enables the edges of the shapes to be rendered a little more smoothly. The `setClearColor()` method sets our background to a light gray colour instead of the default black one.
-Add this code into the second {{htmlelement("script")}} element, just below the JavaScript comment.
+Add this code into the second {{htmlelement("script")}} element, just below the JavaScript comment.
-场景
+## 场景
-A scene is the place where everything happens. When creating new objects in the demo, we will be adding them all to the scene to make them visible on the screen. In three.js, the scene is reperesented by a Scene
object. Let's create it, by adding the following line below our previous lines:
+A scene is the place where everything happens. When creating new objects in the demo, we will be adding them all to the scene to make them visible on the screen. In three.js, the scene is reperesented by a `Scene` object. Let's create it, by adding the following line below our previous lines:
-var scene = new THREE.Scene();
-
+```js
+var scene = new THREE.Scene();
+```
-Later on we will be using the .add()
method to add objects to the scene.
+Later on we will be using the `.add()` method to add objects to the scene.
-摄像机
+## 摄像机
-我们有渲染场景,但是我们仍然需要一个摄像机来观察场景 - 想象没有摄像机的电影场景。下面的代码将摄像机放在三维坐标系中,并将其指向我们的场景,这样人们就能看到一些东西:
+我们有渲染场景,但是我们仍然需要一个摄像机来观察场景 - 想象没有摄像机的电影场景。下面的代码将摄像机放在三维坐标系中,并将其指向我们的场景,这样人们就能看到一些东西:
-var camera = new THREE.PerspectiveCamera(70, WIDTH/HEIGHT);
+```js
+var camera = new THREE.PerspectiveCamera(70, WIDTH/HEIGHT);
camera.position.z = 50;
scene.add(camera);
-
+```
-Add these lines to your code, below the prevous ones.
+Add these lines to your code, below the prevous ones.
-There are other types of camera available (Cube, Orthographic), but the simplest is the Perspective one. To initialize it we have to set its field of view and aspect ratio — the first one is used to set how much is seen, and a proper aspect ratio is important for the objects on the screen to have the right proportions when rendered and not look stretched. Let's explain the values we are setting in the code above:
+There are other types of camera available (Cube, Orthographic), but the simplest is the Perspective one. To initialize it we have to set its field of view and aspect ratio — the first one is used to set how much is seen, and a proper aspect ratio is important for the objects on the screen to have the right proportions when rendered and not look stretched. Let's explain the values we are setting in the code above:
-
- - The value we set for the field of view, 70, is something we can experiment with — the higher the value, the greater the amount of scene the camera will show. Imagine a normal camera view, versus a fish eye effect, which allows a lot more to be seen. The default value is 50.
- - The aspect ratio is set to the current width and height of the window so it will be dynamically adjusted. We could set a fixed ratio — for example 16 ⁄ 9, which is the aspect ratio of a widescreen TV. The default value is 1.
- - The
z
position with the value of 50 units is the distance between the camera and the center of the scene on the z
axis — here we're moving the camera back so the objects on the scene can be viewed. 50 feels ok as it's not too near and not too far and the sizes of the objects allow them to stay on the scene within the given field of view. The x
and y
values, if not specified, will default to 0.
-
+- The value we set for the field of view, 70, is something we can experiment with — the higher the value, the greater the amount of scene the camera will show. Imagine a normal camera view, versus a fish eye effect, which allows a lot more to be seen. The default value is 50.
+- The aspect ratio is set to the current width and height of the window so it will be dynamically adjusted. We could set a fixed ratio — for example 16 ⁄ 9, which is the aspect ratio of a widescreen TV. The default value is 1.
+- The `z` position with the value of 50 units is the distance between the camera and the center of the scene on the `z` axis — here we're moving the camera back so the objects on the scene can be viewed. 50 feels ok as it's not too near and not too far and the sizes of the objects allow them to stay on the scene within the given field of view. The `x` and `y` values, if not specified, will default to 0.
-You should experiment with these values and see how they change what you see in the scene.
+You should experiment with these values and see how they change what you see in the scene.
-
-
备注: The distance values (e.g. for the camera z position) are unitless, and can basically be anything you deem suitable for your scene — milimeters, meters, feet, or miles — it's up to you.
-
+> **备注:** The distance values (e.g. for the camera z position) are unitless, and can basically be anything you deem suitable for your scene — milimeters, meters, feet, or miles — it's up to you.
-Rendering the scene
+## Rendering the scene
-Everything is ready, but we still can't see anything. Although we set the renderer up, we still have to actually render everything. Our render()
function will do this job, with a little help from requestAnimationFrame()
, which causes the scene to be re-rendered constantly on every frame:
+Everything is ready, but we still can't see anything. Although we set the renderer up, we still have to actually render everything. Our `render()` function will do this job, with a little help from [`requestAnimationFrame()`](/en-US/docs/Web/API/window/requestAnimationFrame), which causes the scene to be re-rendered constantly on every frame:
-function render() {
+```js
+function render() {
requestAnimationFrame(render);
renderer.render(scene, camera);
}
render();
-
+```
-On every new frame the render
function is invoked and the renderer
renders the scene
and the camera
. Right after the function declaration we're invoking it for the first time to start the loop, after which it will be used indefinitely.
+On every new frame the `render` function is invoked and the `renderer` renders the `scene` and the `camera`. Right after the function declaration we're invoking it for the first time to start the loop, after which it will be used indefinitely.
-Again add the new code below your previous additions, then try saving the file and loading it in your browser. You should now see a gray window. Congratulations!
+Again add the new code below your previous additions, then try saving the file and loading it in your browser. You should now see a gray window. Congratulations!
-Geometry
+## Geometry
-Now the scene is properly rendering we can start adding 3D shapes to it. To speed up development Three.js provides a bunch of predefined primitives that you can to create shapes instantly in a single line of code. There's cubes, spheres, cylinders and more complicated shapes available. Drawing the needed vertices and faces for given shape is taken care of by the framework, so we can focus on the high level coding. Let's start by defining the geometry for a cube shape — add the following just above the render()
function:
+Now the scene is properly rendering we can start adding 3D shapes to it. To speed up development Three.js provides a bunch of predefined primitives that you can to create shapes instantly in a single line of code. There's cubes, spheres, cylinders and more complicated shapes available. Drawing the needed vertices and faces for given shape is taken care of by the framework, so we can focus on the high level coding. Let's start by defining the geometry for a cube shape — add the following just above the `render()` function:
-var boxGeometry = new THREE.BoxGeometry(10, 10, 10);
-
+```js
+var boxGeometry = new THREE.BoxGeometry(10, 10, 10);
+```
-In this case we define a simple cube that is 10 x 10 x 10 units. The geometry itself is not enough though — we also need a material that will be used for our shape.
+In this case we define a simple cube that is 10 x 10 x 10 units. The geometry itself is not enough though — we also need a material that will be used for our shape.
-Material
+## Material
-Material is that thing covering the object — the colors or texture on its surface. In our case we will use a simple blue color to paint our box. There are predefined materials that can be used: Basic, Phong, Lambert. We will play with the last two later on, but for now the Basic one should be enough:
+Material is that thing covering the object — the colors or texture on its surface. In our case we will use a simple blue color to paint our box. There are predefined materials that can be used: Basic, Phong, Lambert. We will play with the last two later on, but for now the Basic one should be enough:
-var basicMaterial = new THREE.MeshBasicMaterial({color: 0x0095DD});
-
+```js
+var basicMaterial = new THREE.MeshBasicMaterial({color: 0x0095DD});
+```
-Add this line below the previous one.
+Add this line below the previous one.
-Our material is ready, but what to do next?
+Our material is ready, but what to do next?
-Mesh
+## Mesh
-To apply the material to a geometry a mesh is used. It takes a shape and adds the specified material to every face:
+To apply the material to a geometry a mesh is used. It takes a shape and adds the specified material to every face:
-var cube = new THREE.Mesh(boxGeometry, basicMaterial);
-
+```js
+var cube = new THREE.Mesh(boxGeometry, basicMaterial);
+```
-Again, add this line below the previous one.
+Again, add this line below the previous one.
-Adding the cube to the scene
+## Adding the cube to the scene
-We've now created the actual cube using the geometry and material defined earlier. The last thing to do is to actually add the cube to our scene — add this line below the previous one:
+We've now created the actual cube using the geometry and material defined earlier. The last thing to do is to actually add the cube to our scene — add this line below the previous one:
-scene.add(cube);
-
+```js
+scene.add(cube);
+```
-If you save and refresh now, your object will look like a square, because it's facing the camera. The good thing about objects is that we can move them on the scene however we want, for example rotating and scaling as we like. Let's apply a little bit of rotation to the cube, so we can see more than one face — again, add below the previous one:
+If you save and refresh now, your object will look like a square, because it's facing the camera. The good thing about objects is that we can move them on the scene however we want, for example rotating and scaling as we like. Let's apply a little bit of rotation to the cube, so we can see more than one face — again, add below the previous one:
-cube.rotation.set(0.4, 0.2, 0);
-
+```js
+cube.rotation.set(0.4, 0.2, 0);
+```
-Congratulations, you've created your first object in a 3D environment! It was easier than you thought, right? Here's how it should look:
+Congratulations, you've created your first object in a 3D environment! It was easier than you thought, right? Here's how it should look:
-
+![Blue cube on a gray background rendered with Three.js.](cube.png)
-And here's the code we have created so far:
+And here's the code we have created so far:
-{{JSFiddleEmbed("https://jsfiddle.net/end3r/bwup75fa/","","350")}}
+{{JSFiddleEmbed("https://jsfiddle.net/end3r/bwup75fa/","","350")}}
-You can also check it out on GitHub.
+You can also [check it out on GitHub](https://github.com/end3r/MDN-Games-3D/blob/gh-pages/Three.js/cube.html).
-More shapes and materials
+## More shapes and materials
-Now we will add more shapes to the scene and explore other shapes, materials, lighting, and more. Let's move the cube to the left to make space for some friends — add the following line just below the previous one:
+Now we will add more shapes to the scene and explore other shapes, materials, lighting, and more. Let's move the cube to the left to make space for some friends — add the following line just below the previous one:
-cube.position.x = -25;
-
+```js
+cube.position.x = -25;
+```
-Now onto the shapes and materials: what would you say for a torus using the Phong material? Try adding the following lines just below the lines that define the cube.
+Now onto the shapes and materials: what would you say for a torus using the Phong material? Try adding the following lines just below the lines that define the cube.
-var torusGeometry = new THREE.TorusGeometry(7, 1, 6, 12);
+```js
+var torusGeometry = new THREE.TorusGeometry(7, 1, 6, 12);
var phongMaterial = new THREE.MeshPhongMaterial({color: 0xFF9500});
var torus = new THREE.Mesh(torusGeometry, phongMaterial);
scene.add(torus);
-
+```
-Thee lines will add a torus geometry; the TorusGeometry()
method's parameters define and the parameters are radius
, tube diameter
, radial segment count
and tubular segment count
. The Phong material should look more glossy than the simple color of the box that was using the Basic material, although at the moment it will just look black.
+Thee lines will add a torus geometry; the `TorusGeometry()` method's parameters define and the parameters are `radius`, `tube diameter`, `radial segment count` and `tubular segment count`. The Phong material should look more glossy than the simple color of the box that was using the Basic material, although at the moment it will just look black.
-We can have even crazier predefined shapes; let's play some more — add the following lines below the ones that defined the torus:
+We can have even crazier predefined shapes; let's play some more — add the following lines below the ones that defined the torus:
-var dodecahedronGeometry = new THREE.DodecahedronGeometry(7);
+```js
+var dodecahedronGeometry = new THREE.DodecahedronGeometry(7);
var lambertMaterial = new THREE.MeshLambertMaterial({color: 0xEAEFF2});
var dodecahedron = new THREE.Mesh(dodecahedronGeometry, lambertMaterial);
dodecahedron.position.x = 25;
scene.add(dodecahedron);
-
+```
-This time we are creating a dodecahedron, which is a shape containing twelve flat faces. The parameter DodecahedronGeometry()
takes is the size of the object. We're using a Lambert material here, which is similar to Phong, but should be less glossy (again, black for now.) We're moving the object to the right, so it's not in the same place as the box or torus.
+This time we are creating a dodecahedron, which is a shape containing twelve flat faces. The parameter `DodecahedronGeometry()` takes is the size of the object. We're using a Lambert material here, which is similar to Phong, but should be less glossy (again, black for now.) We're moving the object to the right, so it's not in the same place as the box or torus.
-As mentioned above, the new objects currently just look black. To have both the Phong and Lambert materials properly visible we need a source of light.
+As mentioned above, the new objects currently just look black. To have both the Phong and Lambert materials properly visible we need a source of light.
-Lights
+## Lights
-There are various types of light sources available in Three.js; the most basic one is the PointLight
, which works like a flashlight — shinig a spotlight in a given direction. Add the following below your shapre definitions:
+There are various types of light sources available in Three.js; the most basic one is the `PointLight`, which works like a flashlight — shinig a spotlight in a given direction. Add the following below your shapre definitions:
-var light = new THREE.PointLight(0xFFFFFF);
+```js
+var light = new THREE.PointLight(0xFFFFFF);
light.position.set(-10, 15, 50);
scene.add(light);
-
+```
-We define a white point of light, set it's position a bit away from the center of the scene so it can light up some parts of the shapes, and add it to the scene. Now everything works as it should — all three shapes are visible. You should check the documentation for other types of light like Ambient, Directional, Hemisphere or Spot, and experiment with placing them on the scene to see the effects.
+We define a white point of light, set it's position a bit away from the center of the scene so it can light up some parts of the shapes, and add it to the scene. Now everything works as it should — all three shapes are visible. You should check the documentation for other types of light like Ambient, Directional, Hemisphere or Spot, and experiment with placing them on the scene to see the effects.
-
+![Shapes: blue cube, dark yellow torus and dark gray dodecahedron on a gray background rendered with Three.js.](shapes.png)
-This looks a little bit boring though. In a game something is usually happening — we can see animations and such — so let's try to breathe a little life into those shapes by animating them.
+This looks a little bit boring though. In a game something is usually happening — we can see animations and such — so let's try to breathe a little life into those shapes by animating them.
-Animation
+## Animation
-We already used rotation to adjust the position of the cube; we could also scale the shapes, or change thier positions. To show actual animation, we need to make changes to these values inside the render loop so, they are updated on every frame.
+We already used rotation to adjust the position of the cube; we could also scale the shapes, or change thier positions. To show actual animation, we need to make changes to these values inside the render loop so, they are updated on every frame.
-Rotation
+### Rotation
-Rotating is quite easy — all you need to do is to add a defined value to the given direction of the rotation on each frame. Add this line of code right after the requestAnimationFrame()
invocation in the render
function:
+Rotating is quite easy — all you need to do is to add a defined value to the given direction of the rotation on each frame. Add this line of code right after the `requestAnimationFrame()` invocation in the `render` function:
-cube.rotation.y += 0.01;
-
+```js
+cube.rotation.y += 0.01;
+```
-It will rotate the cube on every frame by a tiny bit, so it will look like a smooth animation.
+It will rotate the cube on every frame by a tiny bit, so it will look like a smooth animation.
-Scaling
+### Scaling
-We can also scale a given object. By applying a constant value we could make it grow or shrink once, but let's make it more interesting. First, we will need a helper variable called t
for counting the elapsed time. Add it right before the render()
function:
+We can also scale a given object. By applying a constant value we could make it grow or shrink once, but let's make it more interesting. First, we will need a helper variable called `t` for counting the elapsed time. Add it right before the `render()` function:
-var t = 0;
-
+```js
+var t = 0;
+```
-Now let's increase the value by a given constant value on each frame of the animation; add the following lines just below the requestAnimationFrame()
invocation:
+Now let's increase the value by a given constant value on each frame of the animation; add the following lines just below the `requestAnimationFrame()` invocation:
-t += 0.01;
+```js
+t += 0.01;
torus.scale.y = Math.abs(Math.sin(t));
-
+```
-This way we'll be able to use Math.sin
and end up with quite an interesting result: this will scale the torus and repeat the whole process, as sin
is a periodic function. We're wrapping the scale value in Math.abs
to pass the absolute values (greater or equal to 0), because sin is between -1 and 0, and for negative values the torus might render unexpectedly (in this case it looks black half the time.)
+This way we'll be able to use `Math.sin` and end up with quite an interesting result: this will scale the torus and repeat the whole process, as `sin` is a periodic function. We're wrapping the scale value in `Math.abs` to pass the absolute values (greater or equal to 0), because sin is between -1 and 0, and for negative values the torus might render unexpectedly (in this case it looks black half the time.)
-Now onto the movement part.
+Now onto the movement part.
-Moving
+### Moving
-Beside rotation and scaling we can also move objects around the scene. Add the following, again just below the requestAnimationFrame()
invocation:
+Beside rotation and scaling we can also move objects around the scene. Add the following, again just below the `requestAnimationFrame()` invocation:
-dodecahedron.position.y = -7*Math.sin(t*2);
-
+```js
+dodecahedron.position.y = -7*Math.sin(t*2);
+```
-This will move the dodecahedron up and down by applying the sin()
value to the y axis on each frame, with a little bit of adjustment to make it look cooler. Try changing the values to see how it affects the animations.
+This will move the dodecahedron up and down by applying the `sin()` value to the y axis on each frame, with a little bit of adjustment to make it look cooler. Try changing the values to see how it affects the animations.
-Conclusion
+## Conclusion
-Here's the final piece of the code:
+Here's the final piece of the code:
-{{JSFiddleEmbed("https://jsfiddle.net/rybr720u/","","350")}}
+{{JSFiddleEmbed("https://jsfiddle.net/rybr720u/","","350")}}
-You can also see it on GitHub and fork the repository if you want to play with it yourself locally. Now you know the basics of Three.js, you can get back to the parent page about 3D on the Web.
+You can also [see it on GitHub](https://github.com/end3r/MDN-Games-3D/blob/gh-pages/Three.js/shapes.html) and [fork the repository](https://github.com/end3r/MDN-Games-3D/) if you want to play with it yourself locally. Now you know the basics of Three.js, you can get back to the parent page about [3D on the Web](/en-US/docs/Games/Techniques/3D_on_the_web).
-You should also try learning raw WebGL, so you can get a better understanding of what's going on. See our WebGL documentation.
+You should also try learning raw WebGL, so you can get a better understanding of what's going on. See our [WebGL documentation](/en-US/docs/Web/API/WebGL_API).
diff --git a/files/zh-cn/games/techniques/3d_on_the_web/glsl_shaders/index.md b/files/zh-cn/games/techniques/3d_on_the_web/glsl_shaders/index.md
index 9ef41dd573c6f6..83c5d77811761c 100644
--- a/files/zh-cn/games/techniques/3d_on_the_web/glsl_shaders/index.md
+++ b/files/zh-cn/games/techniques/3d_on_the_web/glsl_shaders/index.md
@@ -8,173 +8,174 @@ tags:
- 顶点着色器
translation_of: Games/Techniques/3D_on_the_web/GLSL_Shaders
---
-{{GamesSidebar}}
使用 GLSL 的着色器 (shader), GLSL 是一门特殊的有着类似于 C 语言的语法,在图形管道 (graphic pipeline) 中直接可执行的 OpenGL 着色语言。着色器有两种类型 -- 顶点着色器 (Vertex Shader) 和片段着色器 (Fragment Shader). 前者是将形状转换到真实的 3D 绘制坐标中,后者是计算最终渲染的颜色和其他属性用的。
+{{GamesSidebar}}
-GLSL 不同于 JavaScript, 它是强类型语言,并且内置很多数学公式用于计算向量和矩阵。快速编写着色器非常复杂,但创建一个简单的着色器并不难。在这篇文章我们将介绍使用着色器的基础知识,并且构建一个使用 Three.js 的例子来加速代码编写。
+使用 GLSL 的着色器 (shader), GLSL 是一门特殊的有着类似于 C 语言的语法,在图形管道 (graphic pipeline) 中直接可执行的 OpenGL 着色语言。着色器有两种类型 -- 顶点着色器 (Vertex Shader) 和片段着色器 (Fragment Shader). 前者是将形状转换到真实的 3D 绘制坐标中,后者是计算最终渲染的颜色和其他属性用的。
-你可能记得基本原理那篇文章,一个顶点 (vertex) 是在空间中有自己 3D 坐标的点,并且通常包含些被定义的其他信息。空间本身会被坐标系统定义。在那个 3D 空间中一切都是关于形状的呈现。
+GLSL 不同于 JavaScript, 它是强类型语言,并且内置很多数学公式用于计算向量和矩阵。快速编写着色器非常复杂,但创建一个简单的着色器并不难。在这篇文章我们将介绍使用着色器的基础知识,并且构建一个使用 Three.js 的例子来加速代码编写。
-着色器类型
+你可能记得[基本原理](/en-US/docs/Games/Techniques/3D_on_the_web/Basic_theory)那篇文章,一个顶点 (vertex) 是在空间中有自己 3D 坐标的点,并且通常包含些被定义的其他信息。空间本身会被坐标系统定义。在那个 3D 空间中一切都是关于形状的呈现。
-一个着色器实际上就是一个绘制东西到屏幕上的函数。着色器运行在 GPU 中,它对这些操作进行了很多的优化,这样你就可以卸载很多不必要的 CPU, 然后集中处理能力去执行你自己的代码。
+## 着色器类型
-顶点着色器
+一个着色器实际上就是一个绘制东西到屏幕上的函数。着色器运行在 GPU 中,它对这些操作进行了很多的优化,这样你就可以卸载很多不必要的 CPU, 然后集中处理能力去执行你自己的代码。
-顶点着色器操作 3D 空间的坐标并且每个顶点都会调用一次这个函数。其目的是设置 gl_Position
变量 -- 这是一个特殊的全局内置变量,它是用来存储当前顶点的位置:
+### 顶点着色器
-void main() {
+顶点着色器操作 3D 空间的坐标并且每个顶点都会调用一次这个函数。其目的是设置 `gl_Position` 变量 -- 这是一个特殊的全局内置变量,它是用来存储当前顶点的位置:
+
+```glsl
+void main() {
gl_Position = makeCalculationsToHaveCoordinates;
}
-
+```
-这个 void main()
函数是定义全局gl_Position
变量的标准方式。所有在这个函数里面的代码都会被着色器执行。 如果将 3D 空间中的位置投射到 2D 屏幕上这些信息都会保存在计算结果的变量中。
+这个 `void main()` 函数是定义全局`gl_Position` 变量的标准方式。所有在这个函数里面的代码都会被着色器执行。 如果将 3D 空间中的位置投射到 2D 屏幕上这些信息都会保存在计算结果的变量中。
-片段着色器
+### 片段着色器
-片段 (或者纹理) 着色器 在计算时定义了每像素的 RGBA 颜色 — 每个像素只调用一次片段着色器。这个着色器的作用是设置 gl_FragColor
变量,也是一个 GLSL 内置变量:
+片段 (或者纹理) 着色器 在计算时定义了每像素的 RGBA 颜色 — 每个像素只调用一次片段着色器。这个着色器的作用是设置 `gl_FragColor` 变量,也是一个 GLSL 内置变量:
-void main() {
+```glsl
+void main() {
gl_FragColor = makeCalculationsToHaveColor;
}
-
+```
-计算结果包含 RGBA 颜色信息。
+计算结果包含 RGBA 颜色信息。
-例子
+## 例子
-让我们构建一个简单的例子来解释这些着色器的动作。假设你已经看过Three.js 教程并掌握了场景,物体和材质的基本概念。
+让我们构建一个简单的例子来解释这些着色器的动作。假设你已经看过[Three.js 教程](/en-US/docs/Games/Techniques/3D_on_the_web/Building_up_a_basic_demo_with_Three.js)并掌握了场景,物体和材质的基本概念。
-
-
备注: 记住你没必要使用 Three.js 或者其他库来编写着色器 -- 纯WebGL 完全够了。我们这里使用 Three.js 来制作背景代码更简单和易理解。所以你只需关注着色器代码。Three.js 和其他 3D 库给你抽象了很多东西出来 -- 如果你想要用纯 WebGL 创建这个例子,你得写很多其他的代码才能运行。
-
+> **备注:** 记住你没必要使用 Three.js 或者其他库来编写着色器 -- 纯[WebGL](/en-US/docs/Web/API/WebGL_API) 完全够了。我们这里使用 Three.js 来制作背景代码更简单和易理解。所以你只需关注着色器代码。Three.js 和其他 3D 库给你抽象了很多东西出来 -- 如果你想要用纯 WebGL 创建这个例子,你得写很多其他的代码才能运行。
-环境设置
+### 环境设置
-要开始编写 WebGL 着色器你不需要做太多,只需:
+要开始编写 WebGL 着色器你不需要做太多,只需:
-
- - 确保你在使用对 WebGL 有良好支持的现代浏览器,比如最新版的 Firefox 或 Chrome.
- - 创建一个目录保存你的实验。
- - 拷贝一份的 压缩版的 Three.js 库 到你的目录。
-
+- 确保你在使用对 [WebGL](/en-US/docs/Web/API/WebGL_API) 有良好支持的现代浏览器,比如最新版的 Firefox 或 Chrome.
+- 创建一个目录保存你的实验。
+- 拷贝一份的 [压缩版的 Three.js 库](http://threejs.org/build/three.min.js) 到你的目录。
-HTML 结构
+### HTML 结构
-这是将用到的 HTML 结构。
+这是将用到的 HTML 结构。
-<!DOCTYPE html>
-<html>
-<head>
- <meta charset="utf-8">
- <title>MDN Games: Shaders demo</title>
- <style>
+```html
+
+
+
+
+ MDN Games: Shaders demo
+
+
+
+
+
+
+
+
+
+```
-他包含了一些基本信息比如 文档的 {{htmlelement("title")}}, 并且设置了{{htmlelement("canvas")}}元素 css 样式的宽高,Three.js 会插入到页面中占满整个可视区域。 {{htmlelement("script")}}元素在包含 Three.js 库的{{htmlelement("head")}}中。我们的代码将卸载{{htmlelement("body")}}标签中的 script 标签中:
+他包含了一些基本信息比如 文档的 {{htmlelement("title")}}, 并且设置了{{htmlelement("canvas")}}元素 css 样式的宽高,Three.js 会插入到页面中占满整个可视区域。 {{htmlelement("script")}}元素在包含 Three.js 库的{{htmlelement("head")}}中。我们的代码将卸载{{htmlelement("body")}}标签中的 script 标签中:
-
- - 首先将包含顶点着色器。
- - 然后包含片段着色器。
- - 最后会包含一些生成实际场景的 JavaScript 代码。
-
+1. 首先将包含顶点着色器。
+2. 然后包含片段着色器。
+3. 最后会包含一些生成实际场景的 JavaScript 代码。
-阅读之前,复制这些代码到一个新的文本文件中,保存到你的工作目录作为 index.html
. 我们将在这个文件中创建一个简单的立方体来解释着色器是如何工作的。
+阅读之前,复制这些代码到一个新的文本文件中,保存到你的工作目录作为 `index.html`. 我们将在这个文件中创建一个简单的立方体来解释着色器是如何工作的。
-立方体源代码
+### 立方体源代码
-我们可以复用Building up a basic demo with Three.js 中立方体的源代码,大多数元素例如渲染器,摄像机和灯光都没有发生改变,但是基本的材质会用到自己写的着色器。
+我们可以复用[Building up a basic demo with Three.js](/en-US/docs/Games/Techniques/3D_on_the_web/Building_up_a_basic_demo_with_Three.js) 中立方体的源代码,大多数元素例如渲染器,摄像机和灯光都没有发生改变,但是基本的材质会用到自己写的着色器。
-去cube.html file on GitHub中,复制第二个{{htmlelement("script")}}元素中所有的 JavaScript 代码,粘贴到当前例子中的第三个<script>
标签中。保存并运行 index.html
— 然后你会看到一个蓝色立方体
+去[cube.html file on GitHub](https://github.com/end3r/MDN-Games-3D/blob/gh-pages/Three.js/cube.html)中,复制第二个{{htmlelement("script")}}元素中所有的 JavaScript 代码,粘贴到当前例子中的第三个`
+```
-或者,通过脚本来做同样的事情:
+或者,通过脚本来做同样的事情:
-var script = document.createElement('script');
+```js
+var script = document.createElement('script');
script.src = "file.js";
-document.body.appendChild(script);
+document.body.appendChild(script);
+```
-(从脚本中创建的脚本默认为异步。) 默认的 HTML shell Emscripten 生成后者。
+(从脚本中创建的脚本默认为异步。) 默认的 HTML shell Emscripten 生成后者。
-什么时候用 async 或者不用?
+## 什么时候用 async 或者不用?
-两种常见的情况下是脚本是非异步的(由HTML 规范定义)
+两种常见的情况下是脚本是**非**异步的(由[HTML 规范](https://www.w3.org/TR/html5/scripting-1.html)定义)
-<script async>code</script>
+```js
+
+```
-以及
+以及
-var script = document.createElement('script');
+```js
+var script = document.createElement('script');
script.innerHTML = "code";
-document.body.appendChild(script);
+document.body.appendChild(script);
+```
-两者都被视为“内联”脚本,阻塞其余所有任务,进行编译,编译完成后立即执行。
+两者都被视为“内联”脚本,阻塞其余所有任务,进行编译,编译完成后立即执行。
-如果你的代码是一个 JS 字符串呢?而不是使用 eval 或 innerHTML,这两者都会触发同步编译,您应该使用 Blob 和 URL 对象:
+如果你的代码是一个 JS 字符串呢?而不是使用 eval 或 innerHTML,这两者都会触发同步编译,您应该使用 Blob 和 URL 对象:
-var blob = new Blob([codeString]);
+```js
+var blob = new Blob([codeString]);
var script = document.createElement('script');
var url = URL.createObjectURL(blob);
script.onload = script.onerror = function() { URL.revokeObjectURL(url); };
script.src = url;
-document.body.appendChild(script);
+document.body.appendChild(script);
+```
-使用src
而不是innerHTML,则该
脚本是异步的。
+使用`src`而不是`innerHTML,则该`脚本是异步的。
diff --git a/files/zh-cn/games/techniques/control_mechanisms/index.md b/files/zh-cn/games/techniques/control_mechanisms/index.md
index 74a38b61d97e3e..ba0ea283a64ee8 100644
--- a/files/zh-cn/games/techniques/control_mechanisms/index.md
+++ b/files/zh-cn/games/techniques/control_mechanisms/index.md
@@ -16,63 +16,65 @@ tags:
- touch
translation_of: Games/Techniques/Control_mechanisms
---
-{{GamesSidebar}}
One of HTML5's main advantages as a game development platform is the ability to run on various platforms and devices. Streamlining cross device differences creates multiple challenges, not least when providing appropriate controls for different contexts. In this series of articles we will show you how you can approach building a game that can be played using touchscreen smartphones, mouse and keyboard, and also less common mechanisms such as gamepads.
+{{GamesSidebar}}
-Case study
+One of HTML5's main advantages as a game development platform is the ability to run on various platforms and devices. Streamlining cross device differences creates multiple challenges, not least when providing appropriate controls for different contexts. In this series of articles we will show you how you can approach building a game that can be played using touchscreen smartphones, mouse and keyboard, and also less common mechanisms such as gamepads.
-We'll be using the Captain Rogers: Battle at Andromeda demo as an example.
+## Case study
-
+We'll be using the [Captain Rogers: Battle at Andromeda demo](http://rogers2.enclavegames.com/demo/) as an example.
-Captain Rogers was created using the Phaser framework, the most popular tool for simple 2D game development in JavaScript right now, but it should be fairly easy to reuse the knowledge contained within these articles when building games in pure JavaScript or any other framework. If you're looking for a good introduction to Phaser, then check the 2D breakout game using Phaser tutorial.
+![Captain Rogers: Battle at Andromeda - cover of the game containing Enclave Games and Blackmoon Design logos, Roger's space ship and title of the game.](captainrogers2-cover.png)
-In the following articles we will show how to implement various different control mechanisms for Captain Rogers to support different platforms — from touch on mobile, through keyboard/mouse/gamepad on desktop, to more unconventional ones like TV remote, shouting to or waving your hand in front of the laptop, or squeezing bananas.
+Captain Rogers was created using the [Phaser](http://phaser.io/) framework, the most popular tool for simple 2D game development in JavaScript right now, but it should be fairly easy to reuse the knowledge contained within these articles when building games in pure JavaScript or any other framework. If you're looking for a good introduction to Phaser, then check the [2D breakout game using Phaser](/en-US/docs/Games/Tutorials/2D_breakout_game_Phaser) tutorial.
-Setting up the environment
+In the following articles we will show how to implement various different control mechanisms for Captain Rogers to support different platforms — from touch on mobile, through keyboard/mouse/gamepad on desktop, to more unconventional ones like TV remote, shouting to or waving your hand in front of the laptop, or squeezing bananas.
-Let's start with a quick overview of the game's folder structure, JavaScript files and in-game states, so we know what's happening where. The game's folders look like this:
+## Setting up the environment
-
+Let's start with a quick overview of the game's folder structure, JavaScript files and in-game states, so we know what's happening where. The game's folders look like this:
-As you can see there are folders for images, JavaScript files, fonts and sound effects. The src
folder contains the JavaScript files split as a separate states — Boot.js
, Preloader.js
, MainMenu.js
and Game.js
— these are loaded into the index file in this exact order. The first one initializes Phaser, the second preloads all the assets, the third one controls the main menu welcoming the player, and the fourth controls the actual gameplay.
+![Captain Rogers: Battle at Andromeda - folder structure of the games' project containing JavaScript sources, images and fonts.](captainrogers2-folderstructure.png)
-Every state has its own default methods: preload()
, create()
, and update()
. The first one is needed for preloading required assets, create()
is executed once the state had started, and update()
is executed on every frame.
+As you can see there are folders for images, JavaScript files, fonts and sound effects. The `src` folder contains the JavaScript files split as a separate states — `Boot.js`, `Preloader.js`, `MainMenu.js` and `Game.js` — these are loaded into the index file in this exact order. The first one initializes Phaser, the second preloads all the assets, the third one controls the main menu welcoming the player, and the fourth controls the actual gameplay.
-For example, you can define a button in the create()
function:
+Every state has its own default methods: `preload()`, `create()`, and `update()`. The first one is needed for preloading required assets, `create()` is executed once the state had started, and `update()` is executed on every frame.
-create: function() {
+For example, you can define a button in the `create()` function:
+
+```js
+create: function() {
// ...
var buttonEnclave = this.add.button(10, 10, 'logo-enclave', this.clickEnclave, this);
// ...
}
-
+```
-It will be created once at the start of the game, and will execute this.clickEnclave()
action assigned to it when clicked, but you can also use the mouse's pointer value in the update()
function to make an action:
+It will be created once at the start of the game, and will execute `this.clickEnclave()` action assigned to it when clicked, but you can also use the mouse's pointer value in the `update()` function to make an action:
-update: function() {
+```js
+update: function() {
// ...
if(this.game.input.mousePointer.isDown) {
// do something
}
// ...
}
-
+```
-This will be executed whenever the mouse button is pressed, and it will be checked against the input's isDown
boolean variable on every frame of the game.
+This will be executed whenever the mouse button is pressed, and it will be checked against the input's `isDown` boolean variable on every frame of the game.
-That should give you some understanding of the project structure. We'll be playing mostly with the MainMenu.js
and Game.js
files, and we'll explain the code inside the create()
and update()
methods in much more detail in later articles.
+That should give you some understanding of the project structure. We'll be playing mostly with the `MainMenu.js` and `Game.js` files, and we'll explain the code inside the `create()` and `update()` methods in much more detail in later articles.
-Pure JavaScript demo
+## Pure JavaScript demo
-There's also a small online demo with full source code available on GitHub where the basic support for the control mechanisms described in the articles is implemented in pure JavaScript. It will be explained in the given articles themselves below, but you can play with it already, and use the code however you want for learning purposes.
+There's also a [small online demo](https://end3r.github.io/JavaScript-Game-Controls/) with full source code [available on GitHub](https://github.com/end3r/JavaScript-Game-Controls/) where the basic support for the control mechanisms described in the articles is implemented in pure JavaScript. It will be explained in the given articles themselves below, but you can play with it already, and use the code however you want for learning purposes.
-The articles
+## The articles
-JavaScript is the perfect choice for mobile gaming because of HTML5 being truly multiplatform; all of the following articles focus on the APIs provided for interfacing with different control mechanisms:
+JavaScript is the perfect choice for mobile gaming because of HTML5 being truly multiplatform; all of the following articles focus on the APIs provided for interfacing with different control mechanisms:
-
- - Mobile touch controls — The first article will kick off with touch, as the mobile first approach is very popular.
- - Desktop mouse and keyboard controls — When playing on a desktop/laptop computer, providing keyboard and mouse controls is essential to provide an acceptable level of accessibility for the game.
- - Desktop gamepad controls — The Gamepad API rather usefully allows gamepads to be used for controlling web apps on desktop/laptop, for that console feel.
- - Unconventional controls — The final article showcases some unconventional control mechanisms, from the experimental to the slightly crazy, which you might not believe could be used to play the game.
-
+1. [Mobile touch controls](/en-US/docs/Games/Techniques/Control_mechanisms/Mobile_touch) — The first article will kick off with touch, as the mobile first approach is very popular.
+2. [Desktop mouse and keyboard controls](/en-US/docs/Games/Techniques/Control_mechanisms/Desktop_with_mouse_and_keyboard) — When playing on a desktop/laptop computer, providing keyboard and mouse controls is essential to provide an acceptable level of accessibility for the game.
+3. [Desktop gamepad controls](/en-US/docs/Games/Techniques/Control_mechanisms/Desktop_with_gamepad) — The Gamepad API rather usefully allows gamepads to be used for controlling web apps on desktop/laptop, for that console feel.
+4. [Unconventional controls](/en-US/docs/Games/Techniques/Control_mechanisms/Other) — The final article showcases some unconventional control mechanisms, from the experimental to the slightly crazy, which you might not believe could be used to play the game.
diff --git a/files/zh-cn/games/techniques/control_mechanisms/mobile_touch/index.md b/files/zh-cn/games/techniques/control_mechanisms/mobile_touch/index.md
index afd7fe49b5bca6..53f81a4fd42fae 100644
--- a/files/zh-cn/games/techniques/control_mechanisms/mobile_touch/index.md
+++ b/files/zh-cn/games/techniques/control_mechanisms/mobile_touch/index.md
@@ -4,120 +4,131 @@ slug: Games/Techniques/Control_mechanisms/Mobile_touch
translation_of: Games/Techniques/Control_mechanisms/Mobile_touch
original_slug: Games/Techniques/Control_mechanisms/移动端触摸控制
---
-{{GamesSidebar}}
+{{GamesSidebar}}
-{{NextMenu("Games/Techniques/Control_mechanisms/Desktop_with_mouse_and_keyboard", "Games/Techniques/Control_mechanisms")}}
+{{NextMenu("Games/Techniques/Control_mechanisms/Desktop_with_mouse_and_keyboard", "Games/Techniques/Control_mechanisms")}}
-未来手游一定是 Web 的天下,许多开发在游戏开发过程中首先选择手游 — 既然如此,触摸控制是不可少的。我们将在本教程中了解怎样简单地在移动端 H5 游戏中实现触摸控制 ,只要移动端支持触摸,你就可以尽情的玩。
+未来手游一定是 Web 的天下,许多开发在游戏开发过程中首先选择手游 — 既然如此,触摸控制是不可少的。我们将在本教程中了解怎样简单地在移动端 H5 游戏中实现触摸控制 ,只要移动端支持触摸,你就可以尽情的玩。
-说明:游戏 Captain Rogers: Battle at Andromeda 是基于Phaser 和 Phaser-based 管理控制,但它也可以用纯 JavaScript 实现。使用 Phaser 的好处它提供了辅助变量和方法可以直接调用,有助于快速的开发游戏,这需要根据项目实际情况选择。
+**说明**:游戏 [Captain Rogers: Battle at Andromeda](http://rogers2.enclavegames.com/demo/) 是基于[Phaser](http://phaser.io/) 和 Phaser-based 管理控制,但它也可以用纯 JavaScript 实现。使用 Phaser 的好处它提供了辅助变量和方法可以直接调用,有助于快速的开发游戏,这需要根据项目实际情况选择。
-纯 JavaScript 方式实现
+## 纯 JavaScript 方式实现
-我们可以实现自己的触摸事件 — 给 document 添加事件监听,并传入自定义功能的方法,非常简单:
+我们可以实现自己的触摸事件 — 给 document 添加事件监听,并传入自定义功能的方法,非常简单:
-var el = document.getElementsByTagName("canvas")[0];
+```js
+var el = document.getElementsByTagName("canvas")[0];
el.addEventListener("touchstart", handleStart);
el.addEventListener("touchmove", handleMove);
el.addEventListener("touchend", handleEnd);
-el.addEventListener("touchcancel", handleCancel);
+el.addEventListener("touchcancel", handleCancel);
+```
-这样,在移动设备上屏幕上触摸游戏的 {{htmlelement("canvas")}} 将触发这些事件,因为我们就可以随意操控游戏(如:移动太空船)。 事件如下所示:
+这样,在移动设备上屏幕上触摸游戏的 {{htmlelement("canvas")}} 将触发这些事件,因为我们就可以随意操控游戏(如:移动太空船)。 事件如下所示:
-
+- [touchstart](/en-US/docs/Web/API/GlobalEventHandlers/ontouchstart) 当用户手指放在屏幕上触发。
+- [touchmove](/en-US/docs/Web/API/GlobalEventHandlers/ontouchmove) 当他们在屏幕上移动手指时触发。
+- [touchend](/en-US/docs/Web/API/GlobalEventHandlers/ontouchend) 当用户在屏幕上停止移动时触发。
+- [touchcancel](/en-US/docs/Web/API/GlobalEventHandlers/ontouchcancel) 触摸被取消是触发,例如当用户将他们的手指移动到屏幕之外时。
-
+> **备注:** 这篇 [touch events](/en-US/docs/Web/API/Touch_events) 参考文章提供了更多的实例和介绍。
-纯 JavaScript 示例
+### 纯 JavaScript 示例
-这个实现了移动端触摸的little demo代码已经放到了 GibHub 上,我们下载这个示例就可以实现在移动端屏幕上移动飞船。
+这个实现了移动端触摸的[little demo](https://github.com/end3r/JavaScript-Game-Controls/)代码已经放到了 GibHub 上,我们下载这个示例就可以实现在移动端屏幕上移动飞船。
-我们将两种事件:touchstart
和touchmove
放到一个方法里处理。为什么呢? touchHandler
方法定义的飞船位置变量适合下面两种情况下:当玩家触摸时,但不移动它(touchstart
)和当手指在屏幕上开始移动(touchmove
):
+我们将两种事件:`touchstart `和`touchmove` 放到一个方法里处理。为什么呢? `touchHandler` 方法定义的飞船位置变量适合下面两种情况下:当玩家触摸时,但不移动它(`touchstart`)和当手指在屏幕上开始移动(`touchmove`):
-document.addEventListener("touchstart", touchHandler);
-document.addEventListener("touchmove", touchHandler);
+```js
+document.addEventListener("touchstart", touchHandler);
+document.addEventListener("touchmove", touchHandler);
+```
-touchHandler
方法的代码如下:
+`touchHandler` 方法的代码如下:
-function touchHandler(e) {
+```js
+function touchHandler(e) {
if(e.touches) {
playerX = e.touches[0].pageX - canvas.offsetLeft - playerWidth / 2;
playerY = e.touches[0].pageY - canvas.offsetTop - playerHeight / 2;
output.innerHTML = "Touch: "+ " x: " + playerX + ", y: " + playerY;
e.preventDefault();
}
-}
+}
+```
-If the touch occurs (touches
object is not empty), then we will have all the info we need in that object. We can get the first touch (e.touches[0]
, our example is not multitouch-enabled), extract the pageX
and pageY
variables and set the player's ship position on the screen by subtracting the Canvas offset (distance from the Canvas and the edge of the screen) and half the player's width and height.
+If the touch occurs (`touches` object is not empty), then we will have all the info we need in that object. We can get the first touch (`e.touches[0]`, our example is not multitouch-enabled), extract the `pageX` and `pageY` variables and set the player's ship position on the screen by subtracting the Canvas offset (distance from the Canvas and the edge of the screen) and half the player's width and height.
-
+![Touch controls for the player's ship, with visible output of the x and y position.](controls-touch.png)
-To see if it's working correctly we can output the x
and y
positions using the output
element. The preventDefault()
function is needed to prevent the browser from moving — without it you'd have the default behaviour, and the Canvas would be dragged around the page, which would show the browser scroll bars and look messy.
+To see if it's working correctly we can output the `x` and `y` positions using the `output` element. The `preventDefault()` function is needed to prevent the browser from moving — without it you'd have the default behaviour, and the Canvas would be dragged around the page, which would show the browser scroll bars and look messy.
-Touch events in Phaser
+## Touch events in Phaser
-We don't have to do this on our own; frameworks like Phaser offer systems for managing touch events for us — see managing the touch events.
+We don't have to do this on our own; frameworks like Phaser offer systems for managing touch events for us — see [managing the touch events](http://phaser.io/docs/2.6.1/Phaser.Touch.html).
-Pointer theory
+### Pointer theory
-A pointer represents a single finger on the touch screen. Phaser starts two pointers by default, so two fingers can perform an action at once. Captain Rogers is a simple game — it can be controlled by two fingers, the left one moving the ship and the right one controlling the ship's gun. There's no multitouch or gestures — everything is handled by single pointer inputs.
+A [pointer](http://phaser.io/docs/2.6.1/Phaser.Pointer.html) represents a single finger on the touch screen. Phaser starts two pointers by default, so two fingers can perform an action at once. Captain Rogers is a simple game — it can be controlled by two fingers, the left one moving the ship and the right one controlling the ship's gun. There's no multitouch or gestures — everything is handled by single pointer inputs.
-You can add more pointers to the game by using; this.game.input.addPointer
up to ten pointers can be managed simultaneously. The most recently used pointer is available in the this.game.input.activePointer
object — the most recent finger active on the screen.
+You can add more pointers to the game by using; `this.game.input.addPointer` up to ten pointers can be managed simultaneously. The most recently used pointer is available in the `this.game.input.activePointer` object — the most recent finger active on the screen.
-If you need to access a specific pointer, they are all available at, this.game.input.pointer1
this.game.input.pointer2
, etc. They are assigned dynamically, so if you put three fingers on the screen, then, pointer1
pointer2
, and pointer3
will be active. Removing the second finger, for example, won't affect the other two, and setting it back again will use the first available property, so pointer2
will be used again.
+If you need to access a specific pointer, they are all available at, ` this.game.input.pointer1``this.game.input.pointer2 `, etc. They are assigned dynamically, so if you put three fingers on the screen, then, ` pointer1``pointer2 `, and `pointer3` will be active. Removing the second finger, for example, won't affect the other two, and setting it back again will use the first available property, so `pointer2` will be used again.
-You can quickly get the coordinates of the most recently active pointer via the this.game.input.x
and this.game.input.y
variables.
+You can quickly get the coordinates of the most recently active pointer via the `this.game.input.x` and `this.game.input.y` variables.
-
+### Input events
-Instead of using the pointers directly it is also possible to listen for this.game.input
events, like onDown
, onUp
, onTap
and onHold
:
+Instead of using the pointers directly it is also possible to listen for `this.game.input` events, like `onDown`, `onUp`, `onTap` and `onHold`:
-this.game.input.onDown.add(itemTouched, this);
+```js
+this.game.input.onDown.add(itemTouched, this);
function itemTouched(pointer) {
// do something
-}
+}
+```
-The itemTouched()
function will be executed when the onDown
event is dispatched by touching the screen. The pointer
variable will contain the information about the pointer that activated the event.
+The `itemTouched()` function will be executed when the `onDown` event is dispatched by touching the screen. The `pointer` variable will contain the information about the pointer that activated the event.
-This approach uses the generally available this.game.input
object, but you can also detect the actions on any game objects like sprites or buttons by using onInputOver
, onInputOut
, onInputDown
, onInputUp
, onDragStart
, or onDragStop
:
+This approach uses the generally available `this.game.input` object, but you can also detect the actions on any game objects like sprites or buttons by using `onInputOver`, `onInputOut`, `onInputDown`, `onInputUp`, `onDragStart`, or `onDragStop`:
-this.button.events.onInputOver.add(itemTouched, this);
+```js
+this.button.events.onInputOver.add(itemTouched, this);
function itemTouched(button, pointer) {
// do something
-}
+}
+```
-That way you'll be able to attach an event to any object in the game, like the player's ship, and react to the actions performed by the user.
+That way you'll be able to attach an event to any object in the game, like the player's ship, and react to the actions performed by the user.
-An additional advantage of using Phaser is that the buttons you create will take any type of input, whether it's a touch on mobile or a click on desktop — the framework sorts this out in the background for you.
+An additional advantage of using Phaser is that the buttons you create will take any type of input, whether it's a touch on mobile or a click on desktop — the framework sorts this out in the background for you.
-Implementation
+### Implementation
-The easiest way to add an interactive object that will listen for user input is to create a button:
+The easiest way to add an interactive object that will listen for user input is to create a button:
-var buttonEnclave = this.add.button(10, 10, 'logo-enclave', this.clickEnclave, this);
+```js
+var buttonEnclave = this.add.button(10, 10, 'logo-enclave', this.clickEnclave, this);
+```
-This one is formed in the MainMenu
state — it will be placed ten pixels from the top left corner of the screen, use the logo-enclave
image, and execute the clickEnclave()
function when it is touched. This will work on mobile and desktop out of the box. There are a few buttons in the main menu, including the one that will start the game.
+This one is formed in the `MainMenu` state — it will be placed ten pixels from the top left corner of the screen, use the `logo-enclave` image, and execute the `clickEnclave()` function when it is touched. This will work on mobile and desktop out of the box. There are a few buttons in the main menu, including the one that will start the game.
-For the actual gameplay, instead of creating more buttons and covering the small mobile screen with them, we can use something a little bit different: we'll create invisible areas which respond to the given action. From a design point of view, it is better to make the field of activity bigger without covering half of the screen with button images. For example, tapping on the right side of the screen will fire the weapon:
+For the actual gameplay, instead of creating more buttons and covering the small mobile screen with them, we can use something a little bit different: we'll create invisible areas which respond to the given action. From a design point of view, it is better to make the field of activity bigger without covering half of the screen with button images. For example, tapping on the right side of the screen will fire the weapon:
-this.buttonShoot = this.add.button(this.world.width*0.5, 0, 'button-alpha', null, this);
+```js
+this.buttonShoot = this.add.button(this.world.width*0.5, 0, 'button-alpha', null, this);
this.buttonShoot.onInputDown.add(this.goShootPressed, this);
-this.buttonShoot.onInputUp.add(this.goShootReleased, this);
+this.buttonShoot.onInputUp.add(this.goShootReleased, this);
+```
-The code above will create a new button using a transparent image that covers the right half of the screen. You can assign functions on input down and input up separately if you'd like to perform more complicated actions, but in this game touching the right side of the screen will simply fire the bullets to the right — this is all we need in this case.
+The code above will create a new button using a transparent image that covers the right half of the screen. You can assign functions on input down and input up separately if you'd like to perform more complicated actions, but in this game touching the right side of the screen will simply fire the bullets to the right — this is all we need in this case.
-Moving the player could be managed by creating the four directional buttons, but we can take the advantage of touch screens and drag the player's ship around:
+Moving the player could be managed by creating the four directional buttons, but we can take the advantage of touch screens and drag the player's ship around:
-var player = this.game.add.sprite(30, 30, 'ship');
+```js
+var player = this.game.add.sprite(30, 30, 'ship');
player.inputEnabled = true;
player.input.enableDrag();
player.events.onDragStart.add(onDragStart, this);
@@ -125,29 +136,34 @@ player.events.onDragStop.add(onDragStop, this);
function onDragStart(sprite, pointer) {
// do something when dragging
-}
+}
+```
-We can pull the ship around and do something in the meantime, and react when the drag is stopped. Hauling in Phaser, if enabled, will work out of the box — you don't have to set the position of the sprite yourself manually, so you could leave the onDragStart()
function empty, or place some debug output to see if it's working correctly. The pointer
element contains the x
and y
variables storing the current position of the dragged element.
+We can pull the ship around and do something in the meantime, and react when the drag is stopped. Hauling in Phaser, if enabled, will work out of the box — you don't have to set the position of the sprite yourself manually, so you could leave the `onDragStart()` function empty, or place some debug output to see if it's working correctly. The `pointer` element contains the `x` and `y` variables storing the current position of the dragged element.
-Dedicated plugins
+### Dedicated plugins
-You could go even further and use dedicated plugins like Virtual Joystick — this is a paid, official Phaser plugin, but you can find free and open source alternatives. The initialization of Virtual Joystick looks like this:
+You could go even further and use dedicated plugins like [Virtual Joystick](http://phaser.io/shop/plugins/virtualjoystick) — this is a paid, official Phaser plugin, but you can find free and [open source alternatives](https://github.com/Gamegur-us/phaser-touch-control-plugin). The initialization of Virtual Joystick looks like this:
-this.pad = this.game.plugins.add(Phaser.VirtualJoystick);
-this.stick = this.pad.addStick(30, 30, 80, 'generic');
+```js
+this.pad = this.game.plugins.add(Phaser.VirtualJoystick);
+this.stick = this.pad.addStick(30, 30, 80, 'generic');
+```
-In the create()
function of the Game
state we're creating a virtual pad and a generic stick that has four directional virtual buttons by default. This is placed 30 pixels from the top and left edges of the screen and is 80 pixels wide.
+In the `create()` function of the `Game` state we're creating a virtual pad and a generic stick that has four directional virtual buttons by default. This is placed 30 pixels from the top and left edges of the screen and is 80 pixels wide.
-The stick being pressed can be handled during the gameplay in the update
function like so:
+The stick being pressed can be handled during the gameplay in the `update` function like so:
-if(this.stick.isDown) {
+```js
+if(this.stick.isDown) {
// move the player
-}
+}
+```
-We can adjust the player's velocity based on the current angle of the stick and move him appropriately.
+We can adjust the player's velocity based on the current angle of the stick and move him appropriately.
-摘要
+## 摘要
-这篇文章主要讲解如何在移动端实现触摸控制; 下一篇文章我们将看到怎样添加键盘和鼠标支持。
+这篇文章主要讲解如何在移动端实现触摸控制; 下一篇文章我们将看到怎样添加键盘和鼠标支持。
-{{NextMenu("Games/Techniques/Control_mechanisms/Desktop_with_mouse_and_keyboard", "Games/Techniques/Control_mechanisms")}}
+{{NextMenu("Games/Techniques/Control_mechanisms/Desktop_with_mouse_and_keyboard", "Games/Techniques/Control_mechanisms")}}
diff --git a/files/zh-cn/games/techniques/controls_gamepad_api/index.md b/files/zh-cn/games/techniques/controls_gamepad_api/index.md
index 958c6107fe5423..7dbad1e3508ecd 100644
--- a/files/zh-cn/games/techniques/controls_gamepad_api/index.md
+++ b/files/zh-cn/games/techniques/controls_gamepad_api/index.md
@@ -3,45 +3,46 @@ title: 使用 Gamepad API 实现控制
slug: Games/Techniques/Controls_Gamepad_API
translation_of: Games/Techniques/Controls_Gamepad_API
---
-{{GamesSidebar}}
这篇文章着眼于使用 Gamepad API 为网页游戏实现一个有效的跨浏览器控制系统,可以让你使用端游控制器来控制你的网页游戏。Hungry Fridge,就是 Enclave Games 以此制作的游戏。
+{{GamesSidebar}}
-网页游戏的控制
+这篇文章着眼于使用 Gamepad API 为网页游戏实现一个有效的跨浏览器控制系统,可以让你使用端游控制器来控制你的网页游戏。Hungry Fridge,就是 [Enclave Games](http://enclavegames.com/) 以此制作的游戏。
-在历史上,在连接主机 (console) 的电视上玩游戏和在电脑 (PC) 上玩游戏是两种完全不一样的体验,最大的区别就是它们的控制方式。后来,额外的驱动程序和插件让我们能够使用主机控制器来游玩电脑端的游戏--不论是本地游戏,还是运行在浏览器中的游戏。 到现在的 HTML5 时代,我们终于有了 Gamepad API ,让我们能够在不安装任何插件的情况下,可以使用控制器来游玩基于浏览器的游戏。Gamepad API 通过提供一个接口公开按钮的按下和坐标的变化来实现这一点,在 JavaScript 中我们可以用这些变化来处理输入。这对于网页游戏来说是非常棒的特性。
+## 网页游戏的控制
-API 状态与浏览器支持
+在历史上,在连接主机 (console) 的电视上玩游戏和在电脑 (PC) 上玩游戏是两种完全不一样的体验,最大的区别就是它们的控制方式。后来,额外的驱动程序和插件让我们能够使用主机控制器来游玩电脑端的游戏--不论是本地游戏,还是运行在浏览器中的游戏。 到现在的 HTML5 时代,我们终于有了 [Gamepad API](/en-US/docs/Web/API/Gamepad_API) ,让我们能够在不安装任何插件的情况下,可以使用控制器来游玩基于浏览器的游戏。Gamepad API 通过提供一个接口公开按钮的按下和坐标的变化来实现这一点,在 JavaScript 中我们可以用这些变化来处理输入。这对于网页游戏来说是非常棒的特性。
-Gamepad API 在 W3C 的进程中仍然还是工作草案的状态,这意味着它的实现方法可能还会出现变动,但是就目前来说浏览器的支持性相当不错。Firefox 29+ 和 Chrome 35+ 对其支持得非常好。Opera 在版本 22+ 对 API 进行了支持 (一点也不奇怪,因为他们现在使用 Chrome 的引擎了。) 并且微软最近在 Edge 中对 API 实现了支持,也就是说四大主流浏览器现在都支持 Gamepad API。
+## API 状态与浏览器支持
-哪种控制器最好?
+[Gamepad API](http://www.w3.org/TR/gamepad/) 在 W3C 的进程中仍然还是工作草案的状态,这意味着它的实现方法可能还会出现变动,但是就目前来说[浏览器的支持性](http://caniuse.com/gamepad)相当不错。Firefox 29+ 和 Chrome 35+ 对其支持得非常好。Opera 在版本 22+ 对 API 进行了支持 (一点也不奇怪,因为他们现在使用 Chrome 的引擎了。) 并且微软最近在 Edge 中对 API 实现了支持,也就是说四大主流浏览器现在都支持 Gamepad API。
-目前最受欢迎的控制器是来自 XBox 360、XBox One、PS3 和 PS4 的 — 它们经受过时间的检验,并且在浏览器跨 Windows 与 Mac OS 平台中对 Gamepad API 的实现中工作良好。
+## 哪种控制器最好?
-还有一些其他各种各样不同布局的控制器或多或少的支持跨浏览器的实现。本文中讨论的代码使用了一些控制器进行测试,但是笔者比较喜欢的配置是:无线 XBox 360 控制器和 Mac OS X 平台的 Firefox 浏览器。
+目前最受欢迎的控制器是来自 XBox 360、XBox One、PS3 和 PS4 的 — 它们经受过时间的检验,并且在浏览器跨 Windows 与 Mac OS 平台中对 Gamepad API 的实现中工作良好。
-实例分析:Hungry Fridge
+还有一些其他各种各样不同布局的控制器或多或少的支持跨浏览器的实现。本文中讨论的代码使用了一些控制器进行测试,但是笔者比较喜欢的配置是:无线 XBox 360 控制器和 Mac OS X 平台的 Firefox 浏览器。
-GitHub Game Off II 比赛举行于 2013 年 11 月,Enclave Games 决定参加比赛。比赛的主题为“改变”(change),所以他们提交了这样一个游戏——你需要通过点击来喂食饥饿的冰箱健康的食物 (苹果、萝卜、莴苣) 并避开“坏”的食物 (啤酒、汉堡、披萨) 。其中会有倒计时会改变接下来几秒内冰箱想吃的东西,所以你又要小心动作又要块。你可以在这里尝试 Hungry Fridge。
+## 实例分析:Hungry Fridge
-第二个隐藏的“改变”的实现是可以从单纯静态的冰箱改变成涡轮驱动、射击和吞食的机器能力。当你连接控制器后,游戏会有很明显的改变 (饥饿冰箱会变成超级涡轮的饥饿冰箱) 并且你可以使用 Gamepad API 来控制装甲冰箱。你需要击落食物但是你仍然需要找到冰箱目前想吃的食物,否则你会失去能量。
+[GitHub Game Off II](https://github.com/blog/1674-github-game-off-ii) 比赛举行于 2013 年 11 月,[Enclave Games](http://enclavegames.com/) 决定参加比赛。比赛的主题为“改变”(change),所以他们提交了这样一个游戏——你需要通过点击来喂食饥饿的冰箱健康的食物 (苹果、萝卜、莴苣) 并避开“坏”的食物 (啤酒、汉堡、披萨) 。其中会有倒计时会改变接下来几秒内冰箱想吃的东西,所以你又要小心动作又要块。你可以[在这里尝试 Hungry Fridge](http://enclavegames.com/games/hungry-fridge/)。
-游戏封装了两种截然不同的“变化”(change) ——好食物对坏食物,与移动端对桌面端。
+第二个隐藏的“改变”的实现是可以从单纯静态的冰箱改变成涡轮驱动、射击和吞食的机器能力。当你连接控制器后,游戏会有很明显的改变 (饥饿冰箱会变成超级涡轮的饥饿冰箱) 并且你可以使用 Gamepad API 来控制装甲冰箱。你需要击落食物但是你仍然需要找到冰箱目前想吃的食物,否则你会失去能量。
-示例
+游戏封装了两种截然不同的“变化”(change) ——好食物对坏食物,与移动端对桌面端。
-Game API 的动作展示与 JavaScript 的源代码公布是在完整版的 Hungry Fridge 构建之后才开始的,然后据此创建了一个 简单的示例。部分 Gamepad API Content Kit 在 Github 上供你分析代码并研究其如何工作。
+## 示例
-以下讨论的代码来自于完整的 Hungry Fridge 游戏中,除了原代码需要 turbo
变量来决定是否启动“超级涡轮模式”以外几乎一模一样。此代码可以独立运行,就算不连接控制器也可以。
+Game API 的动作展示与 JavaScript 的源代码公布是在完整版的 Hungry Fridge 构建之后才开始的,然后据此创建了一个 [简单的示例](https://end3r.github.io/Gamepad-API-Content-Kit/demo/demo.html)。部分 [Gamepad API Content Kit](https://end3r.github.io/Gamepad-API-Content-Kit/) 在 Github 上供你分析代码并研究其如何工作。
-
-
备注: 一个彩蛋:点击界面右上角的控制器图标有个隐藏选项——不连接控制器也能启动“超级涡轮模式” 。你可以使用键盘上的 A 和 D 控制左右旋转,W 射击,方向键移动。
-
+以下讨论的代码来自于完整的 Hungry Fridge 游戏中,除了原代码需要 `turbo` 变量来决定是否启动“超级涡轮模式”以外几乎一模一样。此代码可以独立运行,就算不连接控制器也可以。
-实现方法
+> **备注:** 一个彩蛋:点击界面右上角的控制器图标有个隐藏选项——不连接控制器也能启动“超级涡轮模式” 。你可以使用键盘上的 A 和 D 控制左右旋转,W 射击,方向键移动。
-使用 Gamepad API 时有两个重要的事件——gamepadconnected
和 gamepaddisconnected
。前者将于浏览器侦测到新控制器连接时触发;而后者则是断开连接 (不管是物理断开还是无响应了) 的时候触发。在示例中 gamepadAPI
对象通常存储着所有关于 API 的东西:
+## 实现方法
-var gamepadAPI = {
+使用 Gamepad API 时有两个重要的事件——`gamepadconnected` 和 `gamepaddisconnected`。前者将于浏览器侦测到新控制器连接时触发;而后者则是断开连接 (不管是物理断开还是无响应了) 的时候触发。在示例中 `gamepadAPI` 对象通常存储着所有关于 API 的东西:
+
+```js
+var gamepadAPI = {
controller: {},
turbo: false,
connect: function() {},
@@ -52,65 +53,73 @@ translation_of: Games/Techniques/Controls_Gamepad_API
buttonsCache: [],
buttonsStatus: [],
axesStatus: []
-};
+};
+```
-数组 buttons
存储着 XBox 360 控制器的按键布局 button layout:
+数组 `buttons` 存储着 XBox 360 控制器的按键布局 button layout:
-buttons: [
+```js
+buttons: [
'DPad-Up','DPad-Down','DPad-Left','DPad-Right',
'Start','Back','Axis-Left','Axis-Right',
'LB','RB','Power','A','B','X','Y',
-],
+],
+```
-这可能和例如 PS3 控制器 (或者其他没名字的通用控制器) 等其他控制器有所不同,所以你需要注意并不要假设你期望的布局和你真正使用的控制器布局是一样。接下来我们设置两个事件侦听器来获取数据:
+这可能和例如 PS3 控制器 (或者其他没名字的通用控制器) 等其他控制器有所不同,所以你需要注意并不要假设你期望的布局和你真正使用的控制器布局是一样。接下来我们设置两个事件侦听器来获取数据:
-window.addEventListener("gamepadconnected", gamepadAPI.connect);
-window.addEventListener("gamepaddisconnected", gamepadAPI.disconnect);
+```js
+window.addEventListener("gamepadconnected", gamepadAPI.connect);
+window.addEventListener("gamepaddisconnected", gamepadAPI.disconnect);
+```
-由于安全策略,你必须先与控制器产生交互才能触发当前显示页面的事件。如果 API 在没有接收到用户交互的时候工作,那它可能会在不知情的情况下被用来识别指纹。
+由于安全策略,你必须先与控制器产生交互才能触发当前显示页面的事件。如果 API 在没有接收到用户交互的时候工作,那它可能会在不知情的情况下被用来识别指纹。
-两个函数都十分简单:
+两个函数都十分简单:
-connect: function(evt) {
+```js
+connect: function(evt) {
gamepadAPI.controller = evt.gamepad;
gamepadAPI.turbo = true;
console.log('控制器已连接。');
-},
+},
+```
-函数 connect()
接受一个事件作为参数,并将其中的 gamepad
对象分配给 gamepadAPI.controller
变量。我们在这个游戏中只使用一个控制器,所以这个变量是一个单独的对象而不是控制器的数组。然后我们设置 turbo
属性为 true
。 (这个可以直接用 gamepad.connected
实现,但我们想单独设置一个变量来控制“涡轮模式”而不需要连接控制器,原因已在前面说明过了。)
+函数 `connect()` 接受一个事件作为参数,并将其中的 `gamepad` 对象分配给 `gamepadAPI.controller` 变量。我们在这个游戏中只使用一个控制器,所以这个变量是一个单独的对象而不是控制器的数组。然后我们设置 `turbo` 属性为 `true`。 (这个可以直接用 `gamepad.connected` 实现,但我们想单独设置一个变量来控制“涡轮模式”而不需要连接控制器,原因已在前面说明过了。)
-disconnect: function(evt) {
+```js
+disconnect: function(evt) {
gamepadAPI.turbo = false;
delete gamepadAPI.controller;
console.log('控制器已断开。');
-},
+},
+```
-函数 disconnect
设置 gamepad.turbo
属性为 false
并移除存储着 gamepad
对象的变量。
+函数 `disconnect` 设置 `gamepad.turbo` 属性为 `false` 并移除存储着 `gamepad` 对象的变量。
-Gamepad 对象
+### Gamepad 对象
-对象 gamepad
中有包含了许多有用的信息,其中就包括按钮和坐标轴的状态等重要信息:
+对象 `gamepad` 中有包含了许多有用的信息,其中就包括按钮和坐标轴的状态等重要信息:
-
- id
: 一个包含关于控制器信息的字符串。
- index
: 一个为已连接的设备分配的唯一标识。
- connected
: 一个布尔变量,true
表示设备已连接。
- mapping
: 键位的布局类型;现在只有 standard
是唯一可用的值。
- axes
: 每一个坐标轴的状态。表示为存储浮点值的数组。
- buttons
: 每个按钮的状态,表示为一个 GamepadButton
对象,其包含 pressed
和 value
属性。
-
+- `id`: 一个包含关于控制器信息的字符串。
+- `index`: 一个为已连接的设备分配的唯一标识。
+- `connected`: 一个布尔变量,`true` 表示设备已连接。
+- `mapping`: 键位的布局类型;现在只有 `standard` 是唯一可用的值。
+- `axes`: 每一个坐标轴的状态。表示为存储浮点值的数组。
+- `buttons` : 每个按钮的状态,表示为一个 `GamepadButton` 对象,其包含 `pressed` 和 `value` 属性。
-变量 index
在我们连接了多个控制器时非常有用,我们可以用此来区分它们的操作——例如我们有一个需要连接两个控制器的双人游戏。
+变量 `index` 在我们连接了多个控制器时非常有用,我们可以用此来区分它们的操作——例如我们有一个需要连接两个控制器的双人游戏。
-查询控制器对象
+### 查询控制器对象
-除了 connect()
和 disconnect()
,gamepadAPI
对象中还有另外两个方法:update()
和 buttonPressed()
。update()
会在游戏循环的每一帧中执行,来更新 gamepad 对象的实时状态:
+除了 `connect()` 和 `disconnect()` ,`gamepadAPI` 对象中还有另外两个方法:`update()` 和 `buttonPressed()`。`update()` 会在游戏循环的每一帧中执行,来更新 gamepad 对象的实时状态:
-update: function() {
+```js
+update: function() {
// 清除按钮缓存
gamepadAPI.buttonsCache = [];
// 从上一帧中移动按钮状态到缓存中
- for(var k=0; k<gamepadAPI.buttonsStatus.length; k++) {
+ for(var k=0; k
+},
+```
-在每一帧上,update()
都会将上一帧的按钮状态保存至数组 buttonsCache
中,并在 gamepadAPI.controller
对象提取出新的状态信息。然后它就能轮询按钮和坐标值并获得它们的实时状态和值。
+在每一帧上,`update()` 都会将上一帧的按钮状态保存至数组 `buttonsCache` 中,并在 `gamepadAPI.controller` 对象提取出新的状态信息。然后它就能轮询按钮和坐标值并获得它们的实时状态和值。
-监测按钮按下
+### 监测按钮按下
-方法 buttonPressed()
也位于主游戏循环中来监听按钮的按下。它有两个参数——我们想要监听的按钮和 (可选) 用来告诉游戏接收的按键是(从之前就)被按住了的。没了它你需要松开并再按一次按钮才能得到想要的结果。
+方法 `buttonPressed()` 也位于主游戏循环中来监听按钮的按下。它有两个参数——我们想要监听的按钮和 (可选) 用来告诉游戏接收的按键是(从之前就)被按住了的。没了它你需要松开并再按一次按钮才能得到想要的结果。
-buttonPressed: function(button, hold) {
+```js
+buttonPressed: function(button, hold) {
var newPress = false;
// 轮询按下的按钮
- for(var i=0,s=gamepadAPI.buttonsStatus.length; i<s; i++) {
+ for(var i=0,s=gamepadAPI.buttonsStatus.length; i
+},
+```
-在一个按钮中有两种动作:单次按下和按住。变量 newPress
布尔变量将会指出这个是不是一个按钮新的按下操作。下次我们再轮询已按下按钮的数组——如果有按钮是我们正在找的,那么设 newPress
变量为 true
。通过检查本次按下是不是新按下的,就能得出玩家是不是按住按钮了。我们从游戏循环中的上一帧轮询按钮的缓存状态,如果我们找到了,就说明按钮被按住了,所以就不是新的按下。最后 newPress
变量被返回。函数 buttonPressed
通常这样来更新游戏循环:
+在一个按钮中有两种动作:单次按下和按住。变量 `newPress` 布尔变量将会指出这个是不是一个按钮新的按下操作。下次我们再轮询已按下按钮的数组——如果有按钮是我们正在找的,那么设 `newPress` 变量为 `true` 。通过检查本次按下是不是新按下的,就能得出玩家是不是按住按钮了。我们从游戏循环中的上一帧轮询按钮的缓存状态,如果我们找到了,就说明按钮被按住了,所以就不是新的按下。最后 `newPress` 变量被返回。函数 `buttonPressed` 通常这样来更新游戏循环:
-if(gamepadAPI.turbo) {
+```js
+if(gamepadAPI.turbo) {
if(gamepadAPI.buttonPressed('A','hold')) {
this.turbo_fire();
}
if(gamepadAPI.buttonPressed('B')) {
this.managePause();
}
-}
+}
+```
-如果 gamepadAPI.turbo
为 true
并有按钮被按下 (或被按住),我们就会为其分配恰当的操作。在本例中,按下或按住 A
开火,按下 B
暂停游戏。
+如果 `gamepadAPI.turbo` 为 `true` 并有按钮被按下 (或被按住),我们就会为其分配恰当的操作。在本例中,按下或按住 `A` 开火,按下 `B` 暂停游戏。
-坐标阈值
+### 坐标阈值
-按钮只有两种状态:0
或 1
,但是摇杆可以有许多不同的值——他们在 X
和 Y
轴上都有一个范围为 -1
到 1
的浮点值。
+按钮只有两种状态:`0` 或 `1`,但是摇杆可以有许多不同的值——他们在 `X` 和 `Y` 轴上都有一个范围为 `-1` 到 `1` 的浮点值。
-控制器放在一边不活动时轴值也可能有一定波动 (get dusty) ,这也就是说通过判断等于绝对的 -1 或 1 来可能是会有问题的。因此对此最好是给轴值设定一个阈值来触发生效。比如说,“冰箱坦克”仅会在 X
值大于 0.5
的时候向右转:
+控制器放在一边不活动时轴值也可能有一定波动 (get dusty) ,这也就是说通过判断等于绝对的 -1 或 1 来可能是会有问题的。因此对此最好是给轴值设定一个阈值来触发生效。比如说,“冰箱坦克”仅会在 `X` 值大于 `0.5` 的时候向右转:
-if(gamepadAPI.axesStatus[0].x > 0.5) {
- this.player.angle += 3;
- this.turret.angle += 3;
-}
+ if(gamepadAPI.axesStatus[0].x > 0.5) {
+ this.player.angle += 3;
+ this.turret.angle += 3;
+ }
-即使我们稍微误推摇杆或者摇杆没有弹回原始位置,“冰箱坦克”也不会意外转向。
+即使我们稍微误推摇杆或者摇杆没有弹回原始位置,“冰箱坦克”也不会意外转向。
-规范更新
+## 规范更新
-经过长达一年多的规范化,W3C Gamepaf API 于 2015 年 4 月更新了规范 (查看最新信息)。更新的改动并不是很大,但是我们最好了解一下到底更新了些什么—— 以下为更新。
+经过长达一年多的规范化,W3C Gamepaf API 于 2015 年 4 月更新了规范 ([查看最新信息](https://w3c.github.io/gamepad/))。更新的改动并不是很大,但是我们最好了解一下到底更新了些什么—— 以下为更新。
-获取控制器
+### 获取控制器
-{{domxref("Naviagator.getGamepads()")}} 方法已用更长的说明和示例代码更新。现在控制器数组的长度必须为 n+1
( n
是已连接设备的数量) —— 当设备连接且其有索引 1,数组长度为 2,那么它将会是这样: [null, [object Gamepad]]
。如果设备被断开或不可用的话,值将被设为 null
。
+{{domxref("Naviagator.getGamepads()")}} 方法已用[更长的说明和示例代码](https://w3c.github.io/gamepad/#navigator-interface-extension)更新。现在控制器数组的长度必须为 `n+1` ( `n` 是已连接设备的数量) —— 当设备连接且其有索引 1,数组长度为 2,那么它将会是这样: `[null, [object Gamepad]]`。如果设备被断开或不可用的话,值将被设为 `null`。
-映射标准
+### 映射标准
-布局类型现在是一个可枚举的对象而不是字符串:
+布局类型现在是一个可枚举的对象而不是字符串:
-enum GamepadMappingType {
- "",
- "standard"
-};
+ enum GamepadMappingType {
+ "",
+ "standard"
+ };
-此枚举中定义了已知的控制器映射集。目前只有 standard
布局可用,但是未来可能会有新的布局。如果布局未知,那么将会是空字符串。
+此枚举中定义了已知的控制器映射集。目前只有 `standard` 布局可用,但是未来可能会有新的布局。如果布局未知,那么将会是空字符串。
-事件
+### 事件
-除了当前可用的 gamepadconnected
和 gamepaddisconnected
事件,其实还有其它事件也曾在规范中,但它们因为不是非常的有用所以被移出了规范。相关讨论仍在进行中,关于它们是否应该恢复规范,以及以什么形式恢复。
+除了当前可用的 `gamepadconnected` 和 `gamepaddisconnected` 事件,其实还有其它事件也曾在规范中,但它们因为不是非常的有用所以被移出了规范。相关讨论仍在进行中,关于它们是否应该恢复规范,以及以什么形式恢复。
-总结
+## 总结
-Gamepad API 非常易于开发。现在它比以往更容易向浏览器提供游戏主机的体验而不需要任何插件。你可以直接在你的浏览器中游玩完整的 Hungry Fridge 游戏。你可以从 Firefox Marketplace 中安装,或者可以在 Gamepad API Content Kit 中查看示例源代码。
+Gamepad API 非常易于开发。现在它比以往更容易向浏览器提供游戏主机的体验而不需要任何插件。你可以直接在你的浏览器中游玩完整的 [Hungry Fridge](http://enclavegames.com/games/hungry-fridge/) 游戏。你可以从 [Firefox Marketplace](https://marketplace.firefox.com/app/hungry-fridge) 中安装,或者可以在 [Gamepad API Content Kit](https://github.com/EnclaveGames/Hungry-Fridge) 中查看示例源代码。
diff --git a/files/zh-cn/games/techniques/index.md b/files/zh-cn/games/techniques/index.md
index 40269267843e54..09b5a00984bc1f 100644
--- a/files/zh-cn/games/techniques/index.md
+++ b/files/zh-cn/games/techniques/index.md
@@ -8,25 +8,21 @@ tags:
- TopicStub
translation_of: Games/Techniques
---
-{{GamesSidebar}}
+{{GamesSidebar}}
-
-
这个页面为想要使用开放的网页技术来开发游戏的人列举出了必要的核心技术。
-
+这个页面为想要使用开放的网页技术来开发游戏的人列举出了必要的核心技术。
-
- - 使用 asm.js 中的异步脚本
- - 尤其在制作中大型游戏时,异步脚本是一项必备技术,你游戏中的 JavaScript 因此可以在主进程之外被编译,并被缓存以之后游戏的运行,这会带来显著的性能提升。这篇文章解释了如何做到。
- - Optimizing startup performance
- - How to make sure your game starts up quickly, smoothly, and without appearing to lock up the user's browser or device.
- - Using WebRTC peer-to-peer data channels
- - In addition to providing support for audio and video communication, WebRTC lets you set up peer-to-peer data channels to exchange text or binary data actively between your players. This article explains what this can do for you, and shows how to use libraries that make this easy.
- - Efficient animation for web games
- - This article covers techniques and advice for creating efficient animation for web games, with a slant towards supporting lower end devices such as mobile phones. We touch on CSS transitions and CSS animations, and JavaScript loops involving {{ domxref("window.requestAnimationFrame") }}.
- - Audio for Web Games
- - Audio is an important part of any game — it adds feedback and atmosphere. Web-based audio is maturing fast, but there are still many browser differences to negotiate. This article provides a detailed guide to implementing audio for web games, looking at what works currently across as wide a range of platforms as possible.
- - 2D collision detection
- - A concise introduction to collision detection in 2D games.
- - Tilemaps
- - Tiles are a very popular technique in 2D games for building the game world. These articles provide an introduction to tilemaps and how to implement them with the Canvas API.
-
+- [使用 asm.js 中的异步脚本](/en-US/docs/Games/Techniques/Async_scripts)
+ - : 尤其在制作中大型游戏时,异步脚本是一项必备技术,你游戏中的 JavaScript 因此可以在主进程之外被编译,并被缓存以之后游戏的运行,这会带来显著的性能提升。这篇文章解释了如何做到。
+- [Optimizing startup performance](/en-US/docs/Apps/Developing/Optimizing_startup_performance)
+ - : How to make sure your game starts up quickly, smoothly, and without appearing to lock up the user's browser or device.
+- [Using WebRTC peer-to-peer data channels](/en-US/docs/Games/WebRTC_data_channels)
+ - : In addition to providing support for audio and video communication, WebRTC lets you set up peer-to-peer data channels to exchange text or binary data actively between your players. This article explains what this can do for you, and shows how to use libraries that make this easy.
+- [Efficient animation for web games](/en-US/docs/Games/Techniques/Efficient_animation_for_web_games)
+ - : This article covers techniques and advice for creating efficient animation for web games, with a slant towards supporting lower end devices such as mobile phones. We touch on CSS transitions and CSS animations, and JavaScript loops involving {{ domxref("window.requestAnimationFrame") }}.
+- [Audio for Web Games](/en-US/docs/Games/Techniques/Audio_for_Web_Games)
+ - : Audio is an important part of any game — it adds feedback and atmosphere. Web-based audio is maturing fast, but there are still many browser differences to negotiate. This article provides a detailed guide to implementing audio for web games, looking at what works currently across as wide a range of platforms as possible.
+- [2D collision detection](/en-US/docs/Games/Techniques/2D_collision_detection)
+ - : A concise introduction to collision detection in 2D games.
+- [Tilemaps](/en-US/docs/Games/Techniques/Tilemaps)
+ - : Tiles are a very popular technique in 2D games for building the game world. These articles provide an introduction to tilemaps and how to implement them with the Canvas API.
diff --git a/files/zh-cn/games/tools/index.md b/files/zh-cn/games/tools/index.md
index c6276627d8c037..579ce15eb69da2 100644
--- a/files/zh-cn/games/tools/index.md
+++ b/files/zh-cn/games/tools/index.md
@@ -10,31 +10,24 @@ tags:
- TopicStub
translation_of: Games/Tools
---
-{{GamesSidebar}}
+{{GamesSidebar}}
-
-
On this page you can find links to our game development tools articles, which eventually aims to cover frameworks, compilers, and debugging tools.
-
+On this page you can find links to our game development tools articles, which eventually aims to cover frameworks, compilers, and debugging tools.
-
- - asm.js
- - asm.js is a very limited subset of the JavaScript language, which can be greatly optimized and run in an ahead-of-time (AOT) compiling engine for much faster performance than your typical JavaScript performance. This is, of course, great for games.
- - Emscripten
- -
-
An LLVM to JavaScript compiler; with Emscripten, you can compile C++ and other languages that can compile to LLVM bytecode into high-performance JavaScript. This is a great tool for porting applications to the Web! There is a useful Emscripten tutorial available on the wiki. Note that we are aiming to cover Emscripten in its own section of MDN.
-
- - Gecko profiler
- - The Gecko profiler extension lets you profile your code to help figure out where your performance issues are so that you can make your game run at top speed.
- - Game engines and tools
- - A list of engines, templates and technologies useful to game developers.
- - Shumway
- - Shumway is a renderer for Adobe Flash built entirely in JavaScript, WebGL, etc., bridging the gap between Flash and web standards. This article shows how to make use of Shumway, and how to contribute fixes and bugs to the project.
- - Toolchain for developing and debugging games
- - How does this differ from normal web app debugging? What specialist tools are available? A lot of this is going to be covered by Will in tools, but here we should provide a kind of practical toolchain tutorial for debugging games, with links to Will's stuff:
-
- - Basic tools overview
- - Shader editor
- - Performance tools (still in production, estimated early 2014)
-
-
-
+- [asm.js](/en-US/docs/Games/Tools/asm.js)
+ - : asm.js is a very limited subset of the JavaScript language, which can be greatly optimized and run in an ahead-of-time (AOT) compiling engine for much faster performance than your typical JavaScript performance. This is, of course, great for games.
+- [Emscripten](https://github.com/kripken/emscripten/wiki)
+ - : An LLVM to JavaScript compiler; with Emscripten, you can compile C++ and other languages that can compile to LLVM bytecode into high-performance JavaScript. This is a great tool for porting applications to the Web! There is a [useful Emscripten tutorial](https://github.com/kripken/emscripten/wiki/Tutorial) available on the wiki. Note that we are [aiming to cover Emscripten in its own section of MDN](/en-US/docs/Emscripten).
+- [Gecko profiler](https://addons.mozilla.org/en-us/firefox/addon/gecko-profiler/)
+ - : The Gecko profiler extension lets you profile your code to help figure out where your performance issues are so that you can make your game run at top speed.
+- [Game engines and tools](/en-US/docs/Games/Tools/Engines_and_tools)
+ - : A list of engines, templates and technologies useful to game developers.
+- [Shumway](/en-US/docs/Mozilla/Projects/Shumway)
+ - : Shumway is a renderer for Adobe Flash built entirely in JavaScript, WebGL, etc., bridging the gap between Flash and web standards. This article shows how to make use of Shumway, and how to contribute fixes and bugs to the project.
+- Toolchain for developing and debugging games
+
+ - : How does this differ from normal web app debugging? What specialist tools are available? A lot of this is going to be covered by Will in [tools](/en-US/docs/Tools), but here we should provide a kind of practical toolchain tutorial for debugging games, with links to Will's stuff:
+
+ - Basic tools overview
+ - [Shader editor](/en-US/docs/Tools/Shader_Editor)
+ - Performance tools (still in production, estimated early 2014)
diff --git a/files/zh-cn/games/tutorials/2d_breakout_game_phaser/animations_and_tweens/index.md b/files/zh-cn/games/tutorials/2d_breakout_game_phaser/animations_and_tweens/index.md
index 741788b4092568..fa46da20f011ad 100644
--- a/files/zh-cn/games/tutorials/2d_breakout_game_phaser/animations_and_tweens/index.md
+++ b/files/zh-cn/games/tutorials/2d_breakout_game_phaser/animations_and_tweens/index.md
@@ -13,103 +13,103 @@ tags:
- tween
translation_of: Games/Tutorials/2D_breakout_game_Phaser/Animations_and_tweens
---
-{{GamesSidebar}}
+{{GamesSidebar}}
-{{PreviousNext("Games/Workflows/2D_Breakout_game_Phaser/Extra_lives", "Games/Workflows/2D_Breakout_game_Phaser/Buttons")}}
+{{PreviousNext("Games/Workflows/2D_Breakout_game_Phaser/Extra_lives", "Games/Workflows/2D_Breakout_game_Phaser/Buttons")}}
-
+这是[Gamedev Phaser 教程](/en-US/docs/Games/Workflows/2D_Breakout_game_Phaser) 16 的**第 14 步**。您可以在[Gamedev-Phaser-Content-Kit / demos / lesson14.html](https://github.com/end3r/Gamedev-Phaser-Content-Kit/blob/gh-pages/demos/lesson14.html)完成本课程后找到源代码。
-为了使游戏看起来更加多汁和活泼,我们可以使用动画和补间。这将导致更好,更有趣的体验。让我们来探讨如何在游戏中实现 Phaser 动画和补间。
+为了使游戏看起来更加多汁和活泼,我们可以使用动画和补间。这将导致更好,更有趣的体验。让我们来探讨如何在游戏中实现 Phaser 动画和补间。
-动画
+## 动画
-在 Phaser,动画中,涉及从外部来源获取 spritesheet 并依次显示 sprites。作为一个例子,当碰到一些东西时,我们会让球摇摆。
+在 Phaser,动画中,涉及从外部来源获取 spritesheet 并依次显示 sprites。作为一个例子,当碰到一些东西时,我们会让球摇摆。
-首先,从 Github 抓取 spritesheet并将其保存在您的/img
目录中。
+首先,[从 Github 抓取 spritesheet](https://github.com/end3r/Gamedev-Phaser-Content-Kit/blob/gh-pages/demos/img/wobble.png)并将其保存在您的`/img`目录中。
-接下来,我们将加载 spritesheet - 将以下行放在preload()
函数的底部:
+接下来,我们将加载 spritesheet - 将以下行放在`preload()`函数的底部:
-game.load.spritesheet('ball', 'img/wobble.png', 20, 20);
-
+```js
+game.load.spritesheet('ball', 'img/wobble.png', 20, 20);
+```
-而不是加载单个图像的球,我们可以加载整个 spritesheet - 不同图像的集合。我们将按顺序显示精灵,创造动画的幻觉。该spritesheet()
方法的两个额外的表格确定给定 spritesheet 文件中每个单个框架的宽度和高度,指示程序如何切割以获取单个框架。
+而不是加载单个图像的球,我们可以加载整个 spritesheet - 不同图像的集合。我们将按顺序显示精灵,创造动画的幻觉。该`spritesheet()`方法的两个额外的表格确定给定 spritesheet 文件中每个单个框架的宽度和高度,指示程序如何切割以获取单个框架。
-加载动画
+## 加载动画
-接下来,进入你的 create() 函数,找到加载球精灵的行,下面的调用animations.add()
如下所示:
+接下来,进入你的 create() 函数,找到加载球精灵的行,下面的调用`animations.add()`如下所示:
-ball = game.add.sprite(50, 250, 'ball');
+```js
+ball = game.add.sprite(50, 250, 'ball');
ball.animations.add('wobble', [0,1,0,2,0,1,0,2,0], 24);
-
+```
-要向对象添加动画,我们使用该animations.add()
方法,其中包含以下参数
+要向对象添加动画,我们使用该`animations.add()`方法,其中包含以下参数
-
- - 我们为动画选择的名称
- - 一个数组,定义在动画过程中显示帧的顺序。如果您再次查看
wobble.png
图像,您会看到有三个框架。Phaser 提取它们并将它们存储在数组中 - 位置 0,1 和 2.上面的数组表示我们显示帧 0,然后是 1,然后是 0 等。
- - 帧速率,以 fps 为单位。由于我们以 24fps 运行动画,有 9 帧,动画每秒将显示三次以下。
-
+- 我们为动画选择的名称
+- 一个数组,定义在动画过程中显示帧的顺序。如果您再次查看`wobble.png`图像,您会看到有三个框架。Phaser 提取它们并将它们存储在数组中 - 位置 0,1 和 2.上面的数组表示我们显示帧 0,然后是 1,然后是 0 等。
+- 帧速率,以 fps 为单位。由于我们以 24fps 运行动画,有 9 帧,动画每秒将显示三次以下。
-当球击中桨时应用动画
+## 当球击中桨时应用动画
-在arcade.collide()
处理球和桨(第一行内部update()
,见下文)之间的碰撞的方法调用中,我们可以添加一个额外的参数,该参数指定每次发生碰撞时执行的功能,与该ballHitBrick()
功能相同。更新内部的第一行update()
,如下所示:
+在`arcade.collide()`处理球和桨(第一行内部`update()`,见下文)之间的碰撞的方法调用中,我们可以添加一个额外的参数,该参数指定每次发生碰撞时执行的功能,与该`ballHitBrick()`功能相同。更新内部的第一行`update()`,如下所示:
-function update() {
+```js
+function update() {
game.physics.arcade.collide(ball, paddle, ballHitPaddle);
game.physics.arcade.collide(ball, bricks, ballHitBrick);
paddle.x = game.input.x || game.world.width*0.5;
}
-
+```
-然后我们可以创建ballHitPaddle()
函数(具有ball
和paddle
作为默认参数),在调用时播放摆动动画。在结束</script>
标签之前添加以下方法:
+然后我们可以创建`ballHitPaddle()`函数(具有`ball`和`paddle`作为默认参数),在调用时播放摆动动画。在结束``标签之前添加以下方法:
-function ballHitPaddle(ball, paddle) {
+```js
+function ballHitPaddle(ball, paddle) {
ball.animations.play('wobble');
}
-
+```
-每次球击中桨时都会播放动画。你也可以animations.play()
在ballHitBrick()
函数内添加调用,如果你觉得它会使游戏看起来更好。
+每次球击中桨时都会播放动画。你也可以`animations.play()`在`ballHitBrick()`函数内添加调用,如果你觉得它会使游戏看起来更好。
-补间
+## 补间
-而动画依次播放外部精灵,补间游戏中物体的属性平滑,如宽度或不透明度。
+而动画依次播放外部精灵,补间游戏中物体的属性平滑,如宽度或不透明度。
-让我们在游戏中增加一个补间,使砖块在被球击中时顺利消失。转到您的ballhitBrick()
功能,找到您的brick.kill();
行,并将其替换为以下内容:
+让我们在游戏中增加一个补间,使砖块在被球击中时顺利消失。转到您的`ballhitBrick()`功能,找到您的`brick.kill();`行,并将其替换为以下内容:
-var killTween = game.add.tween(brick.scale);
+```js
+var killTween = game.add.tween(brick.scale);
killTween.to({x:0,y:0}, 200, Phaser.Easing.Linear.None);
killTween.onComplete.addOnce(function(){
brick.kill();
}, this);
killTween.start();
-
+```
-让我们来看看这里,看看这里发生了什么:
+让我们来看看这里,看看这里发生了什么:
-
- - 当定义一个新的补间时,你必须指定哪些属性将被补间 - 在我们的例子中,而不是在被球击中时立即隐藏砖块,我们将把它们的宽度和高度缩放到零,所以它们将很好地消失。最后,我们使用该
add.tween()
方法,指定brick.scale
为参数,因为这是我们想要补间。
- - 该
to()
方法定义补间结束时对象的状态。它需要一个包含所选参数的期望结束值的对象(比例取尺度值,1 为大小的 100%,0 为大小的 0%等),补间的时间(以毫秒为单位)以及使用的宽松类型补间。
- - 我们还将添加可选的
onComplete
事件处理程序,该处理程序定义了在补间程序完成时要执行的函数。
- - 最后一件事是立即开始补间
start()
。
-
+1. 当定义一个新的补间时,你必须指定哪些属性将被补间 - 在我们的例子中,而不是在被球击中时立即隐藏砖块,我们将把它们的宽度和高度缩放到零,所以它们将很好地消失。最后,我们使用该`add.tween()`方法,指定`brick.scale`为参数,因为这是我们想要补间。
+2. 该`to()`方法定义补间结束时对象的状态。它需要一个包含所选参数的期望结束值的对象(比例取尺度值,1 为大小的 100%,0 为大小的 0%等),补间的时间(以毫秒为单位)以及使用的宽松类型补间。
+3. 我们还将添加可选的`onComplete`事件处理程序,该处理程序定义了在补间程序完成时要执行的函数。
+4. 最后一件事是立即开始补间`start()`。
-这是补间定义的扩展版本,但是我们也可以使用速记语法:
+这是补间定义的扩展版本,但是我们也可以使用速记语法:
-game.add.tween(brick.scale).to({x:2,y:2}, 500, Phaser.Easing.Elastic.Out, true, 100);
-
+```js
+game.add.tween(brick.scale).to({x:2,y:2}, 500, Phaser.Easing.Elastic.Out, true, 100);
+```
-这个补间将使用弹性宽松在半秒内将砖的比例翻倍,将自动启动,延迟 100 毫秒。
+这个补间将使用弹性宽松在半秒内将砖的比例翻倍,将自动启动,延迟 100 毫秒。
-比较你的代码
+## 比较你的代码
-您可以在下面的现场演示中查看本课程的完成代码,并使用它来更好地了解它的工作原理:
+您可以在下面的现场演示中查看本课程的完成代码,并使用它来更好地了解它的工作原理:
-{{JSFiddleEmbed("https://jsfiddle.net/end3r/9o4pakrb/","","400")}}
+{{JSFiddleEmbed("https://jsfiddle.net/end3r/9o4pakrb/","","400")}}
-下一步
+## 下一步
-动画和 tweens 看起来很不错,但我们可以添加更多的我们的游戏 - 在下一节我们将看看处理按钮输入。
+动画和 tweens 看起来很不错,但我们可以添加更多的我们的游戏 - 在下一节我们将看看处理[按钮](/en-US/docs/Games/Workflows/2D_Breakout_game_Phaser/Buttons)输入。
-{{PreviousNext("Games/Workflows/2D_Breakout_game_Phaser/Extra_lives", "Games/Workflows/2D_Breakout_game_Phaser/Buttons")}}
+{{PreviousNext("Games/Workflows/2D_Breakout_game_Phaser/Extra_lives", "Games/Workflows/2D_Breakout_game_Phaser/Buttons")}}
diff --git a/files/zh-cn/games/tutorials/2d_breakout_game_phaser/bounce_off_the_walls/index.md b/files/zh-cn/games/tutorials/2d_breakout_game_phaser/bounce_off_the_walls/index.md
index ac6dd6f30c2dd4..4f9e476e1b2c8a 100644
--- a/files/zh-cn/games/tutorials/2d_breakout_game_phaser/bounce_off_the_walls/index.md
+++ b/files/zh-cn/games/tutorials/2d_breakout_game_phaser/bounce_off_the_walls/index.md
@@ -12,38 +12,38 @@ tags:
- bouncing
translation_of: Games/Tutorials/2D_breakout_game_Phaser/Bounce_off_the_walls
---
-{{GamesSidebar}}
+{{GamesSidebar}}
-{{PreviousNext("Games/Workflows/2D_Breakout_game_Phaser/Physics", "Games/Workflows/2D_Breakout_game_Phaser/Player_paddle_and_controls")}}
+{{PreviousNext("Games/Workflows/2D_Breakout_game_Phaser/Physics", "Games/Workflows/2D_Breakout_game_Phaser/Player_paddle_and_controls")}}
-
+这是[Gamedev Phaser 教程](/en-US/docs/Games/Workflows/2D_Breakout_game_Phaser)的**第** 6 **步**。在[Gamedev-Phaser-Content-Kit / demos / lesson06.html](https://github.com/end3r/Gamedev-Phaser-Content-Kit/blob/gh-pages/demos/lesson06.html)完成本课后,您可以找到源代码。
-现在已经介绍了物理引擎,我们可以开始在游戏中实现碰撞检测 - 首先我们来看看墙壁。
+现在已经介绍了物理引擎,我们可以开始在游戏中实现碰撞检测 - 首先我们来看看墙壁。
-反弹边界
+## 反弹边界
-让我们的球从墙壁上弹起的最简单的方法是告诉框架,我们想要将元素可用于通过脚本(通常为JavaScript)绘制图形。 例如,它可以用于绘制图形,制作照片,甚至执行动画。 您可以(并且应该)在<canvas>块内提供备用内容。 该内容将在不支持画布的旧浏览器和禁用JavaScript的浏览器中呈现。"><canvas>
元素的边界视为墙壁,而不是让球移过它们。在 Phaser 中,可以使用该collideWorldsBound
属性轻松实现。在现有game.physics.enable()
方法调用之后添加此行:
+让我们的球从墙壁上弹起的最简单的方法是告诉框架,我们想要将[元素可用于通过脚本(通常为 JavaScript)绘制图形。 例如,它可以用于绘制图形,制作照片,甚至执行动画。 您可以(并且应该)在\