From 484f0fde494fbd5d9aeb23f7484b797ff7396732 Mon Sep 17 00:00:00 2001 From: shiffman Date: Sat, 24 Feb 2024 20:54:20 +0000 Subject: [PATCH] Notion - Update docs --- content/06_libraries.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/06_libraries.html b/content/06_libraries.html index 600c2432..1726fb2e 100644 --- a/content/06_libraries.html +++ b/content/06_libraries.html @@ -242,6 +242,7 @@

Engine

  // Change the engine’s gravity to point horizontally.
   engine.gravity.x = 1;
   engine.gravity.y = 0;
+

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.

Object Destructuring

Object destructuring in JavaScript is a technique for extracting properties from an object and assigning them to variables. In the case of Matter.js, the Matter object contains the Engine property. Normally, an alias for this property can be set with let Engine = Matter.Engine, but with destructuring, the alias can be created more concisely:

@@ -252,7 +253,6 @@

Object Destructuring

const { Engine, Vector } = Matter;

This sets up Engine as an alias for Matter.Engine, and Vector as an alias for Matter.Vector, all in one statement. I’ll use this technique throughout the chapter’s examples.

-

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.

Once the world is initialized, it’s time to put stuff in it—bodies!

Bodies

The body is the primary element in the Matter.js world. It’s the equivalent of the Vehicle (née Particle, née Mover) 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).