create-dreamer-app 1.0.7 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Disco Dreamer reference
|
|
2
2
|
|
|
3
|
-
A practical guide to building browser games with `discodreamer`. Examples use the public API in version 1.0.
|
|
3
|
+
A practical guide to building browser games with `discodreamer`. Examples use the public API in version 1.0.6 and TypeScript with JSX.
|
|
4
4
|
|
|
5
5
|
## How a game runs
|
|
6
6
|
|
|
@@ -273,21 +273,27 @@ Rectangle bounds use their top-left corner; circle bounds use their center. `pos
|
|
|
273
273
|
|
|
274
274
|
Call these each frame with the body's public `key`. The handler receives the other body's public key once per reported body pair per frame.
|
|
275
275
|
|
|
276
|
+
- `gameCollision` calls `handler(otherKey: string, otherLayer: string)`, passing the other body's public key and layer. The layer is always defined for a physical collision.
|
|
277
|
+
- `gameHit` calls `handler(otherKey: string, otherLayer: string)`, passing the other body's public key and layer. The other body's layer is always defined for a hit.
|
|
276
278
|
- Physical collisions require both bodies to include each other's `layer` in `collidesWith`.
|
|
277
|
-
- Hits are directional: only the observing body's `hitsWith` needs to include the other body's layer.
|
|
279
|
+
- Hits are directional: only the observing body's `hitsWith` needs to include the other body's layer. The observing body does not need its own layer.
|
|
278
280
|
- Hits alone do not separate bodies or change their velocities.
|
|
279
281
|
- Hooks read the previous frame's contact results because the current collision pass happens after tree construction. Contacts are reported repeatedly while detected; these are not enter/exit events.
|
|
280
282
|
|
|
281
283
|
```tsx
|
|
282
284
|
function PhysicsExample() {
|
|
283
|
-
gameCollision("ball", (otherKey) => {
|
|
284
|
-
if (
|
|
285
|
+
gameCollision("ball", (otherKey, otherLayer) => {
|
|
286
|
+
if (otherLayer === "world") console.log("Ball contacted world body:", otherKey);
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
gameHit("ball", (otherKey, otherLayer) => {
|
|
290
|
+
if (otherLayer === "world") console.log("Ball overlapped world body:", otherKey);
|
|
285
291
|
});
|
|
286
292
|
|
|
287
293
|
return (
|
|
288
294
|
<Scene>
|
|
289
295
|
<RigidBody2D key="ball" x={100} y={40}
|
|
290
|
-
layer="ball" collidesWith={["world"]} restitution={0.6}>
|
|
296
|
+
layer="ball" collidesWith={["world"]} hitsWith={["world"]} restitution={0.6}>
|
|
291
297
|
<Bounds radius={16} outline style={{ fill: "hotpink" }} />
|
|
292
298
|
</RigidBody2D>
|
|
293
299
|
<RigidBody2D key="floor" y={350} mass={0}
|