A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
docs: add subsystem guides (physics/spine/tilemap/ui/audio/assets/wechat)
yhhc8c6f0a0e700
diff --git a/docs/astro/astro.config.mjs b/docs/astro/astro.config.mjsindex 93baa1a7d..24c6fc948 100644--- a/docs/astro/astro.config.mjs+++ b/docs/astro/astro.config.mjs@@ -44,6 +44,19 @@ export default defineConfig({{ label: 'Systems', translations: { 'zh-CN': '系统' }, slug: 'core-concepts/systems' },],},+ {+ label: 'Guides',+ translations: { 'zh-CN': '指南' },+ items: [+ { label: 'Physics', translations: { 'zh-CN': '物理' }, slug: 'guides/physics' },+ { label: 'Spine Animation', translations: { 'zh-CN': 'Spine 动画' }, slug: 'guides/spine' },+ { label: 'Tilemaps', translations: { 'zh-CN': '瓦片地图' }, slug: 'guides/tilemap' },+ { label: 'UI', translations: { 'zh-CN': 'UI' }, slug: 'guides/ui' },+ { label: 'Audio', translations: { 'zh-CN': '音频' }, slug: 'guides/audio' },+ { label: 'Assets', translations: { 'zh-CN': '资源' }, slug: 'guides/assets' },+ { label: 'WeChat MiniGame', translations: { 'zh-CN': '微信小游戏' }, slug: 'guides/wechat' },+ ],+ },{label: 'Reference',translations: { 'zh-CN': '参考' },diff --git a/docs/astro/src/content/docs/guides/assets.mdx b/docs/astro/src/content/docs/guides/assets.mdxnew file mode 100644index 000000000..6f806dd3f--- /dev/null+++ b/docs/astro/src/content/docs/guides/assets.mdx@@ -0,0 +1,54 @@+---+title: Assets+description: How assets are referenced, cooked, and loaded at runtime.+---++import { Aside } from '@astrojs/starlight/components';++Every asset in a project has a stable UUID. Scenes and prefabs reference assets+by UUID; at build time the engine **cooks** only the assets your game actually+reaches, and the runtime loads them through a manifest.++## Referencing assets++Assets are referenced by UUID in the canonical form `@uuid:<uuid>`. The editor+manages these — you rarely type them by hand.++## Cooking++Cooking walks the dependency graph from your entry scene(s), **culls anything+unreachable**, stages the reachable files, and writes `assets.manifest.json`+(the map the runtime consumes). Optionally it compresses textures: PNGs are+encoded to GPU-ready **KTX2** (Basis Universal), which the runtime transcodes to+the best format the device supports (ASTC → ETC2 → S3TC, falling back to RGBA8).++## Loading at runtime++```typescript+import { defineSystem, Res, Assets } from 'esengine';++defineSystem([Res(Assets)], async (assets) => {+ const texture = await assets.load('@uuid:a1234567-...');+});+```++## Addressable groups (subpackages)++Assets under a `subpackages/<name>/…` folder belong to a lazy group `<name>`;+everything else is the eagerly-loaded `main` group. Load a group on demand:++```typescript+const bundle = await assets.loadGroup('level2', (loaded, total) => {+ console.log(`${loaded}/${total}`);+});+```++This grouping is what maps onto [WeChat subpackages](/docs/guides/wechat/) for+on-demand download.++<Aside type="note">+ Content hashing runs on the **staged** bytes (after PNG→KTX2 encoding), so the+ manifest hash identifies the shipped artifact and identical files dedupe to one+ copy. Assets under `subpackages/` are always included even if unreachable —+ only their group assignment differs.+</Aside>diff --git a/docs/astro/src/content/docs/guides/audio.mdx b/docs/astro/src/content/docs/guides/audio.mdxnew file mode 100644index 000000000..4b5948315--- /dev/null+++ b/docs/astro/src/content/docs/guides/audio.mdx@@ -0,0 +1,57 @@+---+title: Audio+description: Play sound effects and music, mix buses, and position spatial audio.+---++import { Aside } from '@astrojs/starlight/components';++Audio is registered by default. Play one-shot effects and music through the+`Audio` resource, or drive playback declaratively with an `AudioSource`+component.++## Play from a system++```typescript+import { defineSystem, Res, Audio } from 'esengine';++defineSystem([Res(Audio)], (audio) => {+ audio.playSFX('assets/audio/kick.wav', { volume: 1.0, pitch: 1.0 });+ audio.playBGM('assets/audio/theme.ogg', { fadeIn: 0.5 });+});+```++`AudioAPI` also has `stopBGM(fadeOut?)`, `stopAll()`, `preload(url)` /+`preloadAll(urls)`, and mixer volumes: `setMasterVolume`, `setMusicVolume`,+`setSFXVolume`, `setUIVolume` (all `0–1`).++`playSFX` returns an `AudioHandle` you can `stop()`, `pause()`, `resume()`,+`setVolume()`, `setPan()`, `setLoop()`.++## Declarative playback: `AudioSource`++Attach an `AudioSource` to an entity to play a clip without code: `clip`, `bus`+(`"sfx"` by default), `volume`, `pitch`, `loop`, `playOnAwake`, and spatial+fields (`spatial`, `minDistance`, `maxDistance`, `attenuationModel`). With+`playOnAwake` + `enabled`, the audio system plays it automatically.++## Mixer buses++The mixer is hierarchical: `master → { music, sfx, ui, voice }`. Setting a bus+volume scales everything under it:++```typescript+audio.setSFXVolume(0.5); // quieter effects+audio.setMasterVolume(0.8);+```++## Spatial audio++Set `AudioSource.spatial = true` and put an enabled `AudioListener` on your+camera/player entity; distance attenuation follows the source's+`attenuationModel`.++<Aside type="caution">+ `playSFX` auto-preloads an uncached clip and plays it once ready, so the very+ first hit can be silent — call `preload(url)` up front for guaranteed timing.+ Browsers also require a user gesture before audio can start.+</Aside>diff --git a/docs/astro/src/content/docs/guides/physics.mdx b/docs/astro/src/content/docs/guides/physics.mdxnew file mode 100644index 000000000..44cef6191--- /dev/null+++ b/docs/astro/src/content/docs/guides/physics.mdx@@ -0,0 +1,99 @@+---+title: Physics+description: Rigid bodies, colliders, forces, queries, and collision events.+---++import { Aside } from '@astrojs/starlight/components';++Estella's physics runs in the C++/WebAssembly core. You add the physics plugin,+attach a `RigidBody` and a collider to an entity, and drive or query it through+the `Physics` API.++## Enable physics++```typescript+import { PhysicsPlugin } from 'esengine/physics';++app.addPlugin(new PhysicsPlugin('physics.js', {+ gravity: { x: 0, y: -9.81 },+}));+```++The module loads asynchronously; physics is ready once its init settles.++## Bodies and colliders++Attach a `RigidBody` plus one collider shape. **Collider dimensions are in+meters, not pixels** — divide pixel sizes by your pixels-per-unit (PPU):++```typescript+import { RigidBody, BodyType, CircleCollider, BoxCollider } from 'esengine';++const PPU = 100;++cmds.spawn()+ .insert(Transform, { position: { x, y, z: 0 } })+ .insert(RigidBody, { bodyType: BodyType.Dynamic })+ .insert(CircleCollider, { radius: 24 / PPU, restitution: 0.4 });+```++- **`BodyType`** — `Static` (immovable), `Kinematic` (moved by you), `Dynamic`+ (moved by the simulation).+- **Collider shapes** — `BoxCollider`, `CircleCollider`, `CapsuleCollider`,+ `SegmentCollider`, `PolygonCollider`, `ChainCollider`. All share `density`,+ `friction`, `restitution`, `isSensor`, `categoryBits`, `maskBits`.+- **Joints** — `RevoluteJoint`, `DistanceJoint`, `PrismaticJoint`, `WeldJoint`,+ `WheelJoint`.++## Collision layers++`categoryBits` (what layer this body is on) and `maskBits` (what it collides+with) are 16-bit filters. Two bodies collide only if each one's category is in+the other's mask:++```typescript+const LAYER_PLAYER = 0x0001;+const LAYER_GROUND = 0x0008;++.insert(CircleCollider, {+ radius: 16 / PPU,+ categoryBits: LAYER_PLAYER,+ maskBits: LAYER_PLAYER | LAYER_GROUND,+});+```++## Forces, velocity, and queries++Read the `Physics` resource in a system to push bodies and query the world:++```typescript+import { defineSystem, Res, Physics } from 'esengine';++defineSystem([Res(Physics)], (physics) => {+ physics.applyImpulse(player, { x: 0, y: 5 }); // jump+ physics.setLinearVelocity(player, { x: 3, y: 0 });++ // Queries take pixel-space and auto-scale by PPU.+ const hits = physics.raycast(origin, direction, 200);+ const inRange = physics.overlapCircle(center, 64);+});+```++## Collision events++The `PhysicsEvents` resource carries this frame's contacts:++```typescript+import { PhysicsEvents } from 'esengine';++defineSystem([Res(PhysicsEvents)], (events) => {+ for (const c of events.collisionEnters) { /* c.entityA, c.entityB */ }+ for (const s of events.sensorEnters) { /* trigger volumes */ }+});+```++<Aside type="caution">+ Set `isSensor: true` on a collider to get enter/exit events **without** a+ physical response (trigger zones). Physics steps at a fixed timestep, not the+ frame delta, so read `PhysicsEvents` every frame.+</Aside>diff --git a/docs/astro/src/content/docs/guides/spine.mdx b/docs/astro/src/content/docs/guides/spine.mdxnew file mode 100644index 000000000..e3ddfb016--- /dev/null+++ b/docs/astro/src/content/docs/guides/spine.mdx@@ -0,0 +1,64 @@+---+title: Spine Animation+description: Play Spine skeletal animations with SpineAnimation and SpineManager.+---++import { Aside } from '@astrojs/starlight/components';++Estella has built-in [Spine](https://esotericsoftware.com/) skeletal animation.+Give an entity a `SpineAnimation` component (usually set up in the editor), then+control it at runtime through the `SpineManager`.++## The `SpineAnimation` component++Points an entity at a skeleton + atlas and its playback state:++- `skeletonPath`, `atlasPath` — the Spine assets to load.+- `animation`, `loop`, `playing` — the current track.+- `skin`, `skeletonScale`, `timeScale`, `flipX`, `flipY`, `color`, `layer`.++## Control at runtime++Read the `SpineManager` and drive tracks, skins, and mixing:++```typescript+import { defineSystem, Res, SpineManager } from 'esengine';++defineSystem([Res(SpineManager)], (spine) => {+ spine.setAnimation(entity, 'walk', true); // play looped 'walk'+ spine.setSkin(entity, 'armor'); // swap skin+ spine.setMixDuration(entity, 'idle', 'walk', 0.2); // 0.2s crossfade+});+```++Useful methods: `setAnimation`, `setSkin`, `setEntityProps`, `getAnimations`,+`getSkins`, `getBounds`, `setAttachment`, `setMixDuration`, `setDefaultMix`.++## Animation events++The `SpineEvents` resource publishes track events once per frame — read it in+the same frame:++```typescript+import { SpineEvents } from 'esengine';++defineSystem([Res(SpineEvents)], (spineEvents) => {+ for (const e of spineEvents.events) {+ // e.type: 'start' | 'interrupt' | 'end' | 'complete' | 'event'+ if (e.type === 'complete') { /* e.entity, e.animationName */ }+ }+});+```++<Aside type="note">+ Estella supports Spine **3.8 / 4.1 / 4.2** — each skeleton version loads its+ own WebAssembly backend on demand (pay-for-use; nothing loads until a skeleton+ of that version appears). Entities sharing the same skeleton + atlas share one+ loaded, ref-counted skeleton.+</Aside>++<Aside type="caution">+ The bundled Spine Runtimes are proprietary. Shipping a game that uses Spine+ requires a valid Spine license from Esoteric Software — separate from+ Estella's own license.+</Aside>diff --git a/docs/astro/src/content/docs/guides/tilemap.mdx b/docs/astro/src/content/docs/guides/tilemap.mdxnew file mode 100644index 000000000..16ef23766--- /dev/null+++ b/docs/astro/src/content/docs/guides/tilemap.mdx@@ -0,0 +1,60 @@+---+title: Tilemaps+description: Load Tiled maps, or build and edit tile layers through the API.+---++import { Aside } from '@astrojs/starlight/components';++Estella renders tile layers in the C++/WebAssembly core. There are two ways in:+a high-level component that loads a whole map from a file, and a low-level API+for building and editing layers yourself.++## High-level: load a Tiled map++Give an entity a `Tilemap` component pointing at a Tiled JSON (`.tmj`) file. The+plugin loads it, spawns a `TilemapLayer` entity per layer, and (in play mode)+applies tile collision:++```typescript+import { Tilemap, Transform } from 'esengine';++world.spawn({+ [Tilemap]: { source: 'assets/maps/level.tmj' },+ [Transform]: { position: { x: 0, y: 0, z: 0 } },+});+```++## Low-level: build layers with `TilemapAPI`++Each layer is a `TilemapLayer` component (cell size, tileset texture, columns,+render layer, tint, opacity, parallax). Edit tiles through `TilemapAPI`:++```typescript+import { defineSystem, Res, TilemapAPI } from 'esengine';++defineSystem([Res(TilemapAPI)], (tilemap) => {+ tilemap.initLayer(entity, 32, 32, 16, 16); // 32x32 tiles, 16px cells++ const tiles = new Uint16Array(32 * 32); // tile ids (0 = empty)+ tiles[0] = 1;+ tilemap.setTiles(entity, tiles);++ tilemap.setTile(entity, 5, 3, 7); // single tile+ tilemap.flipTile(entity, 5, 3, true, false, false); // flip horizontally++ tilemap.setTileAnimation(entity, 10, [ // animate tile id 10+ { tileId: 10, duration: 100 },+ { tileId: 11, duration: 100 },+ ]);+});+```++Other methods: `getTile`, `fillRect`, `rotateTile`, `initInfiniteLayer` (chunked+infinite maps), `setTilesets`, `tileToWorld` / `worldToTile`.++<Aside type="note">+ Tile **collision is play-mode only** — static colliders are spawned from+ collidable tiles (marked in the `.estileset` tileset) when the scene runs; they+ are never in the edit world or serialized. Tile animations advance+ automatically once set; you only call `setTileAnimation` once.+</Aside>diff --git a/docs/astro/src/content/docs/guides/ui.mdx b/docs/astro/src/content/docs/guides/ui.mdxnew file mode 100644index 000000000..6967fb679--- /dev/null+++ b/docs/astro/src/content/docs/guides/ui.mdx@@ -0,0 +1,70 @@+---+title: UI+description: Flexbox layout, text, and interactive widgets.+---++import { Aside } from '@astrojs/starlight/components';++Estella's UI is a CSS-like flexbox system solved in the C++ core. You compose an+interface from `UINode` boxes, lay them out with `FlexContainer`, render `Text`+and `UIVisual`, and make things clickable with `Interactable`.++## Layout with `UINode` + `FlexContainer`++`UINode` is the box-model primitive. Build dimensions with `px()`, `percent()`,+or `auto()`:++```typescript+import { spawnUIEntity, buildUINode, px, percent } from 'esengine';++spawnUIEntity({+ node: buildUINode({ width: px(240), height: percent(100) }),+});+```++`FlexContainer` controls how children flow (`direction`, `justifyContent`,+`alignItems`, `gap`, `padding`). Layout is recomputed each frame, so changing a+property just works.++## Text++The `Text` component renders through an SDF glyph atlas: `content`, `fontSize`,+`color`, `align`, `bold`, `italic`, `strokeColor`, `shadowColor`, `wordWrap`,+`richText`, and more.++## Widgets++Widget factories compose the primitives into ready controls —+`createButton`, `createToggle`, `createSlider`, `createProgress`,+`createDialog`, `createDropdown`:++```typescript+import { createButton } from 'esengine';++createButton({+ world: app.world,+ events: uiPlugin.events,+ parent: canvasEntity,+ text: 'Play',+ states: {+ normal: { color: { r: 1, g: 1, b: 1, a: 1 } },+ hover: { color: { r: 0.8, g: 0.8, b: 0.8, a: 1 } },+ pressed: { color: { r: 0.6, g: 0.6, b: 0.6, a: 1 } },+ },+ onClick: () => audio.playSFX('assets/audio/click.wav'),+});+```++## Interaction and events++`Interactable` marks an entity clickable; the system writes read-only pointer+state to `UIInteraction` (`hovered`, `pressed`, `justPressed`, `justReleased`).+For input handling, subscribe to the UI event bus (`UIEvents`) — events like+`click`, `hover_enter`, `change`, `submit`, `drag_move` bubble up the parent+chain.++<Aside type="note">+ There is no `RectTransform` — `UINode` replaces it with real flexbox+ (`px`/`percent`/`auto` and `Absolute` positioning via insets). `UIInteraction`+ is written by the engine; drive your logic from events, not by mutating it.+</Aside>diff --git a/docs/astro/src/content/docs/guides/wechat.mdx b/docs/astro/src/content/docs/guides/wechat.mdxnew file mode 100644index 000000000..b49cd656c--- /dev/null+++ b/docs/astro/src/content/docs/guides/wechat.mdx@@ -0,0 +1,60 @@+---+title: WeChat MiniGame+description: Build and export a game for WeChat MiniGames, with subpackages.+---++import { Steps, Aside } from '@astrojs/starlight/components';++Estella exports the same project to **WeChat MiniGames**. You build the engine+for the WeChat target, export the game from the editor, and open the result in+WeChat DevTools.++## Build the engine for WeChat++The WeChat target compiles the C++ core with WeChat's `WXWebAssembly` shims:++```bash+node build-tools/cli.js build -t wechat+# optional side modules, only if your game uses them:+node build-tools/cli.js build -t spine-wechat+node build-tools/cli.js build -t physics-wechat+```++## Export from the editor++<Steps>++1. In **Project Settings → Packaging → WeChat**, set your AppID and orientation.++2. Click **Export Game**. Estella cooks assets, bundles the SDK + your scripts+ (as CommonJS, via esbuild), transforms scenes, and writes a standalone+ MiniGame package.++</Steps>++The output directory contains `game.js` (entry), `game-bundle.js` (SDK ++scripts), `game.json` / `project.config.json` (WeChat config), the+`asset-manifest.json`, your scenes, and the `wasm/` engine + side modules. Open+that directory in WeChat DevTools to compile, test, and submit.++## Subpackages (分包)++Lazy asset groups become WeChat **subPackages** in `game.json`. At runtime,+`assets.loadGroup('level2')` triggers `wx.loadSubpackage` under the hood, so+levels download on demand rather than bloating the initial package:++```json+{+ "deviceOrientation": "landscape",+ "subPackages": [+ { "name": "level2", "root": "subpackages/level2" }+ ]+}+```++<Aside type="caution">+ **Build the side modules your game needs.** If a scene uses Spine or physics+ but you didn't build `spine-wechat` / `physics-wechat`, the export warns and+ the game fails at runtime. The exporter only wires in the side modules the+ entry scene actually requires, so unused ones add no weight.+</Aside>diff --git a/docs/astro/src/content/docs/zh-cn/guides/assets.mdx b/docs/astro/src/content/docs/zh-cn/guides/assets.mdxnew file mode 100644index 000000000..ee76f5344--- /dev/null+++ b/docs/astro/src/content/docs/zh-cn/guides/assets.mdx@@ -0,0 +1,49 @@+---+title: 资源+description: 资源如何被引用、烘焙,以及在运行时加载。+---++import { Aside } from '@astrojs/starlight/components';++项目里每个资源都有一个稳定的 UUID。场景与预制体按 UUID 引用资源;构建时引擎只**烘焙**+(cook)你的游戏真正能触达的资源,运行时再通过清单加载它们。++## 引用资源++资源以规范形式 `@uuid:<uuid>` 按 UUID 引用。编辑器会管理这些——你几乎不用手写。++## 烘焙(cook)++烘焙从入口场景出发遍历依赖图,**剔除一切触达不到的资源**,暂存可达文件,并写出+`assets.manifest.json`(运行时消费的映射)。它还可选地压缩纹理:PNG 被编码为 GPU 就绪+的 **KTX2**(Basis Universal),运行时再转码为设备支持的最佳格式(ASTC → ETC2 → S3TC,+最后回退到 RGBA8)。++## 运行时加载++```typescript+import { defineSystem, Res, Assets } from 'esengine';++defineSystem([Res(Assets)], async (assets) => {+ const texture = await assets.load('@uuid:a1234567-...');+});+```++## 可寻址分组(分包)++位于 `subpackages/<name>/…` 文件夹下的资源属于惰性分组 `<name>`;其余属于会被急切加载的+`main` 分组。按需加载某个分组:++```typescript+const bundle = await assets.loadGroup('level2', (loaded, total) => {+ console.log(`${loaded}/${total}`);+});+```++正是这种分组映射到[微信分包](/docs/zh-cn/guides/wechat/),实现按需下载。++<Aside type="note">+ 内容哈希基于**暂存后**的字节(PNG→KTX2 编码之后)计算,因此清单里的哈希标识的是最终+ 发布的产物,相同文件会去重成一份。`subpackages/` 下的资源即使触达不到也总会被包含——+ 只是分组归属不同而已。+</Aside>diff --git a/docs/astro/src/content/docs/zh-cn/guides/audio.mdx b/docs/astro/src/content/docs/zh-cn/guides/audio.mdxnew file mode 100644index 000000000..625d87382--- /dev/null+++ b/docs/astro/src/content/docs/zh-cn/guides/audio.mdx@@ -0,0 +1,54 @@+---+title: 音频+description: 播放音效与音乐、混音总线,以及空间音频。+---++import { Aside } from '@astrojs/starlight/components';++音频默认已注册。通过 `Audio` 资源播放一次性音效与音乐,或用 `AudioSource` 组件以声明+方式驱动播放。++## 在系统里播放++```typescript+import { defineSystem, Res, Audio } from 'esengine';++defineSystem([Res(Audio)], (audio) => {+ audio.playSFX('assets/audio/kick.wav', { volume: 1.0, pitch: 1.0 });+ audio.playBGM('assets/audio/theme.ogg', { fadeIn: 0.5 });+});+```++`AudioAPI` 还有 `stopBGM(fadeOut?)`、`stopAll()`、`preload(url)` /+`preloadAll(urls)`,以及混音音量:`setMasterVolume`、`setMusicVolume`、+`setSFXVolume`、`setUIVolume`(均为 `0–1`)。++`playSFX` 返回一个 `AudioHandle`,可 `stop()`、`pause()`、`resume()`、+`setVolume()`、`setPan()`、`setLoop()`。++## 声明式播放:`AudioSource`++给实体挂上 `AudioSource`,无需写代码即可播放某个片段:`clip`、`bus`(默认 `"sfx"`)、+`volume`、`pitch`、`loop`、`playOnAwake`,以及空间字段(`spatial`、`minDistance`、+`maxDistance`、`attenuationModel`)。当 `playOnAwake` 且 `enabled` 时,音频系统会自动+播放它。++## 混音总线++混音器是分层的:`master → { music, sfx, ui, voice }`。设置某个总线的音量会缩放它下面的+一切:++```typescript+audio.setSFXVolume(0.5); // 降低音效+audio.setMasterVolume(0.8);+```++## 空间音频++把 `AudioSource.spatial` 设为 `true`,并在相机/玩家实体上放一个启用的 `AudioListener`;+距离衰减遵循音源的 `attenuationModel`。++<Aside type="caution">+ `playSFX` 会自动预加载未缓存的片段并在就绪后播放,因此第一次触发可能是静音的——请+ 提前调用 `preload(url)` 以保证时机。浏览器还要求先有一次用户手势才能开始播放音频。+</Aside>diff --git a/docs/astro/src/content/docs/zh-cn/guides/physics.mdx b/docs/astro/src/content/docs/zh-cn/guides/physics.mdxnew file mode 100644index 000000000..9f072385f--- /dev/null+++ b/docs/astro/src/content/docs/zh-cn/guides/physics.mdx@@ -0,0 +1,96 @@+---+title: 物理+description: 刚体、碰撞体、力、查询与碰撞事件。+---++import { Aside } from '@astrojs/starlight/components';++Estella 的物理运行在 C++/WebAssembly 内核中。你添加物理插件,给实体挂上 `RigidBody`+和一个碰撞体,再通过 `Physics` API 驱动或查询它。++## 启用物理++```typescript+import { PhysicsPlugin } from 'esengine/physics';++app.addPlugin(new PhysicsPlugin('physics.js', {+ gravity: { x: 0, y: -9.81 },+}));+```++模块异步加载;初始化完成后物理即就绪。++## 刚体与碰撞体++挂上一个 `RigidBody` 加一个碰撞体形状。**碰撞体尺寸的单位是米,不是像素**——把像素+尺寸除以你的「每单位像素数」(PPU):++```typescript+import { RigidBody, BodyType, CircleCollider, BoxCollider } from 'esengine';++const PPU = 100;++cmds.spawn()+ .insert(Transform, { position: { x, y, z: 0 } })+ .insert(RigidBody, { bodyType: BodyType.Dynamic })+ .insert(CircleCollider, { radius: 24 / PPU, restitution: 0.4 });+```++- **`BodyType`** —— `Static`(不可移动)、`Kinematic`(由你移动)、`Dynamic`(由模拟+ 驱动)。+- **碰撞体形状** —— `BoxCollider`、`CircleCollider`、`CapsuleCollider`、+ `SegmentCollider`、`PolygonCollider`、`ChainCollider`。都带 `density`、`friction`、+ `restitution`、`isSensor`、`categoryBits`、`maskBits`。+- **关节** —— `RevoluteJoint`、`DistanceJoint`、`PrismaticJoint`、`WeldJoint`、+ `WheelJoint`。++## 碰撞层++`categoryBits`(该刚体所在的层)与 `maskBits`(它会与哪些层碰撞)是 16 位过滤器。+两个刚体只有在各自的 category 都落在对方的 mask 里时才会碰撞:++```typescript+const LAYER_PLAYER = 0x0001;+const LAYER_GROUND = 0x0008;++.insert(CircleCollider, {+ radius: 16 / PPU,+ categoryBits: LAYER_PLAYER,+ maskBits: LAYER_PLAYER | LAYER_GROUND,+});+```++## 力、速度与查询++在系统里读取 `Physics` 资源,推动刚体并查询世界:++```typescript+import { defineSystem, Res, Physics } from 'esengine';++defineSystem([Res(Physics)], (physics) => {+ physics.applyImpulse(player, { x: 0, y: 5 }); // 跳跃+ physics.setLinearVelocity(player, { x: 3, y: 0 });++ // 查询以像素为单位,自动按 PPU 缩放。+ const hits = physics.raycast(origin, direction, 200);+ const inRange = physics.overlapCircle(center, 64);+});+```++## 碰撞事件++`PhysicsEvents` 资源携带当前帧的接触信息:++```typescript+import { PhysicsEvents } from 'esengine';++defineSystem([Res(PhysicsEvents)], (events) => {+ for (const c of events.collisionEnters) { /* c.entityA, c.entityB */ }+ for (const s of events.sensorEnters) { /* 触发体 */ }+});+```++<Aside type="caution">+ 给碰撞体设 `isSensor: true`,可以在**没有物理响应**的情况下获得进入/离开事件+ (触发区)。物理按固定时间步进,而不是帧间隔,所以每帧都要读 `PhysicsEvents`。+</Aside>diff --git a/docs/astro/src/content/docs/zh-cn/guides/spine.mdx b/docs/astro/src/content/docs/zh-cn/guides/spine.mdxnew file mode 100644index 000000000..ab443d474--- /dev/null+++ b/docs/astro/src/content/docs/zh-cn/guides/spine.mdx@@ -0,0 +1,60 @@+---+title: Spine 动画+description: 用 SpineAnimation 与 SpineManager 播放 Spine 骨骼动画。+---++import { Aside } from '@astrojs/starlight/components';++Estella 内置 [Spine](https://esotericsoftware.com/) 骨骼动画。给实体一个+`SpineAnimation` 组件(通常在编辑器里配置),然后在运行时通过 `SpineManager` 控制它。++## `SpineAnimation` 组件++把实体指向一套骨骼 + 图集,以及它的播放状态:++- `skeletonPath`、`atlasPath` —— 要加载的 Spine 资源。+- `animation`、`loop`、`playing` —— 当前轨道。+- `skin`、`skeletonScale`、`timeScale`、`flipX`、`flipY`、`color`、`layer`。++## 运行时控制++读取 `SpineManager`,驱动轨道、皮肤与混合:++```typescript+import { defineSystem, Res, SpineManager } from 'esengine';++defineSystem([Res(SpineManager)], (spine) => {+ spine.setAnimation(entity, 'walk', true); // 循环播放 'walk'+ spine.setSkin(entity, 'armor'); // 切换皮肤+ spine.setMixDuration(entity, 'idle', 'walk', 0.2); // 0.2 秒交叉淡入+});+```++常用方法:`setAnimation`、`setSkin`、`setEntityProps`、`getAnimations`、+`getSkins`、`getBounds`、`setAttachment`、`setMixDuration`、`setDefaultMix`。++## 动画事件++`SpineEvents` 资源每帧发布一次轨道事件——在同一帧里读取它:++```typescript+import { SpineEvents } from 'esengine';++defineSystem([Res(SpineEvents)], (spineEvents) => {+ for (const e of spineEvents.events) {+ // e.type: 'start' | 'interrupt' | 'end' | 'complete' | 'event'+ if (e.type === 'complete') { /* e.entity, e.animationName */ }+ }+});+```++<Aside type="note">+ Estella 支持 Spine **3.8 / 4.1 / 4.2**——每个骨骼版本按需加载各自的 WebAssembly+ 后端(用到才加载;没有该版本的骨骼出现时不会加载)。使用同一套骨骼 + 图集的多个+ 实体共享同一份加载后、引用计数的骨骼。+</Aside>++<Aside type="caution">+ 随附的 Spine Runtimes 是专有软件。发布使用 Spine 的游戏需要 Esoteric Software 的+ 有效 Spine 授权——与 Estella 自身的许可证相互独立。+</Aside>diff --git a/docs/astro/src/content/docs/zh-cn/guides/tilemap.mdx b/docs/astro/src/content/docs/zh-cn/guides/tilemap.mdxnew file mode 100644index 000000000..c79bcdd6f--- /dev/null+++ b/docs/astro/src/content/docs/zh-cn/guides/tilemap.mdx@@ -0,0 +1,57 @@+---+title: 瓦片地图+description: 加载 Tiled 地图,或通过 API 构建和编辑瓦片图层。+---++import { Aside } from '@astrojs/starlight/components';++Estella 在 C++/WebAssembly 内核中渲染瓦片图层。有两种用法:一个从文件加载整张地图的+高层组件,以及一套自己构建、编辑图层的低层 API。++## 高层:加载 Tiled 地图++给实体一个 `Tilemap` 组件,指向 Tiled JSON(`.tmj`)文件。插件会加载它,为每个图层+生成一个 `TilemapLayer` 实体,并在运行模式下应用瓦片碰撞:++```typescript+import { Tilemap, Transform } from 'esengine';++world.spawn({+ [Tilemap]: { source: 'assets/maps/level.tmj' },+ [Transform]: { position: { x: 0, y: 0, z: 0 } },+});+```++## 低层:用 `TilemapAPI` 构建图层++每个图层是一个 `TilemapLayer` 组件(格子尺寸、图集贴图、列数、渲染层、着色、不透明度、+视差)。通过 `TilemapAPI` 编辑瓦片:++```typescript+import { defineSystem, Res, TilemapAPI } from 'esengine';++defineSystem([Res(TilemapAPI)], (tilemap) => {+ tilemap.initLayer(entity, 32, 32, 16, 16); // 32x32 格,16px 格子++ const tiles = new Uint16Array(32 * 32); // 瓦片 id(0 = 空)+ tiles[0] = 1;+ tilemap.setTiles(entity, tiles);++ tilemap.setTile(entity, 5, 3, 7); // 单个瓦片+ tilemap.flipTile(entity, 5, 3, true, false, false); // 水平翻转++ tilemap.setTileAnimation(entity, 10, [ // 让瓦片 id 10 动起来+ { tileId: 10, duration: 100 },+ { tileId: 11, duration: 100 },+ ]);+});+```++其他方法:`getTile`、`fillRect`、`rotateTile`、`initInfiniteLayer`(分块的无限地图)、+`setTilesets`、`tileToWorld` / `worldToTile`。++<Aside type="note">+ 瓦片**碰撞仅在运行模式**存在——静态碰撞体在场景运行时由可碰撞瓦片(在 `.estileset`+ 图集里标记)生成;它们不存在于编辑世界中,也不会被序列化。瓦片动画一旦设置便自动+ 推进;`setTileAnimation` 只需调用一次。+</Aside>diff --git a/docs/astro/src/content/docs/zh-cn/guides/ui.mdx b/docs/astro/src/content/docs/zh-cn/guides/ui.mdxnew file mode 100644index 000000000..73169e0de--- /dev/null+++ b/docs/astro/src/content/docs/zh-cn/guides/ui.mdx@@ -0,0 +1,65 @@+---+title: UI+description: 弹性盒布局、文本与可交互控件。+---++import { Aside } from '@astrojs/starlight/components';++Estella 的 UI 是一套在 C++ 内核里求解的类 CSS 弹性盒(flexbox)系统。你用 `UINode`+盒子组合界面,用 `FlexContainer` 布局,用 `Text` 和 `UIVisual` 渲染,再用+`Interactable` 让元素可点击。++## 用 `UINode` + `FlexContainer` 布局++`UINode` 是盒模型原语。用 `px()`、`percent()` 或 `auto()` 构建尺寸:++```typescript+import { spawnUIEntity, buildUINode, px, percent } from 'esengine';++spawnUIEntity({+ node: buildUINode({ width: px(240), height: percent(100) }),+});+```++`FlexContainer` 控制子元素如何排布(`direction`、`justifyContent`、`alignItems`、+`gap`、`padding`)。布局每帧重新计算,因此改属性即刻生效。++## 文本++`Text` 组件通过 SDF 字形图集渲染:`content`、`fontSize`、`color`、`align`、`bold`、+`italic`、`strokeColor`、`shadowColor`、`wordWrap`、`richText` 等。++## 控件++控件工厂把这些原语组合成开箱即用的控件——`createButton`、`createToggle`、+`createSlider`、`createProgress`、`createDialog`、`createDropdown`:++```typescript+import { createButton } from 'esengine';++createButton({+ world: app.world,+ events: uiPlugin.events,+ parent: canvasEntity,+ text: 'Play',+ states: {+ normal: { color: { r: 1, g: 1, b: 1, a: 1 } },+ hover: { color: { r: 0.8, g: 0.8, b: 0.8, a: 1 } },+ pressed: { color: { r: 0.6, g: 0.6, b: 0.6, a: 1 } },+ },+ onClick: () => audio.playSFX('assets/audio/click.wav'),+});+```++## 交互与事件++`Interactable` 标记实体可点击;系统会把只读的指针状态写入 `UIInteraction`+(`hovered`、`pressed`、`justPressed`、`justReleased`)。要处理输入,请订阅 UI 事件+总线(`UIEvents`)——像 `click`、`hover_enter`、`change`、`submit`、`drag_move` 这些+事件会沿父链冒泡。++<Aside type="note">+ 这里没有 `RectTransform`——`UINode` 用真正的弹性盒取代它(`px`/`percent`/`auto`+ 以及通过 inset 的 `Absolute` 定位)。`UIInteraction` 由引擎写入;请用事件驱动逻辑,+ 而不是去修改它。+</Aside>diff --git a/docs/astro/src/content/docs/zh-cn/guides/wechat.mdx b/docs/astro/src/content/docs/zh-cn/guides/wechat.mdxnew file mode 100644index 000000000..f6f1fd479--- /dev/null+++ b/docs/astro/src/content/docs/zh-cn/guides/wechat.mdx@@ -0,0 +1,56 @@+---+title: 微信小游戏+description: 为微信小游戏构建和导出游戏,并使用分包。+---++import { Steps, Aside } from '@astrojs/starlight/components';++Estella 能把同一个项目导出为**微信小游戏**。你为微信目标构建引擎,从编辑器导出游戏,+再用微信开发者工具打开结果。++## 为微信构建引擎++微信目标用微信的 `WXWebAssembly` 垫片编译 C++ 内核:++```bash+node build-tools/cli.js build -t wechat+# 可选的侧模块,仅当你的游戏用到时:+node build-tools/cli.js build -t spine-wechat+node build-tools/cli.js build -t physics-wechat+```++## 从编辑器导出++<Steps>++1. 在**项目设置 → 打包 → 微信**中,填写 AppID 与横竖屏方向。++2. 点击**导出游戏**。Estella 会烘焙资源,把 SDK 与你的脚本打包(用 esbuild 打成+ CommonJS),转换场景,并写出一个独立的小游戏包。++</Steps>++输出目录包含 `game.js`(入口)、`game-bundle.js`(SDK + 脚本)、`game.json` /+`project.config.json`(微信配置)、`asset-manifest.json`、你的场景,以及 `wasm/` 引擎+和侧模块。用微信开发者工具打开该目录即可编译、测试、提交。++## 分包(subpackages)++惰性资源分组会成为 `game.json` 里的微信 **subPackages**。运行时,+`assets.loadGroup('level2')` 底层会触发 `wx.loadSubpackage`,于是关卡按需下载,而不会+撑大初始包:++```json+{+ "deviceOrientation": "landscape",+ "subPackages": [+ { "name": "level2", "root": "subpackages/level2" }+ ]+}+```++<Aside type="caution">+ **构建你的游戏需要的侧模块。** 如果某个场景用了 Spine 或物理,但你没构建+ `spine-wechat` / `physics-wechat`,导出会警告且游戏在运行时失败。导出器只接入入口+ 场景实际需要的侧模块,未用到的不会增加体积。+</Aside>