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: correct the spine and ui guides against real SDK API
yhh641754999b6c
diff --git a/docs/astro/src/content/docs/guides/spine.mdx b/docs/astro/src/content/docs/guides/spine.mdxindex e3ddfb016..c5633f9ab 100644--- a/docs/astro/src/content/docs/guides/spine.mdx+++ b/docs/astro/src/content/docs/guides/spine.mdx@@ -1,48 +1,47 @@---title: Spine Animation-description: Play Spine skeletal animations with SpineAnimation and SpineManager.+description: Play Spine skeletal animations with the SpineAnimation component.---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`.+Estella has built-in [Spine](https://esotericsoftware.com/) skeletal animation,+driven by the `SpineAnimation` component.## The `SpineAnimation` component-Points an entity at a skeleton + atlas and its playback state:+You usually add it in the editor and point it at your Spine assets. Its fields:-- `skeletonPath`, `atlasPath` — the Spine assets to load.-- `animation`, `loop`, `playing` — the current track.-- `skin`, `skeletonScale`, `timeScale`, `flipX`, `flipY`, `color`, `layer`.+- `skeletonPath`, `atlasPath` — the skeleton and atlas to load.+- `animation`, `loop`, `playing` — the current track and its playback state.+- `skin`, `timeScale`, `skeletonScale`, `flipX`, `flipY`, `color`, `layer`.-## Control at runtime+## Control it at runtime-Read the `SpineManager` and drive tracks, skins, and mixing:+Because it's a normal component, you change playback by writing its fields from+a system — query it with `Mut`:```typescript-import { defineSystem, Res, SpineManager } from 'esengine';+import { defineSystem, Query, Mut, SpineAnimation } 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+const play = defineSystem([Query(Mut(SpineAnimation))], (q) => {+ for (const [entity, spine] of q) {+ spine.animation = 'walk';+ spine.loop = true;+ spine.playing = true;+ }});```-Useful methods: `setAnimation`, `setSkin`, `setEntityProps`, `getAnimations`,-`getSkins`, `getBounds`, `setAttachment`, `setMixDuration`, `setDefaultMix`.-## Animation eventsThe `SpineEvents` resource publishes track events once per frame — read it inthe same frame:```typescript-import { SpineEvents } from 'esengine';+import { defineSystem, Res, SpineEvents } from 'esengine';-defineSystem([Res(SpineEvents)], (spineEvents) => {+const onSpine = 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 */ }@@ -52,9 +51,8 @@ defineSystem([Res(SpineEvents)], (spineEvents) => {<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.+ own WebAssembly backend on demand (pay-for-use). Entities that share the same+ skeleton + atlas share one loaded, ref-counted skeleton.</Aside><Aside type="caution">diff --git a/docs/astro/src/content/docs/guides/ui.mdx b/docs/astro/src/content/docs/guides/ui.mdxindex 6967fb679..63ee4ab38 100644--- a/docs/astro/src/content/docs/guides/ui.mdx+++ b/docs/astro/src/content/docs/guides/ui.mdx@@ -1,70 +1,57 @@---title: UI-description: Flexbox layout, text, and interactive widgets.+description: Flexbox layout, text, and pointer interaction.---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`.+interface in the editor from UI components, then read interaction state from+your systems.-## Layout with `UINode` + `FlexContainer`+## UI components-`UINode` is the box-model primitive. Build dimensions with `px()`, `percent()`,-or `auto()`:+Add these to entities in the editor to build an interface:-```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.+- **`UINode`** — the layout box. Flexbox fields live on it directly: `width`,+ `height` (and min/max), `flexGrow`, `flexShrink`, `flexBasis`, `alignSelf`,+ `margin*`, and `inset*` for absolute positioning. Layout is recomputed each+ frame.+- **`Text`** — text rendered through an SDF glyph atlas (`content`, `fontSize`,+ `color`, `align`, `bold`, `italic`, stroke/shadow, `wordWrap`, `richText`).+- **`UIVisual`** — solid-color, textured, sliced, or tiled fills.+- **`UIMask`** — clips its children.+- **`Interactable`** — marks an entity hit-testable (`enabled`, `blockRaycast`,+ `raycastTarget`).-## Text+## Handling interaction-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`:+The hit-test system writes per-frame pointer state into `UIInteraction`+(`hovered`, `pressed`, `justPressed`, `justReleased`). It's **read-only for your+logic** — query it alongside `Interactable` to react:```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'),-});+import { defineSystem, Query, Interactable, UIInteraction } from 'esengine';++const handleClicks = defineSystem(+ [Query(Interactable, UIInteraction)],+ (q) => {+ for (const [entity, _gate, state] of q) {+ if (state.justReleased) {+ // entity was clicked+ }+ }+ }+);```-## 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.+For richer input — bubbling `click` / `hover_enter` / `change` / `submit` /+`drag` events across the parent chain — read the `UIEvents` resource, the UI+event bus.<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.+ There is no `RectTransform`: `UINode` is real flexbox, sized with `px`,+ `percent`, and `auto` dimensions (set in the inspector), plus `Absolute`+ positioning via insets. `UIInteraction` is written by the engine each frame —+ drive your logic from it or from `UIEvents`, don't mutate it.</Aside>diff --git a/docs/astro/src/content/docs/zh-cn/guides/spine.mdx b/docs/astro/src/content/docs/zh-cn/guides/spine.mdxindex ab443d474..6abf15b93 100644--- a/docs/astro/src/content/docs/zh-cn/guides/spine.mdx+++ b/docs/astro/src/content/docs/zh-cn/guides/spine.mdx@@ -1,46 +1,45 @@---title: Spine 动画-description: 用 SpineAnimation 与 SpineManager 播放 Spine 骨骼动画。+description: 用 SpineAnimation 组件播放 Spine 骨骼动画。---import { Aside } from '@astrojs/starlight/components';-Estella 内置 [Spine](https://esotericsoftware.com/) 骨骼动画。给实体一个-`SpineAnimation` 组件(通常在编辑器里配置),然后在运行时通过 `SpineManager` 控制它。+Estella 内置 [Spine](https://esotericsoftware.com/) 骨骼动画,由 `SpineAnimation`+组件驱动。## `SpineAnimation` 组件-把实体指向一套骨骼 + 图集,以及它的播放状态:+通常你在编辑器里添加它并指向你的 Spine 资源。它的字段:-- `skeletonPath`、`atlasPath` —— 要加载的 Spine 资源。-- `animation`、`loop`、`playing` —— 当前轨道。-- `skin`、`skeletonScale`、`timeScale`、`flipX`、`flipY`、`color`、`layer`。+- `skeletonPath`、`atlasPath` —— 要加载的骨骼与图集。+- `animation`、`loop`、`playing` —— 当前轨道及其播放状态。+- `skin`、`timeScale`、`skeletonScale`、`flipX`、`flipY`、`color`、`layer`。## 运行时控制-读取 `SpineManager`,驱动轨道、皮肤与混合:+因为它就是个普通组件,你在系统里写它的字段即可改变播放——用 `Mut` 查询它:```typescript-import { defineSystem, Res, SpineManager } from 'esengine';+import { defineSystem, Query, Mut, SpineAnimation } 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 秒交叉淡入+const play = defineSystem([Query(Mut(SpineAnimation))], (q) => {+ for (const [entity, spine] of q) {+ spine.animation = 'walk';+ spine.loop = true;+ spine.playing = true;+ }});```-常用方法:`setAnimation`、`setSkin`、`setEntityProps`、`getAnimations`、-`getSkins`、`getBounds`、`setAttachment`、`setMixDuration`、`setDefaultMix`。-## 动画事件-`SpineEvents` 资源每帧发布一次轨道事件——在同一帧里读取它:+`SpineEvents` 资源每帧发布一次轨道事件——在同一帧里读取它:```typescript-import { SpineEvents } from 'esengine';+import { defineSystem, Res, SpineEvents } from 'esengine';-defineSystem([Res(SpineEvents)], (spineEvents) => {+const onSpine = 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 */ }@@ -49,9 +48,8 @@ defineSystem([Res(SpineEvents)], (spineEvents) => {```<Aside type="note">- Estella 支持 Spine **3.8 / 4.1 / 4.2**——每个骨骼版本按需加载各自的 WebAssembly- 后端(用到才加载;没有该版本的骨骼出现时不会加载)。使用同一套骨骼 + 图集的多个- 实体共享同一份加载后、引用计数的骨骼。+ Estella 支持 Spine **3.8 / 4.1 / 4.2** —— 每个骨骼版本按需加载各自的 WebAssembly+ 后端(用到才加载)。共享同一套骨骼 + 图集的实体共享同一份加载后、引用计数的骨骼。</Aside><Aside type="caution">diff --git a/docs/astro/src/content/docs/zh-cn/guides/ui.mdx b/docs/astro/src/content/docs/zh-cn/guides/ui.mdxindex 73169e0de..b1e9713e5 100644--- a/docs/astro/src/content/docs/zh-cn/guides/ui.mdx+++ b/docs/astro/src/content/docs/zh-cn/guides/ui.mdx@@ -1,65 +1,52 @@---title: UI-description: 弹性盒布局、文本与可交互控件。+description: 弹性盒布局、文本与指针交互。---import { Aside } from '@astrojs/starlight/components';-Estella 的 UI 是一套在 C++ 内核里求解的类 CSS 弹性盒(flexbox)系统。你用 `UINode`-盒子组合界面,用 `FlexContainer` 布局,用 `Text` 和 `UIVisual` 渲染,再用-`Interactable` 让元素可点击。+Estella 的 UI 是一套在 C++ 内核里求解的类 CSS 弹性盒(flexbox)系统。你在编辑器里用+UI 组件组合界面,再从系统里读取交互状态。-## 用 `UINode` + `FlexContainer` 布局+## UI 组件-`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`)。布局每帧重新计算,因此改属性即刻生效。+- **`UINode`** —— 布局盒。弹性盒字段直接在它身上:`width`、`height`(以及 min/max)、+ `flexGrow`、`flexShrink`、`flexBasis`、`alignSelf`、`margin*`,以及用于绝对定位的+ `inset*`。布局每帧重新计算。+- **`Text`** —— 通过 SDF 字形图集渲染的文本(`content`、`fontSize`、`color`、`align`、+ `bold`、`italic`、描边/阴影、`wordWrap`、`richText`)。+- **`UIVisual`** —— 纯色、贴图、九宫格或平铺填充。+- **`UIMask`** —— 裁剪其子元素。+- **`Interactable`** —— 标记实体可命中测试(`enabled`、`blockRaycast`、+ `raycastTarget`)。-## 文本+## 处理交互-`Text` 组件通过 SDF 字形图集渲染:`content`、`fontSize`、`color`、`align`、`bold`、-`italic`、`strokeColor`、`shadowColor`、`wordWrap`、`richText` 等。--## 控件--控件工厂把这些原语组合成开箱即用的控件——`createButton`、`createToggle`、-`createSlider`、`createProgress`、`createDialog`、`createDropdown`:+命中测试系统每帧把指针状态写入 `UIInteraction`(`hovered`、`pressed`、`justPressed`、+`justReleased`)。它对你的逻辑而言是**只读的**——与 `Interactable` 一起查询即可响应:```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'),-});+import { defineSystem, Query, Interactable, UIInteraction } from 'esengine';++const handleClicks = defineSystem(+ [Query(Interactable, UIInteraction)],+ (q) => {+ for (const [entity, _gate, state] of q) {+ if (state.justReleased) {+ // 该实体被点击了+ }+ }+ }+);```-## 交互与事件--`Interactable` 标记实体可点击;系统会把只读的指针状态写入 `UIInteraction`-(`hovered`、`pressed`、`justPressed`、`justReleased`)。要处理输入,请订阅 UI 事件-总线(`UIEvents`)——像 `click`、`hover_enter`、`change`、`submit`、`drag_move` 这些-事件会沿父链冒泡。+若需要更丰富的输入——沿父链冒泡的 `click` / `hover_enter` / `change` / `submit` /+`drag` 等事件——请读取 `UIEvents` 资源,即 UI 事件总线。<Aside type="note">- 这里没有 `RectTransform`——`UINode` 用真正的弹性盒取代它(`px`/`percent`/`auto`- 以及通过 inset 的 `Absolute` 定位)。`UIInteraction` 由引擎写入;请用事件驱动逻辑,- 而不是去修改它。+ 这里没有 `RectTransform`:`UINode` 是真正的弹性盒,用 `px`、`percent`、`auto` 尺寸+ (在检视面板里设置)加上通过 inset 的 `Absolute` 定位。`UIInteraction` 由引擎每帧+ 写入——请用它或 `UIEvents` 驱动逻辑,不要去修改它。</Aside>