Notion - Update docs

This commit is contained in:
shiffman 2024-02-24 20:54:20 +00:00 committed by GitHub
parent 7a2afe10c7
commit 484f0fde49

View file

@ -242,6 +242,7 @@ function setup() {
<pre class="codesplit" data-code-language="javascript"> // Change the engines gravity to point horizontally.
engine.gravity.x = 1;
engine.gravity.y = 0;</pre>
<p>Of course, gravity doesnt 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. Ill use this technique throughout the chapters examples.</p>
</div>
<p>Of course, gravity doesnt 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, its 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. Its 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>