Reference · Deterministic 2D physics
addBodyfunction
Adds a body to the world and gives it back.
Import it
import { addBody } from "@johnmorrisdotca/karakuri/physics";
Definition
function addBody<T extends Body>(world: World, body: T): T
Parameters
| Name | Type | Description |
|---|---|---|
world | World | The mutable native world and its bodies in insertion order. |
body | T | The native rigid body whose cached world shapes are used or refreshed. |
Returns
T
Adds a body to the world and gives it back.
Examples
import type { BodySpec } from "@johnmorrisdotca/karakuri/physics";
import { addBody, createBody, createWorld } from "@johnmorrisdotca/karakuri/physics";
const spec: BodySpec={id:"ball",shapes:[{kind:"circle",x:0,y:0,r:3}],x:0,y:0};
const body=createBody(spec);
console.log(addBody(createWorld({gravity:0}),body).id);ballWhat it prints (run when this page was built)