mirror of
https://github.com/nature-of-code/noc-book-2
synced 2024-09-29 05:36:56 +02:00
Notion - Update docs
This commit is contained in:
parent
7a2afe10c7
commit
484f0fde49
1 changed files with 1 additions and 1 deletions
|
@ -242,6 +242,7 @@ function setup() {
|
|||
<pre class="codesplit" data-code-language="javascript"> // Change the engine’s gravity to point horizontally.
|
||||
engine.gravity.x = 1;
|
||||
engine.gravity.y = 0;</pre>
|
||||
<p>Of course, gravity doesn’t have to be fixed for the duration of the simulation; you can adjust the gravity vector while your program is running. You can also turn gravity off altogether by setting it to a (0, 0) vector.</p>
|
||||
<div data-type="note">
|
||||
<h3 id="object-destructuring">Object Destructuring</h3>
|
||||
<p><strong>Object destructuring</strong> in JavaScript is a technique for extracting properties from an object and assigning them to variables. In the case of Matter.js, the <code>Matter</code> object contains the <code>Engine</code> property. Normally, an alias for this property can be set with <code>let Engine = Matter.Engine</code>, but with destructuring, the alias can be created more concisely:</p>
|
||||
|
@ -252,7 +253,6 @@ function setup() {
|
|||
const { Engine, Vector } = Matter;</pre>
|
||||
<p>This sets up <code>Engine</code> as an alias for <code>Matter.Engine</code>, and <code>Vector</code> as an alias for <code>Matter.Vector</code>, all in one statement. I’ll use this technique throughout the chapter’s examples.</p>
|
||||
</div>
|
||||
<p>Of course, gravity doesn’t have to be fixed for the duration of the simulation; you can adjust the gravity vector while your program is running. You can also turn gravity off altogether by setting it to a (0, 0) vector.</p>
|
||||
<p>Once the world is initialized, it’s time to put stuff in it—bodies!</p>
|
||||
<h3 id="bodies">Bodies</h3>
|
||||
<p>The <strong>body</strong> is the primary element in the Matter.js world. It’s the equivalent of the <code>Vehicle</code> (née <code>Particle</code>, née <code>Mover</code>) class I built in previous chapters—the thing that moves around the space and experiences forces. A body can also be static (fixed and not moving).</p>
|
||||
|
|
Loading…
Reference in a new issue