{ { GamesSidebar } }
{ { GamesSidebar } }
This sample shows 31 sentences.
{ { GamesSidebar } }
{ { GamesSidebar } }
Some games drive this cycle by user input .
Imagine that you are developing a “ find the differences between these two similar pictures ” -type game .
本文 从 技术 角度 分析 了 一般 电子 游戏 的 结构 和 工作 流程 , 就此 介绍 主 循环 是 如何 运行 的 。
The game loop is advanced by the user ’ s input and sleeps until they provide it .
This is more of a turn-based approach that doesn ’ t demand a constant update every frame , only when the player reacts .
它 有助 于 初学者 了解 在 现代 游戏 开发 领域 构 建 游戏 时 需要 什么 , 以及 如何 将 JavaScript 这样 的 Web 标准 工具 作为 自己 的 工具 使用 。
It might require both input and simulated time .
It might even loop based on something else entirely .
游戏 开发 经验 丰富 但 不 熟悉 Web 开发 的 开发 者 也能 从中 受益 。
Of course , your game will only be as optimized as you make it .
呈现 、 接收 、 解释 、 计算 、 重复
JavaScript works best with events and callback functions .
Modern browsers strive to call methods right as they are needed and idle ( or do their other tasks ) in the gaps .
It is an excellent idea to attach your code to the moments that are appropriate for them .
所有电子游戏的目标都是向用户 呈现 一个场景 , 接收 他们的输入 , 将这些输入信号 解释 为动作 , 并 计算 出 由 这些 动作 产生 的 新 场景 。
A callback function must be passed in to it when it is called .
That callback function will be executed at a suitable time before the next repaint .
游戏 不断地 循环 遍 历 , 一遍 又 一遍 , 直到 遇到 某些 终止 条件 ( 比如 赢 、 输 或者 退出 睡觉 ) 。
Here is an example of a simple main loop :
window . main = ( ) = > {
window . requestAnimationFrame ( main ) ;
毫不 奇怪 , 这种 模式 与 游戏 引擎 的 编 程 方式 相 呼应 。
That is not by accident and it is considered best practice .
具体 情况 取决 于 游戏 本身 。
The above chunk of code has two statements .
一些游戏通过 用户 输入 来 驱动 这个 循环 。