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 BitmapText, UIMask, Name, LabelAtlas docs and update existing guides
esengineb392288fbdeb
diff --git a/docs/astro/astro.config.mjs b/docs/astro/astro.config.mjsindex e8e46bbe9..47cf73ebb 100644--- a/docs/astro/astro.config.mjs+++ b/docs/astro/astro.config.mjs@@ -68,6 +68,7 @@ export default defineConfig({{ label: 'Canvas & Resolution', translations: { 'zh-CN': 'Canvas 与分辨率' }, slug: 'guides/canvas' },{ label: 'Sprite', translations: { 'zh-CN': '精灵' }, slug: 'guides/sprite' },{ label: 'Spine Animation', translations: { 'zh-CN': 'Spine 动画' }, slug: 'guides/spine' },+ { label: 'Bitmap Text', translations: { 'zh-CN': '位图文本' }, slug: 'guides/bitmap-text' },{ label: 'Custom Draw', translations: { 'zh-CN': '自定义绘制' }, slug: 'guides/custom-draw' },{ label: 'Post-Processing', translations: { 'zh-CN': '后处理效果' }, slug: 'guides/post-processing' },],diff --git a/docs/astro/src/content/docs/core-concepts/components.mdx b/docs/astro/src/content/docs/core-concepts/components.mdxindex ff404d1f1..8204f04d6 100644--- a/docs/astro/src/content/docs/core-concepts/components.mdx+++ b/docs/astro/src/content/docs/core-concepts/components.mdx@@ -37,7 +37,14 @@ View settings. At least one active camera is required to see anything. The edito| `nearPlane` | number | Near clipping plane || `farPlane` | number | Far clipping plane || `isActive` | boolean | Whether this camera is used for rendering |-| `priority` | number | Higher priority camera takes precedence |+| `aspectRatio` | number | Camera aspect ratio |+| `priority` | number | Render order — lower priority renders first, higher renders on top |+| `viewportX` | number | Viewport left edge (0–1). Default: 0 |+| `viewportY` | number | Viewport bottom edge (0–1). Default: 0 |+| `viewportW` | number | Viewport width (0–1). Default: 1 |+| `viewportH` | number | Viewport height (0–1). Default: 1 |+| `clearFlags` | number | Buffer clear mode: 0=None, 1=Color, 2=Depth, 3=Both |+| `showFrustum` | boolean | Draw the camera frustum wireframe in the editor |### Canvas@@ -73,6 +80,20 @@ Entity hierarchy for scene graphs.Spine skeletal animation playback. Requires `LocalTransform`. See [Spine Animation guide](/microes/guides/spine/) for full details.+### BitmapText++GPU-rendered text using pre-baked bitmap font atlases (BMFont format). Requires `LocalTransform`. See [Bitmap Text guide](/microes/guides/bitmap-text/) for full details.++| Property | Type | Description |+|----------|------|-------------|+| `text` | string | Text content |+| `color` | Color | Tint color RGBA |+| `fontSize` | number | Scale factor relative to the font's native size |+| `align` | number | Horizontal alignment: 0=Left, 1=Center, 2=Right |+| `spacing` | number | Extra spacing between characters |+| `layer` | number | Render layer |+| `font` | number | Font handle from `assets.loadBitmapFont()` |+### TextUI text rendering. Works with `UIRect` and `Sprite` to display text. See [UI & Text guide](/microes/guides/ui/) for full details.@@ -96,6 +117,22 @@ UI layout rectangle. Defines size, anchor, and pivot for UI elements.| `anchor` | Vec2 | Anchor point (0–1) || `pivot` | Vec2 | Pivot point for rotation |+### UIMask++Clips child entities to the parent's `UIRect` bounds. Requires `UIRect` and `LocalTransform` on the same entity. See [UI & Text guide](/microes/guides/ui/) for details.++| Property | Type | Default | Description |+|----------|------|---------|-------------|+| `enabled` | boolean | `true` | Whether clipping is active |++### Name++A string identifier for the entity. Useful for finding entities by name at runtime.++| Property | Type | Default | Description |+|----------|------|---------|-------------|+| `value` | string | `''` | Entity name |+### PhysicsPhysics components require the `PhysicsPlugin`. See [Physics guide](/microes/guides/physics/) for setup and usage.diff --git a/docs/astro/src/content/docs/guides/assets.mdx b/docs/astro/src/content/docs/guides/assets.mdxindex af42554fe..69973a853 100644--- a/docs/astro/src/content/docs/guides/assets.mdx+++ b/docs/astro/src/content/docs/guides/assets.mdx@@ -74,6 +74,24 @@ if (!result.success) {| `loadSpine(skeleton, atlas, baseUrl?)` | Load Spine skeleton and atlas || `isSpineLoaded(skeleton, atlas)` | Check if a Spine asset pair is already loaded |+## BitmapFont Loading++```typescript+const fontHandle = await assets.loadBitmapFont('assets/my-font.fnt');+```++Supports `.fnt` (BMFont text format) and `.bmfont` (JSON metadata) files. The loader automatically resolves and loads referenced texture atlases.++| Method | Returns | Description |+|--------|---------|-------------|+| `loadBitmapFont(path)` | `Promise<number>` | Load a bitmap font file and its textures. Returns a font handle |+| `getFont(path)` | `number \| undefined` | Get cached font handle, `undefined` if not loaded |+| `releaseFont(path)` | `void` | Release the font and its textures from memory |++<Aside type="note">+ `loadAll` does not currently support bitmap fonts. Load them separately with `loadBitmapFont`.+</Aside>+## Generic File Loading| Method | Returns | Description |@@ -166,25 +184,11 @@ Absolute paths and full URLs are not affected by `baseUrl`.## Embedded Assets-For Playable Ad builds, assets can be embedded directly into the output bundle using `registerEmbeddedAssets`. This eliminates network requests at runtime:--```typescript-import { registerEmbeddedAssets } from 'esengine';--registerEmbeddedAssets(app, {- 'sprites/player.png': 'data:image/png;base64,iVBOR...',- 'data/config.json': 'data:application/json;base64,eyJsZXZlbCI6MX0=',-});-```--The first argument is the `App` instance. Asset values must be data URIs. Once registered, all `assets.loadTexture()` / `assets.loadJson()` calls resolve from the embedded data instead of fetching over the network.--<Aside type="tip">- The editor's Playable build pipeline calls `registerEmbeddedAssets` automatically. You only need to call it manually in custom build workflows.-</Aside>+For Playable Ad builds, the editor's build pipeline automatically embeds all referenced assets as data URIs into the output bundle. At runtime, `assets.loadTexture()` / `assets.loadJson()` and other load calls resolve from the embedded data instead of fetching over the network — no code changes are needed.## Next Steps- [Materials & Shaders](/microes/guides/materials/) — custom shaders and blend modes- [Sprite](/microes/guides/sprite/) — using textures with sprites+- [Bitmap Text](/microes/guides/bitmap-text/) — rendering text with bitmap fonts- [Spine Animation](/microes/guides/spine/) — Spine skeletal animationdiff --git a/docs/astro/src/content/docs/guides/bitmap-text.mdx b/docs/astro/src/content/docs/guides/bitmap-text.mdxnew file mode 100644index 000000000..8e56e196a--- /dev/null+++ b/docs/astro/src/content/docs/guides/bitmap-text.mdx@@ -0,0 +1,149 @@+---+title: Bitmap Text+description: Rendering text with pre-baked bitmap font atlases in ESEngine+---++import { Aside } from '@astrojs/starlight/components';++The `BitmapText` component renders text using pre-baked bitmap font atlases (BMFont format). Unlike the `Text` component which rasterizes fonts via Canvas 2D each frame, `BitmapText` draws directly from a pre-rendered glyph atlas on the GPU.++<Aside type="tip">+ **BitmapText vs Text** — `Text` uses Canvas 2D to rasterize dynamic fonts at runtime, supporting any system font. `BitmapText` uses a pre-rendered glyph atlas (BMFont), giving consistent pixel-perfect results and better performance for static text. Use `Text` when you need dynamic font features (e.g. system fonts, rich styling); use `BitmapText` when you need pixel-art fonts or high-performance HUD text.+</Aside>++## Properties++| Property | Type | Default | Description |+|----------|------|---------|-------------|+| `text` | string | `''` | Text content to display |+| `color` | Color | `{r:1, g:1, b:1, a:1}` | Tint color RGBA (0–1) |+| `fontSize` | number | `1.0` | Scale factor relative to the font's native size |+| `align` | number | `0` | Horizontal alignment: 0=Left, 1=Center, 2=Right |+| `spacing` | number | `0` | Extra spacing between characters (pixels) |+| `layer` | number | `0` | Render layer for draw ordering |+| `font` | number | `0` | Font handle returned by `assets.loadBitmapFont()` |++## Font Formats++BitmapText supports two font formats:++**`.fnt` (BMFont text format)** — The standard BMFont text descriptor. Pair it with a `.png` atlas image:++```+assets/+ my-font.fnt+ my-font_0.png+```++**`.bmfont` (JSON metadata)** — A JSON file that references the `.fnt` and atlas paths:++```json+{+ "font": "my-font.fnt",+ "textures": ["my-font_0.png"]+}+```++Both formats are loaded with the same `assets.loadBitmapFont()` call.++## LabelAtlas++LabelAtlas is a simplified font creation mode for **uniform-grid** glyph atlases — ideal for score counters, timers, and other displays that only need digits or a small set of symbols. All glyphs share the same cell size.++### Editor Workflow++1. In the Content Browser, right-click → **New → BitmapFont** to create a `.bmfont` file+2. Select the font file in the Content Browser — the inspector shows the font editor+3. Choose **LabelAtlas** as the type+4. Map each character to an image file in the glyph list (e.g. `0` → `zero.png`, `1` → `one.png`)+5. Click **Build Atlas** — the editor packs all glyph images into a single atlas PNG and generates a `.fnt` file automatically++The generated font is loaded at runtime through the same `loadBitmapFont()` path as a standard BMFont.++### .bmfont Format (LabelAtlas)++```json+{+ "version": "1.0",+ "type": "label-atlas",+ "glyphs": {+ "0": "digits/zero.png",+ "1": "digits/one.png",+ "2": "digits/two.png"+ },+ "generatedFnt": "my-digits.fnt"+}+```++| Field | Description |+|-------|-------------|+| `type` | `"label-atlas"` — tells the editor to use the LabelAtlas workflow |+| `glyphs` | Map of character → image path |+| `generatedFnt` | Path to the auto-generated `.fnt` file (created by Build Atlas) |++<Aside type="note">+ At runtime, a LabelAtlas font is identical to a standard BMFont — the editor simply generates the `.fnt` and atlas for you. The `BitmapText` component works the same regardless of how the font was created.+</Aside>++## Loading a Bitmap Font++Load the font in a startup system, then assign the handle to your `BitmapText` component:++```typescript+import { defineSystem, addStartupSystem, Res } from 'esengine';+import { Assets } from 'esengine';++addStartupSystem(defineSystem(+ [Res(Assets)],+ async (assets) => {+ const font = await assets.loadBitmapFont('assets/my-font.fnt');+ // font is the handle to use with BitmapText.font+ }+));+```++### Font Resource API++| Method | Returns | Description |+|--------|---------|-------------|+| `loadBitmapFont(path)` | `Promise<number>` | Load a `.fnt` or `.bmfont` file and its textures. Returns a font handle |+| `getFont(path)` | `number \| undefined` | Get cached font handle, `undefined` if not loaded |+| `releaseFont(path)` | `void` | Release the font and its textures from memory |++<Aside type="note">+ When a BitmapText entity references a font file in the scene editor, the scene loader calls `loadBitmapFont` automatically. You only need to call it manually when creating BitmapText entities at runtime.+</Aside>++## Modifying BitmapText at Runtime++Query the `BitmapText` component with `Mut()` to change text or style during gameplay:++```typescript+import { defineSystem, addSystem, Query, Mut } from 'esengine';+import { BitmapText } from 'esengine';++addSystem(defineSystem(+ [Query(Mut(BitmapText))],+ (query) => {+ for (const [entity, bitmapText] of query) {+ bitmapText.text = 'Hello!';+ bitmapText.fontSize = 2.0;+ bitmapText.color = { r: 1, g: 0.8, b: 0, a: 1 };+ }+ }+));+```++## Render Order++BitmapText follows the same draw ordering as Sprite:++1. **Z position** (`transform.position.z`) — lower Z draws first (behind)+2. **Layer** (`bitmapText.layer`) — higher layer draws on top++## Next Steps++- [Asset Loading](/microes/guides/assets/) — loading bitmap fonts and other assets+- [UI & Text](/microes/guides/ui/) — Canvas 2D text and UI layout+- [Rendering](/microes/guides/rendering/) — camera, transform, and render order+- [Components](/microes/core-concepts/components/) — all builtin componentsdiff --git a/docs/astro/src/content/docs/guides/rendering.mdx b/docs/astro/src/content/docs/guides/rendering.mdxindex f85c4e0dd..5fc3d8345 100644--- a/docs/astro/src/content/docs/guides/rendering.mdx+++ b/docs/astro/src/content/docs/guides/rendering.mdx@@ -138,6 +138,7 @@ Set these values in the inspector when placing entities, or modify them at runti- [Canvas & Resolution](/microes/guides/canvas/) — screen adaptation and scale modes- [Sprite](/microes/guides/sprite/) — sprite rendering and animation- [Spine Animation](/microes/guides/spine/) — skeletal animation+- [Bitmap Text](/microes/guides/bitmap-text/) — GPU-rendered bitmap font text- [Custom Draw](/microes/guides/custom-draw/) — immediate-mode drawing for debug visualization and dynamic graphics- [Post-Processing](/microes/guides/post-processing/) — full-screen effects (blur, vignette, grayscale)- [Geometry & Meshes](/microes/guides/geometry/) — custom mesh creation for advanced renderingdiff --git a/docs/astro/src/content/docs/guides/spine.mdx b/docs/astro/src/content/docs/guides/spine.mdxindex a9ec62614..3694b6870 100644--- a/docs/astro/src/content/docs/guides/spine.mdx+++ b/docs/astro/src/content/docs/guides/spine.mdx@@ -8,7 +8,7 @@ import { Aside } from '@astrojs/starlight/components';The `SpineAnimation` component plays [Spine](http://esotericsoftware.com/) skeletal animations. Add it to an entity in the scene editor along with `LocalTransform`.<Aside type="note">- Since v0.3.0, Spine uses standalone WASM modules (`spine38` / `spine41` / `spine42`) instead of being bundled into the engine core. Select the Spine version in the editor under **Settings → Project → Spine Version** (`3.8`, `4.1`, or `4.2`). The editor loads the matching runtime automatically — no code is needed.+ Since v0.3.0, Spine uses standalone WASM modules (`spine38` / `spine41` / `spine42`) instead of being bundled into the engine core. Select the Spine version in the editor under **Settings → Project → Spine Version** (`3.8`, `4.1`, or `4.2`). The editor loads the matching runtime automatically — no code is needed. New projects default to **None** — you must select a Spine version to enable Spine.</Aside>## Propertiesdiff --git a/docs/astro/src/content/docs/guides/sprite.mdx b/docs/astro/src/content/docs/guides/sprite.mdxindex 932d24ac9..37185f641 100644--- a/docs/astro/src/content/docs/guides/sprite.mdx+++ b/docs/astro/src/content/docs/guides/sprite.mdx@@ -40,6 +40,33 @@ addSystem(defineSystem());```+## Loading a Texture++The `texture` property expects a texture handle (number), not a file path. Load the image first with `assets.loadTexture()`, then assign the handle:++```typescript+import { defineSystem, addStartupSystem, Res, Query, Mut, Sprite } from 'esengine';+import { Assets } from 'esengine';+import { Player } from './components';++addStartupSystem(defineSystem(+ [Res(Assets), Query(Mut(Sprite), Player)],+ async (assets, query) => {+ const tex = await assets.loadTexture('assets/player.png');+ for (const [entity, sprite] of query) {+ sprite.texture = tex.handle;+ sprite.size = { x: tex.width, y: tex.height };+ }+ }+));+```++<Aside type="note">+ When you assign a texture to a Sprite in the scene editor, the scene loader calls `loadTexture` and sets the handle automatically. You only need the code above when assigning textures at runtime.+</Aside>++See [Asset Loading](/microes/guides/assets/) for the full texture API (`getTexture`, `releaseTexture`, 9-slice metadata, etc.).+## Solid Color RectangleWithout a texture (default), the sprite renders as a solid rectangle using its `color` and `size`.diff --git a/docs/astro/src/content/docs/guides/ui.mdx b/docs/astro/src/content/docs/guides/ui.mdxindex 339973250..09d252f5b 100644--- a/docs/astro/src/content/docs/guides/ui.mdx+++ b/docs/astro/src/content/docs/guides/ui.mdx@@ -120,8 +120,56 @@ addSystem(defineSystem(In the editor: create a text entity with `Text`, `UIRect`, `Sprite`, `LocalTransform`, and the `ScoreDisplay` tag.+## UIMask++`UIMask` clips child entities to the parent entity's `UIRect` bounds. Any child that extends beyond the rectangle is visually cropped.++**Setup:** Add `UIMask`, `UIRect`, and `LocalTransform` to the parent entity. All child entities (and their descendants) will be clipped to this rectangle.++<Aside type="note">+ `UIMaskPlugin` is registered automatically by `createWebApp()`. No manual setup is needed.+</Aside>++### UIMask Properties++| Property | Type | Default | Description |+|----------|------|---------|-------------|+| `enabled` | boolean | `true` | Whether clipping is active |++### Nesting++When a child entity also has `UIMask`, its clip rectangle is the intersection of its own `UIRect` and the parent's clip rect. This allows nested scroll areas or layered clipping.++<Aside type="caution">+ `UIMask` only clips **child** entities — the entity with UIMask itself is not clipped.+</Aside>++### Example: Scrollable List++Create a mask container, then move child entities to scroll:++```typescript+import { defineSystem, addSystem, Res, Input, Query, Mut, LocalTransform, Children } from 'esengine';+import { UIMask } from 'esengine';+import { ScrollList } from './components';++addSystem(defineSystem(+ [Res(Input), Query(Children, UIMask, ScrollList), Query(Mut(LocalTransform))],+ (input, maskQuery, childQuery) => {+ for (const [entity, children, mask, scroll] of maskQuery) {+ const scrollDelta = input.getScrollDelta();+ for (const child of children.entities) {+ const [, transform] = childQuery.get(child);+ transform.position.y += scrollDelta * 20;+ }+ }+ }+));+```+## Next Steps- [Components](/microes/core-concepts/components/) — all builtin components- [Sprite](/microes/guides/sprite/) — sprite rendering details+- [Bitmap Text](/microes/guides/bitmap-text/) — GPU-rendered bitmap font text- [Asset Loading](/microes/guides/assets/) — loading textures and other assetsdiff --git a/docs/astro/src/content/docs/zh/core-concepts/components.mdx b/docs/astro/src/content/docs/zh/core-concepts/components.mdxindex 0a194cd4a..9e0480e1f 100644--- a/docs/astro/src/content/docs/zh/core-concepts/components.mdx+++ b/docs/astro/src/content/docs/zh/core-concepts/components.mdx@@ -37,7 +37,14 @@ import { Aside } from '@astrojs/starlight/components';| `nearPlane` | number | 近裁剪面 || `farPlane` | number | 远裁剪面 || `isActive` | boolean | 是否用于渲染 |-| `priority` | number | 高优先级相机优先 |+| `aspectRatio` | number | 相机宽高比 |+| `priority` | number | 渲染顺序 — 低优先级先渲染,高优先级覆盖在上 |+| `viewportX` | number | 视口左边缘(0–1)。默认:0 |+| `viewportY` | number | 视口底边缘(0–1)。默认:0 |+| `viewportW` | number | 视口宽度(0–1)。默认:1 |+| `viewportH` | number | 视口高度(0–1)。默认:1 |+| `clearFlags` | number | 缓冲区清除模式:0=无, 1=颜色, 2=深度, 3=两者 |+| `showFrustum` | boolean | 在编辑器中显示相机视锥线框 |### Canvas@@ -73,6 +80,20 @@ import { Aside } from '@astrojs/starlight/components';Spine 骨骼动画播放。需要 `LocalTransform`。详见 [Spine 动画指南](/microes/zh/guides/spine/)。+### BitmapText++使用预烘焙位图字体图集(BMFont 格式)进行 GPU 渲染的文本。需要 `LocalTransform`。详见[位图文本指南](/microes/zh/guides/bitmap-text/)。++| 属性 | 类型 | 说明 |+|------|------|------|+| `text` | string | 文本内容 |+| `color` | Color | 着色 RGBA |+| `fontSize` | number | 相对于字体原始大小的缩放因子 |+| `align` | number | 水平对齐:0=左对齐,1=居中,2=右对齐 |+| `spacing` | number | 字符间额外间距 |+| `layer` | number | 渲染层级 |+| `font` | number | `assets.loadBitmapFont()` 返回的字体句柄 |+### TextUI 文本渲染。配合 `UIRect` 和 `Sprite` 组件显示文本。详见 [UI 与文本指南](/microes/zh/guides/ui/)。@@ -96,6 +117,22 @@ UI 布局矩形。定义 UI 元素的尺寸、锚点和旋转中心。| `anchor` | Vec2 | 锚点(0–1) || `pivot` | Vec2 | 旋转中心点 |+### UIMask++将子实体裁剪到父级 `UIRect` 边界内。需要在同一实体上同时挂载 `UIRect` 和 `LocalTransform`。详见 [UI 与文本指南](/microes/zh/guides/ui/)。++| 属性 | 类型 | 默认值 | 说明 |+|------|------|--------|------|+| `enabled` | boolean | `true` | 是否启用裁剪 |++### Name++实体的字符串标识符,用于在运行时按名称查找实体。++| 属性 | 类型 | 默认值 | 说明 |+|------|------|--------|------|+| `value` | string | `''` | 实体名称 |+### 物理物理组件需要 `PhysicsPlugin`。详见[物理指南](/microes/zh/guides/physics/)。diff --git a/docs/astro/src/content/docs/zh/guides/assets.mdx b/docs/astro/src/content/docs/zh/guides/assets.mdxindex 46472ac39..d549d30f3 100644--- a/docs/astro/src/content/docs/zh/guides/assets.mdx+++ b/docs/astro/src/content/docs/zh/guides/assets.mdx@@ -74,6 +74,24 @@ if (!result.success) {| `loadSpine(skeleton, atlas, baseUrl?)` | 加载 Spine 骨骼和图集 || `isSpineLoaded(skeleton, atlas)` | 检查 Spine 资源对是否已加载 |+## 位图字体加载++```typescript+const fontHandle = await assets.loadBitmapFont('assets/my-font.fnt');+```++支持 `.fnt`(BMFont 文本格式)和 `.bmfont`(JSON 元数据)文件。加载器会自动解析并加载引用的纹理图集。++| 方法 | 返回值 | 说明 |+|------|--------|------|+| `loadBitmapFont(path)` | `Promise<number>` | 加载位图字体文件及其纹理,返回字体句柄 |+| `getFont(path)` | `number \| undefined` | 获取已缓存的字体句柄,未加载则返回 `undefined` |+| `releaseFont(path)` | `void` | 从内存中释放字体及其纹理 |++<Aside type="note">+ `loadAll` 目前不支持位图字体,需要使用 `loadBitmapFont` 单独加载。+</Aside>+## 通用文件加载| 方法 | 返回值 | 说明 |@@ -166,25 +184,11 @@ const tex = await assets.loadTexture('sprites/player.png');## 嵌入式资源-对于 Playable Ad 构建,可以使用 `registerEmbeddedAssets` 将资源直接嵌入输出包中,避免运行时网络请求:--```typescript-import { registerEmbeddedAssets } from 'esengine';--registerEmbeddedAssets(app, {- 'sprites/player.png': 'data:image/png;base64,iVBOR...',- 'data/config.json': 'data:application/json;base64,eyJsZXZlbCI6MX0=',-});-```--第一个参数是 `App` 实例,资源值必须是 data URI。注册后,所有 `assets.loadTexture()` / `assets.loadJson()` 调用将从嵌入数据解析,不再发起网络请求。--<Aside type="tip">- 编辑器的 Playable 构建流程会自动调用 `registerEmbeddedAssets`。仅在自定义构建流程中才需要手动调用。-</Aside>+对于 Playable Ad 构建,编辑器的构建流程会自动将所有引用的资源以 data URI 形式嵌入输出包中。运行时 `assets.loadTexture()` / `assets.loadJson()` 等加载调用会直接从嵌入数据解析,无需网络请求,也无需修改任何代码。## 下一步- [材质与着色器](/microes/zh/guides/materials/) — 自定义着色器和混合模式- [精灵](/microes/zh/guides/sprite/) — 纹理与精灵的使用+- [位图文本](/microes/zh/guides/bitmap-text/) — 使用位图字体渲染文本- [Spine 动画](/microes/zh/guides/spine/) — Spine 骨骼动画diff --git a/docs/astro/src/content/docs/zh/guides/bitmap-text.mdx b/docs/astro/src/content/docs/zh/guides/bitmap-text.mdxnew file mode 100644index 000000000..50cdd8d06--- /dev/null+++ b/docs/astro/src/content/docs/zh/guides/bitmap-text.mdx@@ -0,0 +1,149 @@+---+title: 位图文本+description: 在 ESEngine 中使用预烘焙位图字体图集渲染文字+---++import { Aside } from '@astrojs/starlight/components';++`BitmapText` 组件使用预烘焙的位图字体图集(BMFont 格式)渲染文本。与 `Text` 组件每帧通过 Canvas 2D 光栅化字体不同,`BitmapText` 直接从预渲染的字形图集在 GPU 上绘制。++<Aside type="tip">+ **BitmapText vs Text** — `Text` 使用 Canvas 2D 在运行时光栅化动态字体,支持任何系统字体。`BitmapText` 使用预渲染字形图集(BMFont),能获得一致的像素级精确结果和更好的性能。需要动态字体功能(如系统字体、富文本样式)时使用 `Text`;需要像素艺术字体或高性能 HUD 文本时使用 `BitmapText`。+</Aside>++## 属性++| 属性 | 类型 | 默认值 | 说明 |+|------|------|--------|------|+| `text` | string | `''` | 显示的文本内容 |+| `color` | Color | `{r:1, g:1, b:1, a:1}` | 着色 RGBA(0–1) |+| `fontSize` | number | `1.0` | 相对于字体原始大小的缩放因子 |+| `align` | number | `0` | 水平对齐:0=左对齐,1=居中,2=右对齐 |+| `spacing` | number | `0` | 字符间额外间距(像素) |+| `layer` | number | `0` | 渲染层级,用于绘制排序 |+| `font` | number | `0` | `assets.loadBitmapFont()` 返回的字体句柄 |++## 字体格式++BitmapText 支持两种字体格式:++**`.fnt`(BMFont 文本格式)** — 标准 BMFont 文本描述文件,配合 `.png` 图集图片使用:++```+assets/+ my-font.fnt+ my-font_0.png+```++**`.bmfont`(JSON 元数据)** — 引用 `.fnt` 和图集路径的 JSON 文件:++```json+{+ "font": "my-font.fnt",+ "textures": ["my-font_0.png"]+}+```++两种格式都使用相同的 `assets.loadBitmapFont()` 调用加载。++## LabelAtlas++LabelAtlas 是一种简化的字体创建模式,用于**等宽网格**字形图集——非常适合计分器、计时器等只需要数字或少量符号的显示场景。所有字形共享相同的单元格大小。++### 编辑器工作流++1. 在 Content Browser 中右键 → **New → BitmapFont** 创建 `.bmfont` 文件+2. 在 Content Browser 中选中该字体文件,检查器显示字体编辑面板+3. 选择 **LabelAtlas** 类型+4. 在字形列表中将每个字符映射到图片文件(如 `0` → `zero.png`,`1` → `one.png`)+5. 点击 **Build Atlas** — 编辑器将所有字形图片打包为单张图集 PNG 并自动生成 `.fnt` 文件++生成的字体在运行时通过与标准 BMFont 相同的 `loadBitmapFont()` 路径加载。++### .bmfont 格式(LabelAtlas)++```json+{+ "version": "1.0",+ "type": "label-atlas",+ "glyphs": {+ "0": "digits/zero.png",+ "1": "digits/one.png",+ "2": "digits/two.png"+ },+ "generatedFnt": "my-digits.fnt"+}+```++| 字段 | 说明 |+|------|------|+| `type` | `"label-atlas"` — 告知编辑器使用 LabelAtlas 工作流 |+| `glyphs` | 字符 → 图片路径的映射 |+| `generatedFnt` | 自动生成的 `.fnt` 文件路径(由 Build Atlas 创建) |++<Aside type="note">+ 在运行时,LabelAtlas 字体与标准 BMFont 完全相同——编辑器只是帮你生成了 `.fnt` 和图集。无论字体以何种方式创建,`BitmapText` 组件的工作方式都一样。+</Aside>++## 加载位图字体++在启动系统中加载字体,然后将句柄赋给 `BitmapText` 组件:++```typescript+import { defineSystem, addStartupSystem, Res } from 'esengine';+import { Assets } from 'esengine';++addStartupSystem(defineSystem(+ [Res(Assets)],+ async (assets) => {+ const font = await assets.loadBitmapFont('assets/my-font.fnt');+ // font 是用于 BitmapText.font 的句柄+ }+));+```++### 字体资源 API++| 方法 | 返回值 | 说明 |+|------|--------|------|+| `loadBitmapFont(path)` | `Promise<number>` | 加载 `.fnt` 或 `.bmfont` 文件及其纹理,返回字体句柄 |+| `getFont(path)` | `number \| undefined` | 获取已缓存的字体句柄,未加载则返回 `undefined` |+| `releaseFont(path)` | `void` | 从内存中释放字体及其纹理 |++<Aside type="note">+ 当 BitmapText 实体在场景编辑器中引用了字体文件时,场景加载器会自动调用 `loadBitmapFont`。仅在运行时创建 BitmapText 实体时才需要手动调用。+</Aside>++## 运行时修改 BitmapText++使用 `Mut()` 查询 `BitmapText` 组件,在游戏运行时修改文本或样式:++```typescript+import { defineSystem, addSystem, Query, Mut } from 'esengine';+import { BitmapText } from 'esengine';++addSystem(defineSystem(+ [Query(Mut(BitmapText))],+ (query) => {+ for (const [entity, bitmapText] of query) {+ bitmapText.text = '你好!';+ bitmapText.fontSize = 2.0;+ bitmapText.color = { r: 1, g: 0.8, b: 0, a: 1 };+ }+ }+));+```++## 渲染顺序++BitmapText 遵循与 Sprite 相同的绘制排序规则:++1. **Z 坐标** (`transform.position.z`) — Z 值越小越先绘制(在后面)+2. **Layer** (`bitmapText.layer`) — layer 值越大越在上面++## 下一步++- [资源加载](/microes/zh/guides/assets/) — 加载位图字体和其他资源+- [UI 与文本](/microes/zh/guides/ui/) — Canvas 2D 文本和 UI 布局+- [渲染](/microes/zh/guides/rendering/) — 相机、变换和渲染顺序+- [组件](/microes/zh/core-concepts/components/) — 所有内置组件diff --git a/docs/astro/src/content/docs/zh/guides/rendering.mdx b/docs/astro/src/content/docs/zh/guides/rendering.mdxindex 7d1d5eeb2..6c6fbb158 100644--- a/docs/astro/src/content/docs/zh/guides/rendering.mdx+++ b/docs/astro/src/content/docs/zh/guides/rendering.mdx@@ -138,6 +138,7 @@ transform.scale = { x: -1, y: 1, z: 1 }; // 水平翻转- [Canvas 与分辨率](/microes/zh/guides/canvas/) — 屏幕适配与缩放模式- [精灵](/microes/zh/guides/sprite/) — 精灵渲染和动画- [Spine 动画](/microes/zh/guides/spine/) — 骨骼动画+- [位图文本](/microes/zh/guides/bitmap-text/) — GPU 渲染的位图字体文本- [自定义绘制](/microes/zh/guides/custom-draw/) — 即时模式绘图,用于调试可视化和动态图形- [后处理效果](/microes/zh/guides/post-processing/) — 全屏效果(模糊、暗角、灰度)- [几何体与网格](/microes/zh/guides/geometry/) — 自定义网格创建diff --git a/docs/astro/src/content/docs/zh/guides/spine.mdx b/docs/astro/src/content/docs/zh/guides/spine.mdxindex bf20feafb..9c091b0da 100644--- a/docs/astro/src/content/docs/zh/guides/spine.mdx+++ b/docs/astro/src/content/docs/zh/guides/spine.mdx@@ -8,7 +8,7 @@ import { Aside } from '@astrojs/starlight/components';`SpineAnimation` 组件播放 [Spine](http://esotericsoftware.com/) 骨骼动画。在场景编辑器中将它和 `LocalTransform` 一起添加到实体上。<Aside type="note">- 从 v0.3.0 起,Spine 使用独立的 WASM 模块(`spine38` / `spine41` / `spine42`),不再内置于引擎核心。在编辑器中通过 **Settings → Project → Spine Version** 选择版本(`3.8`、`4.1` 或 `4.2`),编辑器会自动加载对应的运行时,无需编写代码。+ 从 v0.3.0 起,Spine 使用独立的 WASM 模块(`spine38` / `spine41` / `spine42`),不再内置于引擎核心。在编辑器中通过 **Settings → Project → Spine Version** 选择版本(`3.8`、`4.1` 或 `4.2`),编辑器会自动加载对应的运行时,无需编写代码。新项目默认为 **None**(不加载 Spine 运行时),需要使用 Spine 时必须显式选择版本。</Aside>## 属性diff --git a/docs/astro/src/content/docs/zh/guides/sprite.mdx b/docs/astro/src/content/docs/zh/guides/sprite.mdxindex 5ca66e728..35594ad7d 100644--- a/docs/astro/src/content/docs/zh/guides/sprite.mdx+++ b/docs/astro/src/content/docs/zh/guides/sprite.mdx@@ -40,6 +40,33 @@ addSystem(defineSystem());```+## 加载纹理++`texture` 属性接受纹理句柄(number),而非文件路径。先用 `assets.loadTexture()` 加载图片,再将句柄赋值:++```typescript+import { defineSystem, addStartupSystem, Res, Query, Mut, Sprite } from 'esengine';+import { Assets } from 'esengine';+import { Player } from './components';++addStartupSystem(defineSystem(+ [Res(Assets), Query(Mut(Sprite), Player)],+ async (assets, query) => {+ const tex = await assets.loadTexture('assets/player.png');+ for (const [entity, sprite] of query) {+ sprite.texture = tex.handle;+ sprite.size = { x: tex.width, y: tex.height };+ }+ }+));+```++<Aside type="note">+ 在场景编辑器中为 Sprite 指定纹理时,场景加载器会自动调用 `loadTexture` 并设置句柄。仅在运行时赋值纹理时才需要上述代码。+</Aside>++完整纹理 API(`getTexture`、`releaseTexture`、九宫格元数据等)详见[资源加载](/microes/zh/guides/assets/)。+## 纯色矩形不设置纹理(默认值)时,精灵按 `color` 和 `size` 渲染为纯色矩形。diff --git a/docs/astro/src/content/docs/zh/guides/ui.mdx b/docs/astro/src/content/docs/zh/guides/ui.mdxindex ea8aac69b..ef38e73aa 100644--- a/docs/astro/src/content/docs/zh/guides/ui.mdx+++ b/docs/astro/src/content/docs/zh/guides/ui.mdx@@ -120,8 +120,56 @@ addSystem(defineSystem(在编辑器中:创建一个文本实体,添加 `Text`、`UIRect`、`Sprite`、`LocalTransform` 和 `ScoreDisplay` 标签。+## UIMask++`UIMask` 将子实体裁剪到父实体的 `UIRect` 边界内。任何超出矩形的子实体部分会被视觉裁切。++**设置:** 在父实体上添加 `UIMask`、`UIRect` 和 `LocalTransform`。所有子实体(及其后代)都会被裁剪到该矩形范围内。++<Aside type="note">+ `UIMaskPlugin` 由 `createWebApp()` 自动注册,无需手动设置。+</Aside>++### UIMask 属性++| 属性 | 类型 | 默认值 | 说明 |+|------|------|--------|------|+| `enabled` | boolean | `true` | 是否启用裁剪 |++### 嵌套遮罩++当子实体也拥有 `UIMask` 时,其裁剪矩形为自身 `UIRect` 与父级裁剪矩形的交集。这允许嵌套滚动区域或分层裁剪。++<Aside type="caution">+ `UIMask` 只裁剪**子实体** — 拥有 UIMask 的实体自身不会被裁剪。+</Aside>++### 示例:可滚动列表++创建遮罩容器,然后移动子实体来实现滚动:++```typescript+import { defineSystem, addSystem, Res, Input, Query, Mut, LocalTransform, Children } from 'esengine';+import { UIMask } from 'esengine';+import { ScrollList } from './components';++addSystem(defineSystem(+ [Res(Input), Query(Children, UIMask, ScrollList), Query(Mut(LocalTransform))],+ (input, maskQuery, childQuery) => {+ for (const [entity, children, mask, scroll] of maskQuery) {+ const scrollDelta = input.getScrollDelta();+ for (const child of children.entities) {+ const [, transform] = childQuery.get(child);+ transform.position.y += scrollDelta * 20;+ }+ }+ }+));+```+## 下一步- [组件](/microes/zh/core-concepts/components/) — 所有内置组件- [精灵](/microes/zh/guides/sprite/) — 精灵渲染详解+- [位图文本](/microes/zh/guides/bitmap-text/) — GPU 渲染的位图字体文本- [资源加载](/microes/zh/guides/assets/) — 加载纹理和其他资源