create-dreamer-app 1.0.15 → 1.0.16
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.2.
|
|
3
|
+
A practical guide to building browser games with `discodreamer`. Examples use the public API in version 1.2.1 and TypeScript with JSX.
|
|
4
4
|
|
|
5
5
|
## How a game runs
|
|
6
6
|
|
|
@@ -73,18 +73,21 @@ The examples below are independent excerpts; add their named imports from `disco
|
|
|
73
73
|
|
|
74
74
|
### `registerRoot(Root, config?)`
|
|
75
75
|
|
|
76
|
-
Registers the single root function and starts the game loop.
|
|
76
|
+
Registers the single root function and starts the game loop. The config argument is optional; omitting it uses `{ units: "pixels" }`. Pixel mode has no scaling factor. Scale mode requires an explicit, finite, positive `scaling` value:
|
|
77
77
|
|
|
78
78
|
```ts
|
|
79
|
+
registerRoot(Game); // Defaults to CSS-pixel coordinates.
|
|
80
|
+
// Or explicitly select a coordinate mode:
|
|
81
|
+
registerRoot(Game, { units: "pixels" });
|
|
79
82
|
registerRoot(Game, { units: "scale", scaling: 0.01 });
|
|
80
83
|
```
|
|
81
84
|
|
|
82
|
-
|
|
85
|
+
These are alternative registration examples; call `registerRoot` only once per game. The config is a union of `{ units: "pixels" }` and `{ units: "scale"; scaling: number }`:
|
|
83
86
|
|
|
84
87
|
| Field | Values | Behavior |
|
|
85
88
|
| --- | --- | --- |
|
|
86
89
|
| `units` | `"pixels"` or `"scale"` | Selects CSS pixels or scaled game units |
|
|
87
|
-
| `scaling` | Finite number greater than `0` |
|
|
90
|
+
| `scaling` | Finite number greater than `0` | Required and validated only in scale mode; fraction of the canvas's shorter CSS dimension occupied by one game unit |
|
|
88
91
|
|
|
89
92
|
In scale mode, the engine recalculates the CSS-pixel size of one game unit before building the tree each frame:
|
|
90
93
|
|
|
@@ -96,7 +99,7 @@ With `scaling: 0.01`, one game unit occupies 1% of the shorter canvas dimension,
|
|
|
96
99
|
|
|
97
100
|
Positions, display widths and heights, circle radii, and font sizes use the selected coordinate units. Resizing changes the size of a scaled unit while stored positions and sizes retain their numeric values. Source image dimensions and sprite-sheet frame sizes remain source pixels; specify sprite display dimensions explicitly when needed for your chosen scale.
|
|
98
101
|
|
|
99
|
-
Viewport dimensions and pointer coordinates use the same units as drawing. Device pixel ratio is handled internally for canvas resolution; no DPR conversion is needed in game code. In pixel mode, `unit` is `1` and `scaling`
|
|
102
|
+
Viewport dimensions and pointer coordinates use the same units as drawing. Device pixel ratio is handled internally for canvas resolution; no DPR conversion is needed in game code. In pixel mode, `unit` is `1` and no `scaling` field is needed. If the calculated unit is zero or non-finite, the engine falls back to `1` for that frame.
|
|
100
103
|
|
|
101
104
|
## State and keys
|
|
102
105
|
|