Skip to content

Commit

Permalink
Merge pull request #820 from nature-of-code/notion-update-docs
Browse files Browse the repository at this point in the history
6
  • Loading branch information
shiffman authored Feb 24, 2024
2 parents 7a2afe1 + 484f0fd commit 4c4ddfe
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion content/06_libraries.html
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ <h3 id="engine">Engine</h3>
<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>
Expand All @@ -252,7 +253,6 @@ <h3 id="object-destructuring">Object Destructuring</h3>
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>
Expand Down

0 comments on commit 4c4ddfe

Please sign in to comment.