Skip to content

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.

docs: add UI, asset loading, and materials guides (EN + ZH)

esenginedc99e1f0bf9c
diff --git a/docs/astro/astro.config.mjs b/docs/astro/astro.config.mjs
index 035b71831..b2b86604d 100644
--- a/docs/astro/astro.config.mjs
+++ b/docs/astro/astro.config.mjs
@@ -14,7 +14,7 @@ export default defineConfig({
integrations: [
starlight({
title: 'ESEngine',
- description: 'A lightweight C++17 game engine for WebAssembly and WeChat MiniGames',
+ description: 'A lightweight 2D game engine for web and WeChat MiniGames',
logo: {
light: './src/assets/logo-light.svg',
dark: './src/assets/logo-dark.svg',
@@ -29,35 +29,49 @@ export default defineConfig({
customCss: [
'./src/styles/custom.css',
],
+ defaultLocale: 'root',
+ locales: {
+ root: { label: 'English', lang: 'en' },
+ zh: { label: '简体中文', lang: 'zh-CN' },
+ },
sidebar: [
{
label: 'Getting Started',
+ translations: { 'zh-CN': '快速上手' },
items: [
- { label: 'Introduction', slug: 'getting-started/introduction' },
- { label: 'Installation', slug: 'getting-started/installation' },
- { label: 'Quick Start', slug: 'getting-started/quick-start' },
+ { label: 'Introduction', translations: { 'zh-CN': '简介' }, slug: 'getting-started/introduction' },
+ { label: 'Installation', translations: { 'zh-CN': '安装' }, slug: 'getting-started/installation' },
+ { label: 'Quick Start', translations: { 'zh-CN': '快速开始' }, slug: 'getting-started/quick-start' },
],
},
{
- label: 'Guides',
+ label: 'Core Concepts',
+ translations: { 'zh-CN': '核心概念' },
items: [
- { label: 'Project Structure', slug: 'guides/project-structure' },
- { label: 'ECS Architecture', slug: 'guides/ecs' },
- { label: 'Rendering', slug: 'guides/rendering' },
- { label: 'Input Handling', slug: 'guides/input' },
+ { label: 'ECS Architecture', translations: { 'zh-CN': 'ECS 架构' }, slug: 'core-concepts/ecs' },
+ { label: 'Components', translations: { 'zh-CN': '组件' }, slug: 'core-concepts/components' },
+ { label: 'Systems', translations: { 'zh-CN': '系统' }, slug: 'core-concepts/systems' },
+ { label: 'Queries', translations: { 'zh-CN': '查询' }, slug: 'core-concepts/queries' },
+ { label: 'Resources', translations: { 'zh-CN': '资源' }, slug: 'core-concepts/resources' },
],
},
{
- label: 'Platforms',
- items: [
- { label: 'Web (Emscripten)', slug: 'platforms/web' },
- { label: 'WeChat MiniGame', slug: 'platforms/wechat' },
- ],
- },
- {
- label: 'API Reference',
+ label: 'Guides',
+ translations: { 'zh-CN': '指南' },
items: [
- { label: 'Overview', slug: 'api/overview' },
+ {
+ label: 'Rendering',
+ translations: { 'zh-CN': '渲染' },
+ items: [
+ { label: 'Overview', translations: { 'zh-CN': '概览' }, slug: 'guides/rendering' },
+ { label: 'Sprite', translations: { 'zh-CN': '精灵' }, slug: 'guides/sprite' },
+ { label: 'Spine Animation', translations: { 'zh-CN': 'Spine 动画' }, slug: 'guides/spine' },
+ ],
+ },
+ { label: 'Input Handling', translations: { 'zh-CN': '输入处理' }, slug: 'guides/input' },
+ { label: 'UI & Text', translations: { 'zh-CN': 'UI 与文本' }, slug: 'guides/ui' },
+ { label: 'Asset Loading', translations: { 'zh-CN': '资源加载' }, slug: 'guides/assets' },
+ { label: 'Materials & Shaders', translations: { 'zh-CN': '材质与着色器' }, slug: 'guides/materials' },
],
},
],
diff --git a/docs/astro/src/content/docs/api/overview.mdx b/docs/astro/src/content/docs/api/overview.mdx
deleted file mode 100644
index 1dbba6e9d..000000000
--- a/docs/astro/src/content/docs/api/overview.mdx
+++ /dev/null
@@ -1,186 +0,0 @@
----
-title: API Overview
-description: ESEngine API reference documentation
----
-
-import { Card, CardGrid } from '@astrojs/starlight/components';
-
-The ESEngine API is organized into several modules. This page provides an overview; detailed documentation is available in the Doxygen-generated reference.
-
-## API Modules
-
-<CardGrid>
- <Card title="Core" icon="setting">
- Application lifecycle, logging, and fundamental types.
-
- - `Application` - Base class for games
- - `ApplicationConfig` - Startup configuration
- - `ES_LOG_*` - Logging macros
- </Card>
-
- <Card title="ECS" icon="puzzle">
- Entity-Component-System for game objects.
-
- - `Registry` - Entity/component container
- - `Entity` - Unique identifier type
- - `View` - Query iterator
- </Card>
-
- <Card title="Renderer" icon="laptop">
- WebGL-based graphics.
-
- - `Renderer` - Drawing API
- - `Texture` - Image loading
- - `Shader` - Custom shaders
- </Card>
-
- <Card title="Platform" icon="rocket">
- OS and browser abstraction.
-
- - `Platform` - Window/context
- - `Input` - Keyboard/mouse/touch
- </Card>
-</CardGrid>
-
-## Key Classes
-
-### Application
-
-The main entry point for games. Inherit and override lifecycle methods.
-
-```cpp
-class Application {
-public:
- Application(const ApplicationConfig& config = {});
- void run();
- void quit();
-
-protected:
- virtual void onInit();
- virtual void onUpdate(f32 deltaTime);
- virtual void onRender();
- virtual void onShutdown();
-
- virtual void onTouch(TouchType type, const TouchPoint& point);
- virtual void onKey(KeyCode key, bool pressed);
- virtual void onResize(u32 width, u32 height);
-
- Platform& getPlatform();
- ecs::Registry& getRegistry();
-};
-```
-
-### Registry
-
-Central ECS container for entities and components.
-
-```cpp
-class Registry {
-public:
- // Entity management
- Entity create();
- void destroy(Entity entity);
- bool valid(Entity entity) const;
-
- // Component management
- template<typename T, typename... Args>
- T& emplace(Entity entity, Args&&... args);
-
- template<typename T>
- T& get(Entity entity);
-
- template<typename T>
- bool has(Entity entity) const;
-
- // Queries
- template<typename... Components>
- View<Components...> view();
-};
-```
-
-### View
-
-Iterator for querying entities with specific components.
-
-```cpp
-template<typename... Components>
-class View {
-public:
- // Range-based for loop
- iterator begin();
- iterator end();
-
- // Structured bindings iteration
- auto each();
-
- // Direct component access
- template<typename T>
- T& get(Entity entity);
-};
-```
-
-## Type Aliases
-
-ESEngine uses consistent type aliases throughout the codebase:
-
-```cpp
-namespace esengine {
- using u8 = uint8_t;
- using u16 = uint16_t;
- using u32 = uint32_t;
- using u64 = uint64_t;
-
- using i8 = int8_t;
- using i16 = int16_t;
- using i32 = int32_t;
- using i64 = int64_t;
-
- using f32 = float;
- using f64 = double;
-
- using usize = size_t;
-
- template<typename T>
- using Unique = std::unique_ptr<T>;
-
- template<typename T>
- using Shared = std::shared_ptr<T>;
-}
-```
-
-## Logging Macros
-
-```cpp
-ES_LOG_TRACE("Detailed debug info: {}", value);
-ES_LOG_DEBUG("Debug message");
-ES_LOG_INFO("General information");
-ES_LOG_WARN("Warning message");
-ES_LOG_ERROR("Error occurred: {}", errorMsg);
-```
-
-## Assertions
-
-```cpp
-ES_ASSERT(condition, "Message if condition is false");
-ES_VERIFY(ptr != nullptr, "Pointer must not be null");
-```
-
-## Doxygen Reference
-
-For complete API documentation with all parameters, return types, and examples, see the Doxygen-generated reference.
-
-<a href="/microes/api/html/index.html" target="_blank" class="sl-flex" style="display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.75rem 1.5rem; background: var(--sl-color-accent); color: white; border-radius: 0.5rem; text-decoration: none; font-weight: 500; margin: 1rem 0;">
- Open API Documentation →
-</a>
-
-:::note[Development Mode]
-If the link above shows 404 in development, open the Doxygen docs directly:
-`F:\esengine\docs\api\html\index.html`
-:::
-
-The Doxygen documentation includes:
-- All public classes and functions
-- Parameter descriptions
-- Code examples
-- Inheritance diagrams
-- Source code references
diff --git a/docs/astro/src/content/docs/core-concepts/components.mdx b/docs/astro/src/content/docs/core-concepts/components.mdx
new file mode 100644
index 000000000..ab46f548b
--- /dev/null
+++ b/docs/astro/src/content/docs/core-concepts/components.mdx
@@ -0,0 +1,189 @@
+---
+title: Components
+description: Builtin and custom components in ESEngine
+---
+
+import { Aside } from '@astrojs/starlight/components';
+
+Components are data attached to entities. In ESEngine, you **define** components in code and **attach** them to entities in the scene editor.
+
+## Builtin Components
+
+Builtin components are always available in the editor. They are backed by the C++ backend.
+
+### LocalTransform
+
+Position, rotation, and scale of an entity.
+
+| Property | Type | Description |
+|----------|------|-------------|
+| `position` | Vec3 | World position `{ x, y, z }` |
+| `rotation` | Quat | Quaternion `{ w, x, y, z }` |
+| `scale` | Vec3 | Scale factor `{ x, y, z }` |
+
+### Sprite
+
+2D sprite rendering. Requires `LocalTransform` to be visible. See [Sprite guide](/microes/guides/sprite/) for full details.
+
+### Camera
+
+View settings. At least one active camera is required to see anything. The editor's default scene includes one.
+
+| Property | Type | Description |
+|----------|------|-------------|
+| `projectionType` | number | 0 = Perspective, 1 = Orthographic |
+| `fov` | number | Field of view in degrees (perspective only) |
+| `orthoSize` | number | Half-height in world units (orthographic only) |
+| `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 |
+
+### Canvas
+
+Display settings for the rendering surface.
+
+| Property | Type | Description |
+|----------|------|-------------|
+| `designResolution` | Vec2 | Design resolution `{ x, y }` |
+| `pixelsPerUnit` | number | Pixels per world unit |
+| `scaleMode` | number | How the canvas scales |
+| `matchWidthOrHeight` | number | Balance between width/height matching |
+| `backgroundColor` | Vec4 | Clear color RGBA |
+
+### Velocity
+
+Movement velocity.
+
+| Property | Type | Description |
+|----------|------|-------------|
+| `linear` | Vec3 | Linear velocity |
+| `angular` | Vec3 | Angular velocity |
+
+### Parent / Children
+
+Entity hierarchy for scene graphs.
+
+| Component | Property | Type | Description |
+|-----------|----------|------|-------------|
+| `Parent` | `entity` | Entity | Parent entity ID |
+| `Children` | `entities` | Entity[] | List of child entity IDs |
+
+### SpineAnimation
+
+Spine skeletal animation playback. Requires `LocalTransform`. See [Spine Animation guide](/microes/guides/spine/) for full details.
+
+### Text
+
+UI text rendering. Works with `UIRect` and `Sprite` to display text. See [UI & Text guide](/microes/guides/ui/) for full details.
+
+| Property | Type | Description |
+|----------|------|-------------|
+| `content` | string | Text content |
+| `fontFamily` | string | Font family |
+| `fontSize` | number | Font size in pixels |
+| `color` | Vec4 | Text color RGBA |
+| `align` | TextAlign | Horizontal alignment |
+| `verticalAlign` | TextVerticalAlign | Vertical alignment |
+
+### UIRect
+
+UI layout rectangle. Defines size, anchor, and pivot for UI elements.
+
+| Property | Type | Description |
+|----------|------|-------------|
+| `size` | Vec2 | Width and height |
+| `anchor` | Vec2 | Anchor point (0–1) |
+| `pivot` | Vec2 | Pivot point for rotation |
+
+## Custom Components
+
+### defineComponent
+
+Define a data component in code. After saving, it appears in the editor's "Add Component" menu.
+
+```typescript
+import { defineComponent } from 'esengine';
+
+export const Health = defineComponent('Health', {
+ current: 100,
+ max: 100
+});
+```
+
+Then in the editor: select an entity → Add Component → Health → set values in the inspector.
+
+Systems query entities with this component:
+
+```typescript
+import { defineSystem, addSystem, Query } from 'esengine';
+import { Health } from './components/Health';
+
+addSystem(defineSystem(
+ [Query(Health)],
+ (query) => {
+ for (const [entity, health] of query) {
+ if (health.current <= 0) {
+ // handle death
+ }
+ }
+ }
+));
+```
+
+### defineTag
+
+A tag component has no data — it's used purely for filtering entities.
+
+```typescript
+import { defineTag } from 'esengine';
+
+export const Player = defineTag('Player');
+export const Enemy = defineTag('Enemy');
+```
+
+Attach `Player` to an entity in the editor, then query it:
+
+```typescript
+addSystem(defineSystem(
+ [Query(LocalTransform, Player)],
+ (query) => {
+ for (const [entity, transform] of query) {
+ // only processes entities with the Player tag
+ }
+ }
+));
+```
+
+<Aside type="caution">
+ Custom components are stored in TypeScript only. Builtin components are synced with the C++ backend for rendering.
+</Aside>
+
+## Runtime Entity Spawning
+
+For entities created at runtime (bullets, particles, effects), use `Commands`:
+
+```typescript
+import { addStartupSystem, defineSystem, Commands, Sprite, LocalTransform } from 'esengine';
+
+addStartupSystem(defineSystem(
+ [Commands()],
+ (cmds) => {
+ const entity = cmds.spawn()
+ .insert(Sprite, { size: { x: 10, y: 10 } })
+ .insert(LocalTransform, { position: { x: 0, y: 0, z: 0 } })
+ .id();
+ }
+));
+```
+
+### Removing Components at Runtime
+
+```typescript
+cmds.entity(entity).remove(Velocity);
+```
+
+## Next Steps
+
+- [Systems](/microes/core-concepts/systems/) — logic that operates on components
+- [Queries](/microes/core-concepts/queries/) — finding entities by component
diff --git a/docs/astro/src/content/docs/core-concepts/ecs.mdx b/docs/astro/src/content/docs/core-concepts/ecs.mdx
new file mode 100644
index 000000000..6af994c93
--- /dev/null
+++ b/docs/astro/src/content/docs/core-concepts/ecs.mdx
@@ -0,0 +1,141 @@
+---
+title: ECS Architecture
+description: Understanding the Entity-Component-System pattern in ESEngine
+---
+
+import { Aside } from '@astrojs/starlight/components';
+
+ESEngine uses an Entity-Component-System (ECS) architecture for game object management. ECS separates **identity** (Entity), **data** (Component), and **behavior** (System).
+
+## What is ECS?
+
+| Concept | Role | Example |
+|---------|------|---------|
+| **Entity** | A unique identifier (just a number) | Player, Enemy, Bullet |
+| **Component** | Data attached to an entity | LocalTransform, Sprite, Health |
+| **System** | Logic that operates on entities with specific components | MovementSystem, RenderSystem |
+
+<Aside type="tip">
+ ECS favors **composition over inheritance**. Instead of a deep class hierarchy, you build game objects by combining small, reusable components.
+</Aside>
+
+## Why ECS?
+
+Traditional OOP approach:
+
+```
+GameObject
+├── Player extends GameObject
+│ ├── FlyingPlayer extends Player
+│ └── SwimmingPlayer extends Player
+└── Enemy extends GameObject
+ └── FlyingEnemy extends Enemy
+```
+
+ECS approach — compose behaviors freely:
+
+```
+Player = Entity + LocalTransform + Sprite + Health + PlayerInput
+Enemy = Entity + LocalTransform + Sprite + Health + AI
+Bullet = Entity + LocalTransform + Sprite + Velocity + Damage
+```
+
+Benefits:
+
+- **Composition** — mix and match components without rigid hierarchies
+- **Data locality** — components of the same type are stored contiguously, improving cache performance
+- **Separation of concerns** — systems contain logic, components hold data
+- **Flexibility** — add or remove components at runtime to change behavior
+
+## Entities
+
+An entity is just a number (ID). In ESEngine, entities are typically created in the **scene editor** — you place them visually, add components, and configure their properties.
+
+Entities can also be spawned at runtime with `Commands` (e.g. bullets, particles):
+
+```typescript
+import { defineSystem, addStartupSystem, Commands, type Entity } from 'esengine';
+
+addStartupSystem(defineSystem([Commands()], (cmds) => {
+ const bullet: Entity = cmds.spawn().id();
+ cmds.despawn(bullet);
+}));
+```
+
+## Components
+
+Components are data attached to entities. You **define** components in code, then **attach** them to entities in the scene editor.
+
+- **Builtin components** — LocalTransform, Sprite, Camera, etc. (always available in the editor)
+- **Custom components** — defined with `defineComponent` / `defineTag` (appear in the editor after saving)
+
+```typescript
+import { defineComponent, defineTag } from 'esengine';
+
+const Health = defineComponent('Health', { current: 100, max: 100 });
+const Player = defineTag('Player');
+```
+
+After defining these, open the editor, select an entity, and add `Health` or `Player` from the "Add Component" menu.
+
+See [Components](/microes/core-concepts/components/) for the full API.
+
+## Systems
+
+Systems are functions that query entities with specific components and operate on them. They run automatically on all matching entities in the scene.
+
+```typescript
+import { defineSystem, addSystem, Res, Time, Query, Mut, LocalTransform } from 'esengine';
+import { Health } from './components';
+
+addSystem(defineSystem(
+ [Res(Time), Query(Mut(LocalTransform), Health)],
+ (time, query) => {
+ for (const [entity, transform, health] of query) {
+ if (health.current <= 0) {
+ transform.position.y -= 100 * time.delta;
+ }
+ }
+ }
+));
+```
+
+See [Systems](/microes/core-concepts/systems/) for the full API.
+
+## ECS Flow
+
+```
+ ┌──────────────────────┐
+ │ Editor: Scene Setup │ Place entities, attach components
+ └──────────┬───────────┘
+ ▼
+ ┌──────────────────────┐
+ │ Scripts: Define │ defineComponent + defineSystem + addSystem
+ └──────────┬───────────┘
+ ▼
+ ┌──────────┐
+ │ Startup │ Startup systems run once
+ └────┬─────┘
+ ▼
+ ┌──────────┐
+ │ Update │◄─┐ Systems query scene entities every frame
+ └────┬─────┘ │
+ ▼ │
+ ┌──────────┐ │
+ │ Render │ │ C++ backend draws all Sprites/Cameras
+ └────┬─────┘ │
+ └────────┘
+```
+
+1. **Scene setup** — place entities and attach components in the editor
+2. **Scripts** — define custom components and register systems
+3. **Startup** — startup systems run once
+4. **Update loop** — systems query and process scene entities every frame
+5. **Render** — the C++ backend automatically renders all entities with `Sprite` and `Camera` components
+
+## Next Steps
+
+- [Components](/microes/core-concepts/components/) — builtin and custom components
+- [Systems](/microes/core-concepts/systems/) — defining and scheduling systems
+- [Queries](/microes/core-concepts/queries/) — querying entities
+- [Resources](/microes/core-concepts/resources/) — global singleton data
diff --git a/docs/astro/src/content/docs/core-concepts/queries.mdx b/docs/astro/src/content/docs/core-concepts/queries.mdx
new file mode 100644
index 000000000..a60d9d9c6
--- /dev/null
+++ b/docs/astro/src/content/docs/core-concepts/queries.mdx
@@ -0,0 +1,153 @@
+---
+title: Queries
+description: Querying entities by component in ESEngine
+---
+
+Queries let you iterate over entities that have specific components. They are the primary way systems access entity data from the scene.
+
+## Basic Query
+
+A query matches all entities in the scene that have **all** the listed components:
+
+```typescript
+import { defineSystem, addSystem, Query, Mut, LocalTransform, Sprite } from 'esengine';
+
+addSystem(defineSystem([Query(Mut(LocalTransform), Sprite)], (query) => {
+ for (const [entity, transform, sprite] of query) {
+ transform.position.x += 1;
+ }
+}));
+```
+
+The `for...of` loop yields tuples of `[entity, ...components]` in the same order as the query parameters.
+
+## Mutable Queries
+
+By default, query results are read-only. Use `Mut()` to get mutable access to specific components:
+
+```typescript
+import { Query, Mut, LocalTransform, Sprite } from 'esengine';
+
+defineSystem(
+ [Query(Mut(LocalTransform), Sprite)],
+ (query) => {
+ for (const [entity, transform, sprite] of query) {
+ transform.position.x += 1; // writable
+ // sprite is read-only
+ }
+ }
+);
+```
+
+## Iteration Methods
+
+### for...of
+
+```typescript
+for (const [entity, transform, sprite] of query) {
+ transform.position.x += 1;
+}
+```
+
+### forEach
+
+```typescript
+query.forEach((entity, transform, sprite) => {
+ transform.position.x += 1;
+});
+```
+
+### single
+
+Get the one and only matching entity. Returns `null` if there are zero or more than one matches.
+
+```typescript
+const result = query.single();
+if (result) {
+ const [entity, transform, sprite] = result;
+ // ...
+}
+```
+
+### Utility Methods
+
+```typescript
+query.isEmpty(); // true if no entities match
+query.count(); // number of matching entities
+query.toArray(); // collect all results into an array
+```
+
+## Multiple Queries
+
+A system can have multiple queries to cross-reference different entity types:
+
+```typescript
+import { defineTag } from 'esengine';
+
+const Player = defineTag('Player');
+const Enemy = defineTag('Enemy');
+
+defineSystem(
+ [Query(LocalTransform, Player), Query(LocalTransform, Enemy)],
+ (players, enemies) => {
+ for (const [_, playerTransform] of players) {
+ for (const [_, enemyTransform] of enemies) {
+ // Check distance between player and each enemy
+ }
+ }
+ }
+);
+```
+
+## Combining with Resources
+
+Queries are often used together with resources:
+
+```typescript
+import { Res, Time, Input, Query, Mut, LocalTransform } from 'esengine';
+
+defineSystem(
+ [Res(Time), Res(Input), Query(Mut(LocalTransform), Player)],
+ (time, input, query) => {
+ for (const [entity, transform] of query) {
+ if (input.isKeyDown('KeyD')) {
+ transform.position.x += 200 * time.delta;
+ }
+ }
+ }
+);
+```
+
+## Example: Collision Detection
+
+Define `Hitbox`, `Player`, and `Enemy` components, attach them to entities in the scene editor, then query:
+
+```typescript
+import { defineSystem, defineComponent, defineTag, addSystem, Query, LocalTransform } from 'esengine';
+
+const Hitbox = defineComponent('Hitbox', { width: 50, height: 50 });
+const Player = defineTag('Player');
+const Enemy = defineTag('Enemy');
+
+addSystem(defineSystem(
+ [Query(LocalTransform, Hitbox, Player), Query(LocalTransform, Hitbox, Enemy)],
+ (players, enemies) => {
+ for (const [_, pPos, pBox] of players) {
+ for (const [_, ePos, eBox] of enemies) {
+ const dx = Math.abs(pPos.position.x - ePos.position.x);
+ const dy = Math.abs(pPos.position.y - ePos.position.y);
+
+ if (dx < (pBox.width + eBox.width) / 2 &&
+ dy < (pBox.height + eBox.height) / 2) {
+ // Collision!
+ }
+ }
+ }
+ }
+));
+```
+
+## Next Steps
+
+- [Resources](/microes/core-concepts/resources/) — global singleton data like Time and Input
+- [Components](/microes/core-concepts/components/) — all builtin and custom component types
diff --git a/docs/astro/src/content/docs/core-concepts/resources.mdx b/docs/astro/src/content/docs/core-concepts/resources.mdx
new file mode 100644
index 000000000..231037c08
--- /dev/null
+++ b/docs/astro/src/content/docs/core-concepts/resources.mdx
@@ -0,0 +1,167 @@
+---
+title: Resources
+description: Global singleton data in ESEngine
+---
+
+Resources are global singletons — they exist once in the entire app, not attached to any entity. Use them for shared state like time, input, and game configuration.
+
+## Accessing Resources
+
+### Res (read-only)
+
+```typescript
+import { defineSystem, Res, Time } from 'esengine';
+
+defineSystem([Res(Time)], (time) => {
+ console.log(`Delta: ${time.delta}s, Elapsed: ${time.elapsed}s`);
+});
+```
+
+### ResMut (mutable)
+
+```typescript
+import { defineSystem, ResMut } from 'esengine';
+
+defineSystem([ResMut(GameState)], (state) => {
+ state.value.score += 10;
+});
+```
+
+`ResMut` wraps the resource value. Access the data with `.value`, or use `.modify()`:
+
+```typescript
+defineSystem([ResMut(GameState)], (state) => {
+ state.modify((s) => {
+ s.score += 10;
+ s.level = Math.floor(s.score / 100) + 1;
+ });
+});
+```
+
+## Builtin Resources
+
+### Time
+
+Frame timing information. Available automatically.
+
+```typescript
+import { Res, Time } from 'esengine';
+
+defineSystem([Res(Time)], (time) => {
+ time.delta; // Seconds since last frame
+ time.elapsed; // Total elapsed seconds
+ time.frameCount; // Total frames rendered
+});
+```
+
+| Property | Type | Description |
+|----------|------|-------------|
+| `delta` | number | Seconds since last frame |
+| `elapsed` | number | Total elapsed seconds |
+| `frameCount` | number | Total frames rendered |
+
+### Input
+
+Keyboard and mouse state. Available automatically.
+
+```typescript
+import { Res, Input } from 'esengine';
+
+defineSystem([Res(Input)], (input) => {
+ if (input.isKeyDown('Space')) {
+ // Space is held
+ }
+ if (input.isKeyPressed('KeyE')) {
+ // E was just pressed this frame
+ }
+});
+```
+
+| Method | Description |
+|--------|-------------|
+| `isKeyDown(code)` | Key is currently held |
+| `isKeyPressed(code)` | Key was pressed this frame |
+| `isKeyReleased(code)` | Key was released this frame |
+| `getMousePosition()` | Returns `{ x, y }` |
+| `isMouseButtonDown(button)` | Mouse button held (0=left, 2=right) |
+
+## Custom Resources
+
+### defineResource
+
+```typescript
+import { defineResource } from 'esengine';
+
+const GameState = defineResource({
+ score: 0,
+ level: 1,
+ paused: false
+});
+```
+
+### Inserting Resources
+
+Insert a resource via `Commands` in a startup system:
+
+```typescript
+import { addStartupSystem, defineSystem, Commands } from 'esengine';
+
+addStartupSystem(defineSystem([Commands()], (cmds) => {
+ cmds.insertResource(GameState, { score: 0, level: 1, paused: false });
+}));
+```
+
+### Reading and Writing
+
+```typescript
+// Read-only
+defineSystem([Res(GameState)], (state) => {
+ console.log(`Score: ${state.score}`);
+});
+
+// Mutable
+defineSystem([ResMut(GameState)], (state) => {
+ state.value.score += 10;
+});
+```
+
+## Example: Score Tracking
+
+Define a `Coin` tag, attach it to coin entities in the scene, and track score with a resource:
+
+```typescript
+import {
+ defineSystem, defineResource, defineTag,
+ addStartupSystem, addSystem, Commands, Query, ResMut,
+ LocalTransform
+} from 'esengine';
+
+const Score = defineResource({ value: 0 });
+const Coin = defineTag('Coin');
+const Player = defineTag('Player');
+
+addStartupSystem(defineSystem([Commands()], (cmds) => {
+ cmds.insertResource(Score, { value: 0 });
+}));
+
+addSystem(defineSystem(
+ [Commands(), ResMut(Score), Query(LocalTransform, Player), Query(LocalTransform, Coin)],
+ (cmds, score, players, coins) => {
+ for (const [_, pPos] of players) {
+ for (const [coinEntity, cPos] of coins) {
+ const dx = pPos.position.x - cPos.position.x;
+ const dy = pPos.position.y - cPos.position.y;
+ if (Math.sqrt(dx * dx + dy * dy) < 30) {
+ cmds.despawn(coinEntity);
+ score.value.value += 1;
+ }
+ }
+ }
+ }
+));
+```
+
+## Next Steps
+
+- [Systems](/microes/core-concepts/systems/) — how systems use resources and queries
+- [Components](/microes/core-concepts/components/) — data attached to entities
diff --git a/docs/astro/src/content/docs/core-concepts/systems.mdx b/docs/astro/src/content/docs/core-concepts/systems.mdx
new file mode 100644
index 000000000..d2f7ca98f
--- /dev/null
+++ b/docs/astro/src/content/docs/core-concepts/systems.mdx
@@ -0,0 +1,157 @@
+---
+title: Systems
+description: Defining systems and scheduling them in ESEngine
+---
+
+Systems contain game logic. They declare what data they need via parameters, and ESEngine injects the data automatically. Systems operate on **all entities in the scene** that match the query.
+
+## Defining Systems
+
+```typescript
+import { defineSystem, Res, Time, Query, Mut, LocalTransform, Velocity } from 'esengine';
+
+const movementSystem = defineSystem(
+ [Res(Time), Query(Mut(LocalTransform), Velocity)],
+ (time, query) => {
+ for (const [entity, transform, velocity] of query) {
+ transform.position.x += velocity.linear.x * time.delta;
+ transform.position.y += velocity.linear.y * time.delta;
+ }
+ }
+);
+```
+
+This system automatically processes every entity in the scene that has both `LocalTransform` and `Velocity` components.
+
+`defineSystem` takes two arguments:
+
+1. **Parameters** — an array of `Query`, `Res`, `ResMut`, or `Commands` descriptors
+2. **Function** — receives the resolved parameters in the same order
+
+## Registering Systems
+
+Register systems with top-level functions:
+
+```typescript
+import { addSystem, addStartupSystem, addSystemToSchedule, Schedule } from 'esengine';
+
+addStartupSystem(setupSystem); // Schedule.Startup
+addSystem(movementSystem); // Schedule.Update
+addSystemToSchedule(Schedule.FixedUpdate, physicsSystem);
+```
+
+### Schedule Types
+
+| Schedule | When it runs |
+|----------|--------------|
+| `Startup` | Once at the beginning |
+| `First` | Every frame, before PreUpdate |
+| `PreUpdate` | Every frame, before Update |
+| `Update` | Every frame (main game logic) |
+| `PostUpdate` | Every frame, after Update |
+| `Last` | Every frame, after PostUpdate |
+| `FixedPreUpdate` | At fixed intervals, before FixedUpdate |
+| `FixedUpdate` | At fixed intervals (physics) |
+| `FixedPostUpdate` | At fixed intervals, after FixedUpdate |
+
+## System Parameters
+
+### Commands
+
+Spawn and despawn entities at runtime:
+
+```typescript
+import { Commands } from 'esengine';
+
+defineSystem([Commands()], (cmds) => {
+ cmds.spawn()
+ .insert(Sprite, { size: { x: 50, y: 50 } })
+ .insert(LocalTransform, { position: { x: 0, y: 0, z: 0 } });
+
+ cmds.despawn(entity);
+});
+```
+
+### Query
+
+Iterate entities with specific components:
+
+```typescript
+import { Query, Mut, LocalTransform, Sprite } from 'esengine';
+
+defineSystem([Query(Mut(LocalTransform), Sprite)], (query) => {
+ for (const [entity, transform, sprite] of query) {
+ transform.position.x += 1;
+ }
+});
+```
+
+See [Queries](/microes/core-concepts/queries/) for the full API.
+
+### Res (read-only resource)
+
+```typescript
+import { Res, Time } from 'esengine';
+
+defineSystem([Res(Time)], (time) => {
+ console.log(`Delta: ${time.delta}s`);
+});
+```
+
+### ResMut (mutable resource)
+
+```typescript
+import { ResMut } from 'esengine';
+
+defineSystem([ResMut(GameState)], (state) => {
+ state.value.score += 10;
+});
+```
+
+See [Resources](/microes/core-concepts/resources/) for the full API.
+
+### Combining Parameters
+
+```typescript
+defineSystem(
+ [Commands(), Res(Time), Res(Input), Query(Mut(LocalTransform), Velocity)],
+ (cmds, time, input, query) => {
+ // All parameters available
+ }
+);
+```
+
+## Example: Player Movement
+
+Define a `Speed` component and attach it to the player entity in the editor. Then write a system:
+
+```typescript
+// src/components/Speed.ts
+import { defineComponent } from 'esengine';
+export const Speed = defineComponent('Speed', { value: 200 });
+```
+
+```typescript
+// src/systems/movement.ts
+import { defineSystem, addSystem, Res, Time, Input, Query, Mut, LocalTransform } from 'esengine';
+import { Speed } from '../components/Speed';
+
+addSystem(defineSystem(
+ [Res(Time), Res(Input), Query(Mut(LocalTransform), Speed)],
+ (time, input, query) => {
+ for (const [entity, transform, speed] of query) {
+ if (input.isKeyDown('KeyD')) {
+ transform.position.x += speed.value * time.delta;
+ }
+ if (input.isKeyDown('KeyA')) {
+ transform.position.x -= speed.value * time.delta;
+ }
+ }
+ }
+));
+```
+
+## Next Steps
+
+- [Queries](/microes/core-concepts/queries/) — query filters and iteration methods
+- [Resources](/microes/core-concepts/resources/) — global singleton data
diff --git a/docs/astro/src/content/docs/getting-started/installation.mdx b/docs/astro/src/content/docs/getting-started/installation.mdx
index 72ab2b0ab..c1f9b2c1d 100644
--- a/docs/astro/src/content/docs/getting-started/installation.mdx
+++ b/docs/astro/src/content/docs/getting-started/installation.mdx
@@ -1,180 +1,62 @@
---
title: Installation
-description: Set up your development environment for ESEngine
+description: Install the ESEngine editor and create your first project
---
-import { Tabs, TabItem, Steps, Aside } from '@astrojs/starlight/components';
+import { Steps, Aside } from '@astrojs/starlight/components';
-This guide will help you set up your development environment for building games with ESEngine.
+## Install the Editor
-## Quick Start (SDK Only)
+Download the ESEngine editor from the [releases page](https://github.com/esengine/microes/releases) and install it.
-For most users, just install the TypeScript SDK:
-
-```bash
-npm install esengine
-```
-
-You'll also need the WASM files. Download them from the [releases page](https://github.com/esengine/microes/releases) or build them yourself (see below).
-
-<Aside type="tip">
- If you're just getting started, skip to [Quick Start](/microes/getting-started/quick-start/) after installing the SDK.
-</Aside>
-
-## Project Setup
+## Create a Project
<Steps>
-1. **Create your project**
-
- ```bash
- mkdir my-game
- cd my-game
- npm init -y
- ```
-
-2. **Install dependencies**
-
- ```bash
- npm install esengine
- npm install -D esbuild typescript
- ```
-
-3. **Create tsconfig.json**
-
- ```json
- {
- "compilerOptions": {
- "target": "ES2020",
- "module": "ESNext",
- "moduleResolution": "bundler",
- "strict": true,
- "esModuleInterop": true
- },
- "include": ["src"]
- }
- ```
-
-4. **Add build scripts to package.json**
-
- ```json
- {
- "type": "module",
- "scripts": {
- "build": "esbuild src/main.ts --bundle --format=esm --outfile=build/main.js",
- "dev": "esbuild src/main.ts --bundle --format=esm --outfile=build/main.js --watch"
- }
- }
- ```
+1. **Open the editor** and click **New Project**
-</Steps>
+2. **Enter project name** and select a location on disk
-## Building WASM (Advanced)
-
-If you need to build the C++ WASM backend yourself:
-
-### Prerequisites
-
-| Tool | Version | Purpose |
-|------|---------|---------|
-| CMake | 3.16+ | Build system |
-| C++ Compiler | C++17 support | GCC 8+, Clang 7+, MSVC 2019+ |
-| Emscripten | 3.1+ | WebAssembly compilation |
-| Node.js | 18+ | SDK build |
-
-### Installing Emscripten
-
-<Tabs>
- <TabItem label="Linux/macOS">
- ```bash
- # Clone emsdk
- git clone https://github.com/emscripten-core/emsdk.git
- cd emsdk
-
- # Install and activate latest version
- ./emsdk install latest
- ./emsdk activate latest
-
- # Add to your shell profile
- echo 'source "/path/to/emsdk/emsdk_env.sh"' >> ~/.bashrc
- ```
- </TabItem>
- <TabItem label="Windows">
- ```powershell
- # Clone emsdk
- git clone https://github.com/emscripten-core/emsdk.git
- cd emsdk
-
- # Install and activate latest version
- .\emsdk.bat install latest
- .\emsdk.bat activate latest
-
- # Activate in current terminal
- .\emsdk_env.bat
- ```
- </TabItem>
-</Tabs>
-
-Verify the installation:
-
-```bash
-emcc --version
-# emcc (Emscripten gcc/clang-like replacement) 3.x.x
-```
+3. **Choose a template** (Empty Project) and click **Create**
-### Building
+</Steps>
-<Steps>
+The editor creates a project with the following structure:
-1. **Clone the repository**
+```
+my-game/
+├── project.esproject # Project manifest
+├── tsconfig.json # TypeScript config
+├── src/ # Your game scripts
+├── assets/
+│ ├── scenes/
+│ │ └── main.esscene # Default scene
+│ ├── textures/
+│ └── audio/
+└── .esengine/
+ ├── settings.json # Editor settings
+ └── sdk/ # SDK (auto-exported by editor)
+ ├── index.js
+ ├── index.d.ts
+ └── wasm.d.ts
+```
- ```bash
- git clone https://github.com/esengine/microes.git
- cd microes
- ```
+<Aside type="tip">
+ The editor automatically exports the SDK to `.esengine/sdk/`. You don't need to install it manually.
+</Aside>
-2. **Build WASM**
+## Development Workflow
- ```bash
- # Web build
- emcmake cmake -B build_web -DES_BUILD_WEB=ON
- cmake --build build_web
+<Steps>
- # WeChat MiniGame build
- emcmake cmake -B build_wxgame -DES_BUILD_WXGAME=ON
- cmake --build build_wxgame
- ```
+1. **Edit scenes** visually in the editor — add entities, attach components, arrange sprites
-3. **Build SDK**
+2. **Write scripts** in `src/` using TypeScript — define systems, custom components, and game logic
- ```bash
- cd sdk
- npm install
- npm run build
- ```
+3. **Press F5** to preview your game in the browser
</Steps>
-### CMake Options
-
-| Option | Default | Description |
-|--------|---------|-------------|
-| `ES_BUILD_WEB` | OFF | Build for web browsers |
-| `ES_BUILD_WXGAME` | OFF | Build for WeChat MiniGames |
-| `ES_BUILD_TESTS` | OFF | Build unit tests |
-
-## IDE Setup
-
-### Visual Studio Code
-
-Recommended extensions:
-- ESLint
-- TypeScript
-
-For C++ development:
-- C/C++ (Microsoft)
-- CMake Tools
-
## Next Steps
-Now that you have ESEngine set up, [create your first game](/microes/getting-started/quick-start/).
+Now that your project is ready, [create your first game](/microes/getting-started/quick-start/).
diff --git a/docs/astro/src/content/docs/getting-started/introduction.mdx b/docs/astro/src/content/docs/getting-started/introduction.mdx
index 8f2c04a0b..0c8302cc6 100644
--- a/docs/astro/src/content/docs/getting-started/introduction.mdx
+++ b/docs/astro/src/content/docs/getting-started/introduction.mdx
@@ -3,46 +3,36 @@ title: Introduction
description: Learn what ESEngine is and why you might want to use it
---
-ESEngine is a lightweight 2D game engine with a **TypeScript SDK** powered by a **C++/WebAssembly** backend. Build games that run in web browsers and WeChat MiniGames with excellent performance.
+ESEngine is a lightweight 2D game engine with a **TypeScript SDK** powered by a **C++/WebAssembly** backend. It comes with a visual editor for scene editing and project management, and outputs games that run in web browsers and WeChat MiniGames.
## Why ESEngine?
-### TypeScript-First Development
+### Visual Editor + TypeScript Scripting
-Write your game logic in TypeScript with a modern, type-safe ECS API:
+Use the editor to create projects, place entities in scenes, and attach components visually. Write game logic in TypeScript — define custom components and systems that operate on scene entities:
```typescript
-import { createWebApp, defineSystem, Schedule, Commands, Query, Res, Time, LocalTransform, Sprite } from 'esengine';
+import { defineComponent, defineSystem, addSystem, Query, Mut, Res, Time, LocalTransform } from 'esengine';
-const app = createWebApp(Module);
+const Speed = defineComponent('Speed', { value: 200 });
-app.addSystemToSchedule(Schedule.Update, defineSystem(
- [Res(Time), Query(LocalTransform, Sprite)],
+addSystem(defineSystem(
+ [Res(Time), Query(Mut(LocalTransform), Speed)],
(time, query) => {
- for (const [entity, transform, sprite] of query) {
- transform.position.x = Math.sin(time.elapsed) * 100;
+ for (const [entity, transform, speed] of query) {
+ transform.position.x += speed.value * time.delta;
}
}
));
-
-app.run();
```
-### High Performance C++ Backend
-
-The rendering and core ECS are implemented in C++ and compiled to WebAssembly:
+### High Performance
-- **Small binary size** - Optimized for fast initial load times
-- **Native performance** - C++ rendering pipeline
-- **Type-safe bridge** - TypeScript types match C++ components
+Rendering and core systems are implemented in C++ and compiled to WebAssembly, delivering native-level performance with small binary sizes and fast load times.
-### WeChat MiniGame Support
+### Cross-Platform
-First-class support for WeChat MiniGames platform:
-
-- Optimized touch input handling
-- WeChat-specific APIs (share, ad, payment)
-- Tested on real devices
+Single codebase targeting web browsers and WeChat MiniGames with platform-specific adapters.
## When to Use ESEngine
@@ -58,27 +48,8 @@ ESEngine may not be the best choice for:
- 3D games (2D only)
- Desktop-only games (use a native engine)
-## Architecture Overview
-
-```
-┌─────────────────────────────────────────────────────┐
-│ Your Game (TypeScript) │
-│ Systems │ Components │ Queries │ Resources │
-├─────────────────────────────────────────────────────┤
-│ ESEngine SDK │
-│ App │ World │ Commands │ defineSystem │
-├─────────────────────────────────────────────────────┤
-│ C++ WASM Backend │
-│ Registry │ Renderer │ Input │ ResourceManager │
-├─────────────────────────────────────────────────────┤
-│ Emscripten / WebGL │
-└─────────────────────────────────────────────────────┘
-```
-
## Next Steps
-Ready to get started?
-
-1. [Install the prerequisites](/microes/getting-started/installation/)
+1. [Install the editor](/microes/getting-started/installation/)
2. [Create your first game](/microes/getting-started/quick-start/)
-3. [Learn about ECS](/microes/guides/ecs/)
+3. [Learn about ECS](/microes/core-concepts/ecs/)
diff --git a/docs/astro/src/content/docs/getting-started/quick-start.mdx b/docs/astro/src/content/docs/getting-started/quick-start.mdx
index e2595082b..f2ec8dbef 100644
--- a/docs/astro/src/content/docs/getting-started/quick-start.mdx
+++ b/docs/astro/src/content/docs/getting-started/quick-start.mdx
@@ -5,132 +5,95 @@ description: Create your first ESEngine game in minutes
import { Steps, Aside } from '@astrojs/starlight/components';
-Let's create a simple game that displays a moving sprite. This will introduce you to the core concepts of ESEngine.
+Let's create a simple game that animates a sprite. This will introduce you to the core concepts of ESEngine.
-## Create a New Project
+## Create a Project
<Steps>
-1. **Create your project directory**
+1. **Open the editor** and click **New Project**
- ```bash
- mkdir my-game
- cd my-game
- npm init -y
- ```
+2. **Name your project** (e.g. "my-first-game") and click **Create**
-2. **Install dependencies**
+ The editor creates a project with a default scene containing a Camera entity.
- ```bash
- npm install esengine
- npm install -D esbuild typescript
- ```
+3. **Add a Sprite entity** in the editor
+
+ In the Hierarchy panel, create a new entity and add `LocalTransform` and `Sprite` components to it. Set the Sprite size to `100 x 100` and pick a color.
-3. **Create src/main.ts**
+4. **Create `src/main.ts`** with the following code:
```typescript
import {
- type ESEngineModule,
- createWebApp,
defineSystem,
- Schedule,
- Commands,
+ addSystem,
Query,
+ Mut,
Res,
Time,
LocalTransform,
Sprite,
- Camera
} from 'esengine';
- export async function main(Module: ESEngineModule): Promise<void> {
- const app = createWebApp(Module);
-
- // Startup system - runs once at the beginning
- app.addSystemToSchedule(Schedule.Startup, defineSystem(
- [Commands()],
- (cmds) => {
- // Create camera
- cmds.spawn()
- .insert(Camera, {
- projectionType: 1,
- orthoSize: 400,
- isActive: true
- })
- .insert(LocalTransform, {
- position: { x: 0, y: 0, z: 10 }
- });
-
- // Create a sprite
- cmds.spawn()
- .insert(Sprite, {
- color: { x: 1, y: 0.5, z: 0.2, w: 1 },
- size: { x: 100, y: 100 }
- })
- .insert(LocalTransform, {
- position: { x: 0, y: 0, z: 0 }
- });
+ addSystem(defineSystem(
+ [Res(Time), Query(Mut(LocalTransform), Sprite)],
+ (time, query) => {
+ for (const [entity, transform, sprite] of query) {
+ transform.position.x = Math.sin(time.elapsed) * 100;
+ transform.position.y = Math.cos(time.elapsed) * 100;
}
- ));
-
- // Update system - runs every frame
- app.addSystemToSchedule(Schedule.Update, defineSystem(
- [Res(Time), Query(LocalTransform, Sprite)],
- (time, query) => {
- for (const [entity, transform, sprite] of query) {
- // Move sprite in a circle
- transform.position.x = Math.sin(time.elapsed) * 100;
- transform.position.y = Math.cos(time.elapsed) * 100;
- }
- }
- ));
-
- app.run();
- }
+ }
+ ));
```
-4. **Add build script to package.json**
+5. **Press F5** in the editor to preview — the sprite moves in a circle
- ```json
- {
- "scripts": {
- "build": "esbuild src/main.ts --bundle --format=esm --outfile=build/main.js"
- }
- }
- ```
+</Steps>
-5. **Build your game**
+## Understanding the Code
- ```bash
- npm run build
- ```
+### Components Live in the Scene
-</Steps>
+In ESEngine, entities and their components are created in the **scene editor**. Your code doesn't create them — it defines **systems** that query and operate on scene entities.
-<Aside type="tip">
- You also need the ESEngine WASM files. See [Installation](/microes/getting-started/installation/) for how to build them.
-</Aside>
+The sprite you placed in step 3 already has `LocalTransform` and `Sprite` components. The system in step 4 finds it via `Query(Mut(LocalTransform), Sprite)` and animates it.
-## Understanding the Code
+### Custom Components
+
+You can define custom components in code, then attach them to entities in the editor:
+
+```typescript
+// src/components/Speed.ts
+import { defineComponent } from 'esengine';
-### App and Systems
+export const Speed = defineComponent('Speed', { value: 200 });
+```
-ESEngine uses a system-based architecture. Systems are functions that run at specific points in the game loop:
+After saving, the `Speed` component appears in the editor's "Add Component" menu. Attach it to an entity, then write a system that queries it:
```typescript
-// Create the app with WASM module
-const app = createWebApp(Module);
-
-// Add a system to a schedule
-app.addSystemToSchedule(Schedule.Update, defineSystem(
- [/* parameters */],
- (/* injected params */) => {
- // Game logic here
+// src/systems/movement.ts
+import { defineSystem, addSystem, Res, Time, Query, Mut, LocalTransform } from 'esengine';
+import { Speed } from '../components/Speed';
+
+addSystem(defineSystem(
+ [Res(Time), Query(Mut(LocalTransform), Speed)],
+ (time, query) => {
+ for (const [entity, transform, speed] of query) {
+ transform.position.x += speed.value * time.delta;
+ }
}
));
+```
+
+### Registering Systems
-// Start the game loop
-app.run();
+```typescript
+import { addSystem, addStartupSystem, addSystemToSchedule, Schedule } from 'esengine';
+
+addStartupSystem(system); // runs once at start
+addSystem(system); // runs every frame (Update)
+addSystemToSchedule(Schedule.FixedUpdate, system); // runs at fixed intervals
```
### Schedule Types
@@ -142,55 +105,23 @@ app.run();
| `PostUpdate` | After Update, every frame |
| `FixedUpdate` | At fixed time intervals |
-### System Parameters
+### Runtime Spawning
-Systems declare what data they need, and it gets injected automatically:
+Use `Commands` when you need to create entities at runtime (e.g. bullets, particles):
```typescript
-defineSystem(
- [Commands(), Res(Time), Query(LocalTransform, Sprite)],
- (cmds, time, query) => {
- // cmds: spawn/despawn entities
- // time: elapsed time, delta time
- // query: iterate entities with components
+addStartupSystem(defineSystem(
+ [Commands()],
+ (cmds) => {
+ cmds.spawn()
+ .insert(Sprite, { size: { x: 10, y: 10 } })
+ .insert(LocalTransform, { position: { x: 0, y: 0, z: 0 } });
}
-)
-```
-
-### Components
-
-Components are data attached to entities. ESEngine provides builtin components:
-
-| Component | Description |
-|-----------|-------------|
-| `LocalTransform` | Position, rotation, scale |
-| `Sprite` | 2D sprite rendering |
-| `Camera` | Camera settings |
-| `Velocity` | Movement velocity |
-
-### Creating Entities
-
-Use `Commands` to spawn entities and attach components:
-
-```typescript
-cmds.spawn()
- .insert(Sprite, { color: { x: 1, y: 0, z: 0, w: 1 } })
- .insert(LocalTransform, { position: { x: 100, y: 100, z: 0 } })
- .id(); // Returns the entity ID
-```
-
-### Querying Entities
-
-Use `Query` to iterate entities with specific components:
-
-```typescript
-for (const [entity, transform, sprite] of query) {
- transform.position.x += 1;
-}
+));
```
## Next Steps
-- [Learn ECS in depth](/microes/guides/ecs/)
-- [Handle input](/microes/guides/input/)
-- [Add sprites and textures](/microes/guides/rendering/)
+- [Understand the ECS pattern](/microes/core-concepts/ecs/)
+- [Learn about components](/microes/core-concepts/components/)
+- [Write systems](/microes/core-concepts/systems/)
diff --git a/docs/astro/src/content/docs/guides/assets.mdx b/docs/astro/src/content/docs/guides/assets.mdx
new file mode 100644
index 000000000..7a12ed7b4
--- /dev/null
+++ b/docs/astro/src/content/docs/guides/assets.mdx
@@ -0,0 +1,171 @@
+---
+title: Asset Loading
+description: Loading textures, Spine data, and other assets in ESEngine
+---
+
+import { Aside } from '@astrojs/starlight/components';
+
+ESEngine provides the `Assets` resource (an `AssetServer` instance) for loading textures, Spine animations, materials, and generic files. Access it in any system via `Res(Assets)`.
+
+## Accessing Assets
+
+```typescript
+import { defineSystem, addStartupSystem, Res } from 'esengine';
+import { Assets } from 'esengine';
+
+addStartupSystem(defineSystem(
+ [Res(Assets)],
+ async (assets) => {
+ const tex = await assets.loadTexture('assets/player.png');
+ console.log(`Loaded ${tex.width}x${tex.height}, handle: ${tex.handle}`);
+ }
+));
+```
+
+## Texture Loading
+
+### loadTexture(path)
+
+Loads an image and returns a `TextureInfo` object. The image is automatically flipped vertically for OpenGL UV conventions.
+
+```typescript
+const tex = await assets.loadTexture('assets/player.png');
+sprite.texture = tex.handle;
+```
+
+**Returns:** `TextureInfo { handle: TextureHandle, width: number, height: number }`
+
+### Other Texture Methods
+
+| Method | Description |
+|--------|-------------|
+| `getTexture(path)` | Returns cached `TextureInfo` if already loaded, `undefined` otherwise |
+| `hasTexture(path)` | Returns `true` if the texture is cached |
+| `releaseTexture(path)` | Releases the texture from GPU memory and cache |
+| `releaseAll()` | Releases all cached assets |
+
+### 9-Slice Metadata
+
+For 9-slice sprites, set border metadata after loading:
+
+```typescript
+const tex = await assets.loadTexture('assets/panel.png');
+assets.setTextureMetadata(tex.handle, {
+ left: 10, right: 10, top: 10, bottom: 10
+});
+```
+
+## Spine Loading
+
+```typescript
+const result = await assets.loadSpine('assets/hero.json', 'assets/hero.atlas');
+if (!result.success) {
+ console.error(result.error);
+}
+```
+
+`loadSpine` automatically:
+1. Fetches the atlas file and writes it to the virtual filesystem
+2. Parses the atlas for texture filenames and loads each texture
+3. Fetches the skeleton file (`.json` or `.skel` binary) and writes it to the virtual filesystem
+
+| Method | Description |
+|--------|-------------|
+| `loadSpine(skeleton, atlas, baseUrl?)` | Load Spine skeleton and atlas |
+| `isSpineLoaded(skeleton, atlas)` | Check if a Spine asset pair is already loaded |
+
+## Generic File Loading
+
+| Method | Returns | Description |
+|--------|---------|-------------|
+| `loadJson<T>(path, options?)` | `Promise<T>` | Load and parse a JSON file |
+| `loadText(path, options?)` | `Promise<string>` | Load a text file |
+| `loadBinary(path, options?)` | `Promise<ArrayBuffer>` | Load a binary file |
+
+```typescript
+const config = await assets.loadJson<GameConfig>('assets/config.json');
+const csv = await assets.loadText('assets/levels.csv');
+const data = await assets.loadBinary('assets/tilemap.bin');
+```
+
+### FileLoadOptions
+
+| Option | Type | Description |
+|--------|------|-------------|
+| `baseUrl` | string | Override the base URL for this request |
+| `noCache` | boolean | Skip cache — always fetch from network |
+
+## Batch Loading
+
+Load multiple assets in parallel with `loadAll`:
+
+```typescript
+const bundle = await assets.loadAll({
+ textures: ['assets/bg.png', 'assets/player.png'],
+ spine: [{ skeleton: 'assets/hero.json', atlas: 'assets/hero.atlas' }],
+ json: ['assets/config.json'],
+});
+
+// Access loaded assets from the bundle
+const bgTex = bundle.textures.get('assets/bg.png');
+const config = bundle.json.get('assets/config.json');
+```
+
+### AssetManifest
+
+| Field | Type | Description |
+|-------|------|-------------|
+| `textures` | string[] | Texture image paths |
+| `materials` | string[] | Material file paths (.material) |
+| `spine` | SpineDescriptor[] | Spine skeleton/atlas pairs |
+| `json` | string[] | JSON file paths |
+| `text` | string[] | Text file paths |
+| `binary` | string[] | Binary file paths |
+
+### AssetBundle
+
+The returned `AssetBundle` contains Maps keyed by path:
+
+| Field | Type |
+|-------|------|
+| `textures` | `Map<string, TextureInfo>` |
+| `materials` | `Map<string, LoadedMaterial>` |
+| `spine` | `Map<string, SpineLoadResult>` |
+| `json` | `Map<string, unknown>` |
+| `text` | `Map<string, string>` |
+| `binary` | `Map<string, ArrayBuffer>` |
+
+## Material Loading
+
+```typescript
+const loaded = await assets.loadMaterial('assets/effects/glow.material');
+sprite.material = loaded.handle;
+```
+
+See [Materials & Shaders](/microes/guides/materials/) for the full material API and `.material` file format.
+
+## Caching
+
+All load methods cache by path. Loading the same path twice returns the cached result without a network request. Use the `noCache` option on generic file loaders to bypass caching:
+
+```typescript
+const fresh = await assets.loadJson('assets/config.json', { noCache: true });
+```
+
+## Base URL
+
+Set `assets.baseUrl` to prefix all relative paths:
+
+```typescript
+assets.baseUrl = 'https://cdn.example.com/game';
+const tex = await assets.loadTexture('sprites/player.png');
+// fetches https://cdn.example.com/game/sprites/player.png
+```
+
+Absolute paths and full URLs are not affected by `baseUrl`.
+
+## Next Steps
+
+- [Materials & Shaders](/microes/guides/materials/) — custom shaders and blend modes
+- [Sprite](/microes/guides/sprite/) — using textures with sprites
+- [Spine Animation](/microes/guides/spine/) — Spine skeletal animation
diff --git a/docs/astro/src/content/docs/guides/ecs.mdx b/docs/astro/src/content/docs/guides/ecs.mdx
deleted file mode 100644
index 5b7fb67dd..000000000
--- a/docs/astro/src/content/docs/guides/ecs.mdx
+++ /dev/null
@@ -1,318 +0,0 @@
----
-title: ECS Architecture
-description: Understanding the Entity-Component-System pattern in ESEngine
----
-
-import { Aside } from '@astrojs/starlight/components';
-
-ESEngine uses an Entity-Component-System (ECS) architecture for game object management. This guide explains the concepts and API.
-
-## What is ECS?
-
-ECS separates **identity** (Entity), **data** (Component), and **behavior** (System):
-
-| Concept | Description | Example |
-|---------|-------------|---------|
-| **Entity** | A unique identifier | Player, Enemy, Bullet |
-| **Component** | Plain data struct | LocalTransform, Sprite, Velocity |
-| **System** | Logic operating on components | MovementSystem, RenderSystem |
-
-<Aside type="tip">
- ECS provides better cache performance than traditional OOP hierarchies because components are stored contiguously in memory.
-</Aside>
-
-## Entities
-
-An entity is just a number (ID). It has no data or behavior on its own.
-
-```typescript
-import { Commands, type Entity } from 'esengine';
-
-// In a system with Commands:
-defineSystem([Commands()], (cmds) => {
- // Create a new entity
- const player: Entity = cmds.spawn().id();
-
- // Despawn an entity
- cmds.despawn(player);
-});
-```
-
-## Components
-
-Components are data attached to entities. ESEngine provides builtin components backed by C++:
-
-### Builtin Components
-
-```typescript
-import { LocalTransform, Sprite, Camera, Velocity, Parent, Children } from 'esengine';
-
-// LocalTransform - position, rotation, scale
-cmds.spawn().insert(LocalTransform, {
- position: { x: 100, y: 200, z: 0 },
- rotation: { w: 1, x: 0, y: 0, z: 0 },
- scale: { x: 1, y: 1, z: 1 }
-});
-
-// Sprite - 2D rendering
-cmds.spawn().insert(Sprite, {
- texture: 0,
- color: { x: 1, y: 1, z: 1, w: 1 },
- size: { x: 64, y: 64 }
-});
-
-// Camera - view settings
-cmds.spawn().insert(Camera, {
- projectionType: 1, // Orthographic
- orthoSize: 400,
- isActive: true
-});
-
-// Velocity - movement
-cmds.spawn().insert(Velocity, {
- linear: { x: 100, y: 0, z: 0 },
- angular: { x: 0, y: 0, z: 0 }
-});
-```
-
-### Custom Components
-
-You can define your own components for game-specific data:
-
-```typescript
-import { defineComponent, defineTag } from 'esengine';
-
-// Data component with default values
-const Health = defineComponent('Health', {
- current: 100,
- max: 100
-});
-
-// Tag component (no data, just for filtering)
-const Player = defineTag('Player');
-const Enemy = defineTag('Enemy');
-
-// Usage
-cmds.spawn()
- .insert(Player)
- .insert(Health, { current: 100, max: 100 });
-```
-
-<Aside type="caution">
- Custom components are stored in TypeScript only. Builtin components are synced with the C++ backend for rendering.
-</Aside>
-
-### Adding Components
-
-```typescript
-// spawn() returns EntityCommands for chaining
-const entity = cmds.spawn()
- .insert(LocalTransform, { position: { x: 0, y: 0, z: 0 } })
- .insert(Sprite, { size: { x: 50, y: 50 } })
- .insert(Health, { current: 100, max: 100 })
- .id();
-
-// Add to existing entity
-cmds.entity(entity)
- .insert(Velocity, { linear: { x: 10, y: 0, z: 0 } });
-```
-
-### Removing Components
-
-```typescript
-cmds.entity(entity).remove(Velocity);
-```
-
-## Systems
-
-Systems contain game logic. They declare what data they need via parameters.
-
-### Defining Systems
-
-```typescript
-import { defineSystem, Schedule, Commands, Query, Res, Time } from 'esengine';
-
-const movementSystem = defineSystem(
- [Res(Time), Query(LocalTransform, Velocity)],
- (time, query) => {
- for (const [entity, transform, velocity] of query) {
- transform.position.x += velocity.linear.x * time.delta;
- transform.position.y += velocity.linear.y * time.delta;
- }
- }
-);
-
-// Add to app
-app.addSystemToSchedule(Schedule.Update, movementSystem);
-```
-
-### System Parameters
-
-| Parameter | Description | Usage |
-|-----------|-------------|-------|
-| `Commands()` | Spawn/despawn entities | `cmds.spawn()` |
-| `Query(...)` | Query entities with components | `for (const [e, ...] of query)` |
-| `Res(T)` | Read-only resource | `time.elapsed` |
-| `ResMut(T)` | Mutable resource | `state.score += 1` |
-
-### Schedule Types
-
-```typescript
-import { Schedule } from 'esengine';
-
-// Startup - runs once at beginning
-app.addSystemToSchedule(Schedule.Startup, setupSystem);
-
-// Update - runs every frame
-app.addSystemToSchedule(Schedule.Update, gameLogicSystem);
-
-// PostUpdate - after Update
-app.addSystemToSchedule(Schedule.PostUpdate, cleanupSystem);
-
-// FixedUpdate - fixed timestep (physics)
-app.addSystemToSchedule(Schedule.FixedUpdate, physicsSystem);
-```
-
-## Queries
-
-Queries let you iterate over entities that have specific components.
-
-### Basic Query
-
-```typescript
-defineSystem(
- [Query(LocalTransform, Sprite)],
- (query) => {
- // Iterate all entities with both LocalTransform AND Sprite
- for (const [entity, transform, sprite] of query) {
- transform.position.x += 1;
- }
- }
-);
-```
-
-### Query Methods
-
-```typescript
-defineSystem(
- [Query(LocalTransform, Sprite)],
- (query) => {
- // Iterate with for-of
- for (const [entity, transform, sprite] of query) { ... }
-
- // Iterate with forEach
- query.forEach((entity, transform, sprite) => { ... });
-
- // Get single entity (errors if 0 or >1)
- const [entity, transform, sprite] = query.single();
-
- // Get count
- const count = query.count();
- }
-);
-```
-
-## Resources
-
-Resources are global singletons, not attached to entities.
-
-### Builtin Resources
-
-```typescript
-import { Res, Time, Input } from 'esengine';
-
-defineSystem(
- [Res(Time)],
- (time) => {
- console.log(`Elapsed: ${time.elapsed}s`);
- console.log(`Delta: ${time.delta}s`);
- }
-);
-```
-
-### Custom Resources
-
-```typescript
-import { defineResource, Res, ResMut } from 'esengine';
-
-const GameState = defineResource({
- score: 0,
- level: 1,
- paused: false
-});
-
-// Read-only access
-defineSystem([Res(GameState)], (state) => {
- console.log(`Score: ${state.score}`);
-});
-
-// Mutable access
-defineSystem([ResMut(GameState)], (state) => {
- state.value.score += 10;
-});
-```
-
-## Best Practices
-
-### Do
-
-- Keep components small and focused
-- Use tags for filtering entities (`const Player = defineTag('Player')`)
-- Prefer composition over complex components
-- Use separate systems for different concerns
-
-### Don't
-
-- Put methods in components (use systems instead)
-- Store references to other entities directly (use entity IDs)
-- Create deeply nested component data
-- Modify components from multiple systems without care
-
-## Example: Complete Game Loop
-
-```typescript
-import {
- createWebApp, defineSystem, defineComponent, defineTag,
- Schedule, Commands, Query, Res, Time,
- LocalTransform, Sprite, Camera
-} from 'esengine';
-
-// Custom components
-const Velocity = defineComponent('Velocity', { x: 0, y: 0 });
-const Player = defineTag('Player');
-
-export async function main(Module) {
- const app = createWebApp(Module);
-
- // Setup
- app.addSystemToSchedule(Schedule.Startup, defineSystem(
- [Commands()],
- (cmds) => {
- // Camera
- cmds.spawn()
- .insert(Camera, { projectionType: 1, orthoSize: 400, isActive: true })
- .insert(LocalTransform, { position: { x: 0, y: 0, z: 10 } });
-
- // Player
- cmds.spawn()
- .insert(Player)
- .insert(Sprite, { size: { x: 50, y: 50 } })
- .insert(LocalTransform, { position: { x: 0, y: 0, z: 0 } })
- .insert(Velocity, { x: 100, y: 50 });
- }
- ));
-
- // Movement
- app.addSystemToSchedule(Schedule.Update, defineSystem(
- [Res(Time), Query(LocalTransform, Velocity)],
- (time, query) => {
- for (const [entity, transform, velocity] of query) {
- transform.position.x += velocity.x * time.delta;
- transform.position.y += velocity.y * time.delta;
- }
- }
- ));
-
- app.run();
-}
-```
diff --git a/docs/astro/src/content/docs/guides/input.mdx b/docs/astro/src/content/docs/guides/input.mdx
index f95fa2924..580d22364 100644
--- a/docs/astro/src/content/docs/guides/input.mdx
+++ b/docs/astro/src/content/docs/guides/input.mdx
@@ -12,13 +12,12 @@ ESEngine provides input handling through the `Input` resource.
Access input state through the `Res(Input)` system parameter:
```typescript
-import { defineSystem, Res, Input, Query, LocalTransform } from 'esengine';
+import { defineSystem, addSystem, Res, Input, Query, Mut, LocalTransform } from 'esengine';
-defineSystem(
- [Res(Input), Query(LocalTransform)],
+addSystem(defineSystem(
+ [Res(Input), Query(Mut(LocalTransform))],
(input, query) => {
for (const [entity, transform] of query) {
- // Move based on input
if (input.isKeyDown('KeyW')) {
transform.position.y -= 5;
}
@@ -33,7 +32,7 @@ defineSystem(
}
}
}
-);
+));
```
## Keyboard Input
@@ -41,19 +40,16 @@ defineSystem(
### Key State
```typescript
-// Check if key is currently held down
if (input.isKeyDown('Space')) {
- player.jump();
+ // Space is currently held
}
-// Check if key was just pressed this frame
if (input.isKeyPressed('Space')) {
- player.startJump();
+ // Space was just pressed this frame
}
-// Check if key was just released this frame
if (input.isKeyReleased('Space')) {
- player.endJump();
+ // Space was just released this frame
}
```
@@ -82,16 +78,14 @@ Use standard DOM key codes:
## Mouse Input
```typescript
-// Get mouse position
const mousePos = input.getMousePosition();
console.log(`Mouse at: ${mousePos.x}, ${mousePos.y}`);
-// Check mouse buttons
if (input.isMouseButtonDown(0)) { // Left button
- shoot(mousePos.x, mousePos.y);
+ // handle click
}
if (input.isMouseButtonDown(2)) { // Right button
- openContextMenu();
+ // handle right click
}
```
@@ -100,7 +94,6 @@ if (input.isMouseButtonDown(2)) { // Right button
Touch input is unified with mouse input for cross-platform support:
```typescript
-// Works for both mouse click and touch
if (input.isMouseButtonDown(0)) {
const pos = input.getMousePosition();
handleTap(pos.x, pos.y);
@@ -113,18 +106,19 @@ if (input.isMouseButtonDown(0)) {
## Example: Player Movement
+Define `Player` and `MoveSpeed` components, attach them to an entity in the scene editor, then write a movement system:
+
```typescript
import {
- defineSystem, defineComponent, Schedule,
- Res, Input, Time, Query, LocalTransform
+ defineSystem, defineComponent, defineTag, addSystem,
+ Res, Input, Time, Query, Mut, LocalTransform
} from 'esengine';
const Player = defineTag('Player');
const MoveSpeed = defineComponent('MoveSpeed', { value: 200 });
-// Movement system
-app.addSystemToSchedule(Schedule.Update, defineSystem(
- [Res(Input), Res(Time), Query(LocalTransform, MoveSpeed, Player)],
+addSystem(defineSystem(
+ [Res(Input), Res(Time), Query(Mut(LocalTransform), MoveSpeed, Player)],
(input, time, query) => {
for (const [entity, transform, speed] of query) {
const velocity = { x: 0, y: 0 };
@@ -142,14 +136,12 @@ app.addSystemToSchedule(Schedule.Update, defineSystem(
velocity.x = 1;
}
- // Normalize diagonal movement
const len = Math.sqrt(velocity.x * velocity.x + velocity.y * velocity.y);
if (len > 0) {
velocity.x /= len;
velocity.y /= len;
}
- // Apply movement
transform.position.x += velocity.x * speed.value * time.delta;
transform.position.y += velocity.y * speed.value * time.delta;
}
diff --git a/docs/astro/src/content/docs/guides/materials.mdx b/docs/astro/src/content/docs/guides/materials.mdx
new file mode 100644
index 000000000..c83340b6c
--- /dev/null
+++ b/docs/astro/src/content/docs/guides/materials.mdx
@@ -0,0 +1,265 @@
+---
+title: Materials & Shaders
+description: Custom shaders, blend modes, and material management in ESEngine
+---
+
+import { Aside } from '@astrojs/starlight/components';
+
+The `Material` API manages custom shaders and rendering effects. Assign a material to a `Sprite` or `SpineAnimation` component via the `material` field.
+
+## Creating a Shader
+
+```typescript
+import { Material } from 'esengine';
+
+const shader = Material.createShader(vertexSrc, fragmentSrc);
+```
+
+Returns a `ShaderHandle` (number). A return value of `0` indicates failure.
+
+### Built-in Vertex Attributes
+
+All shaders share these fixed vertex attribute locations:
+
+| Location | Name | Type | Description |
+|----------|------|------|-------------|
+| 0 | `a_position` | vec3 | Vertex position |
+| 1 | `a_color` | vec4 | Vertex color |
+| 2 | `a_texCoord` | vec2 | Texture coordinates |
+
+### Built-in Shader Sources
+
+`ShaderSources` provides the default sprite and color shaders as reference:
+
+| Constant | Description |
+|----------|-------------|
+| `ShaderSources.SPRITE_VERTEX` | Default sprite vertex shader |
+| `ShaderSources.SPRITE_FRAGMENT` | Default sprite fragment shader |
+| `ShaderSources.COLOR_VERTEX` | Vertex shader for untextured geometry |
+| `ShaderSources.COLOR_FRAGMENT` | Fragment shader for untextured geometry |
+
+## Creating a Material
+
+```typescript
+import { Material, BlendMode } from 'esengine';
+
+const mat = Material.create({
+ shader,
+ uniforms: {
+ u_time: 0,
+ u_tint: { x: 1, y: 0, z: 0, w: 1 },
+ },
+ blendMode: BlendMode.Additive,
+});
+
+sprite.material = mat;
+```
+
+### MaterialOptions
+
+| Field | Type | Default | Description |
+|-------|------|---------|-------------|
+| `shader` | ShaderHandle | — | Required. Shader to use |
+| `uniforms` | Record&lt;string, UniformValue&gt; | `{}` | Initial uniform values |
+| `blendMode` | BlendMode | `Normal` | Blend mode |
+| `depthTest` | boolean | `false` | Enable depth testing |
+
+## Uniforms
+
+### Setting and Getting
+
+```typescript
+Material.setUniform(mat, 'u_time', elapsed);
+Material.setUniform(mat, 'u_tint', { x: 1, y: 0.5, z: 0, w: 1 });
+
+const time = Material.getUniform(mat, 'u_time');
+```
+
+### Uniform Types
+
+| Type | Example |
+|------|---------|
+| number | `1.5` |
+| Vec2 | `{ x: 0.5, y: 1.0 }` |
+| Vec3 | `{ x: 1, y: 0, z: 0 }` |
+| Vec4 | `{ x: 1, y: 1, z: 1, w: 1 }` |
+| number[] | `[1, 2, 3, 4]` |
+| TextureRef | `Material.tex(textureId, slot?)` |
+
+### Texture Uniforms
+
+Use `Material.tex()` to create a texture reference for sampler uniforms:
+
+```typescript
+const tex = await assets.loadTexture('assets/noise.png');
+Material.setUniform(mat, 'u_noiseTex', Material.tex(tex.handle, 1));
+```
+
+## BlendMode
+
+| Value | Name | Description |
+|-------|------|-------------|
+| 0 | `Normal` | Standard alpha blending |
+| 1 | `Additive` | Additive blending (glow effects) |
+| 2 | `Multiply` | Multiply blending (darken) |
+| 3 | `Screen` | Screen blending (lighten) |
+| 4 | `PremultipliedAlpha` | Premultiplied alpha blending |
+
+```typescript
+Material.setBlendMode(mat, BlendMode.Screen);
+const mode = Material.getBlendMode(mat);
+```
+
+## Material Instances
+
+Create an instance that shares the same shader but has independent uniforms:
+
+```typescript
+const instance = Material.createInstance(sourceMat);
+Material.setUniform(instance, 'u_tint', { x: 0, y: 1, z: 0, w: 1 });
+```
+
+## Shader File Format (.shader)
+
+Shader files use `#pragma` directives to separate vertex and fragment sections:
+
+```glsl
+#pragma vertex
+#version 300 es
+precision highp float;
+
+layout(location = 0) in vec3 a_position;
+layout(location = 1) in vec4 a_color;
+layout(location = 2) in vec2 a_texCoord;
+
+uniform mat4 u_projection;
+uniform mat4 u_model;
+
+out vec4 v_color;
+out vec2 v_texCoord;
+
+void main() {
+ v_color = a_color;
+ v_texCoord = a_texCoord;
+ gl_Position = u_projection * u_model * vec4(a_position, 1.0);
+}
+#pragma end
+
+#pragma fragment
+#version 300 es
+precision highp float;
+
+in vec4 v_color;
+in vec2 v_texCoord;
+
+uniform sampler2D u_texture;
+
+out vec4 fragColor;
+
+void main() {
+ fragColor = texture(u_texture, v_texCoord) * v_color;
+}
+#pragma end
+```
+
+Load shader files via the asset server:
+
+```typescript
+const shader = await assets.loadShader('assets/effects/glow.shader');
+```
+
+## Material File Format (.material)
+
+Materials can be defined as JSON files and loaded via the asset server:
+
+```json
+{
+ "version": "1.0",
+ "type": "material",
+ "shader": "effects/glow.shader",
+ "blendMode": 1,
+ "depthTest": false,
+ "properties": {
+ "u_intensity": 1.5,
+ "u_color": { "x": 1, "y": 0.5, "z": 0, "w": 1 }
+ }
+}
+```
+
+| Field | Type | Description |
+|-------|------|-------------|
+| `version` | string | Format version (`"1.0"`) |
+| `type` | string | Must be `"material"` |
+| `shader` | string | Path to .shader file (relative to material or absolute) |
+| `blendMode` | number | BlendMode enum value |
+| `depthTest` | boolean | Enable depth testing |
+| `properties` | object | Uniform name/value pairs |
+
+```typescript
+const loaded = await assets.loadMaterial('assets/effects/glow.material');
+sprite.material = loaded.handle;
+```
+
+## Example: Flashing Effect
+
+Animate a uniform in a system to create a flashing effect:
+
+```typescript
+import { defineSystem, addSystem, Query, Mut, Res } from 'esengine';
+import { Sprite, Material, BlendMode, Time } from 'esengine';
+
+const flashShader = Material.createShader(
+ ShaderSources.SPRITE_VERTEX,
+ `#version 300 es
+ precision highp float;
+ in vec4 v_color;
+ in vec2 v_texCoord;
+ uniform sampler2D u_texture;
+ uniform float u_flash;
+ out vec4 fragColor;
+ void main() {
+ vec4 tex = texture(u_texture, v_texCoord) * v_color;
+ fragColor = mix(tex, vec4(1.0), u_flash * step(0.5, tex.a));
+ }`
+);
+
+const flashMat = Material.create({
+ shader: flashShader,
+ uniforms: { u_flash: 0.0 },
+});
+
+addSystem(defineSystem(
+ [Res(Time)],
+ (time) => {
+ const flash = Math.abs(Math.sin(time.elapsed * 5.0));
+ Material.setUniform(flashMat, 'u_flash', flash);
+ }
+));
+```
+
+## Full API Reference
+
+| Method | Description |
+|--------|-------------|
+| `Material.createShader(vertex, fragment)` | Create a shader program |
+| `Material.releaseShader(shader)` | Release a shader |
+| `Material.create(options)` | Create a material |
+| `Material.createInstance(source)` | Create a material instance sharing the shader |
+| `Material.createFromAsset(data, shader)` | Create from a parsed .material file |
+| `Material.setUniform(mat, name, value)` | Set a uniform value |
+| `Material.getUniform(mat, name)` | Get a uniform value |
+| `Material.getUniforms(mat)` | Get all uniforms as a Map |
+| `Material.setBlendMode(mat, mode)` | Set blend mode |
+| `Material.getBlendMode(mat)` | Get blend mode |
+| `Material.setDepthTest(mat, enabled)` | Set depth testing |
+| `Material.getShader(mat)` | Get the shader handle |
+| `Material.release(mat)` | Release a material |
+| `Material.isValid(mat)` | Check if a material exists |
+| `Material.toAssetData(mat, shaderPath)` | Export to serializable format |
+| `Material.tex(textureId, slot?)` | Create a texture uniform reference |
+
+## Next Steps
+
+- [Asset Loading](/microes/guides/assets/) — loading materials and shaders from files
+- [Sprite](/microes/guides/sprite/) — assigning materials to sprites
+- [Rendering Overview](/microes/guides/rendering/) — rendering pipeline
diff --git a/docs/astro/src/content/docs/guides/project-structure.mdx b/docs/astro/src/content/docs/guides/project-structure.mdx
deleted file mode 100644
index 9323e4873..000000000
--- a/docs/astro/src/content/docs/guides/project-structure.mdx
+++ /dev/null
@@ -1,201 +0,0 @@
----
-title: Project Structure
-description: How to organize your ESEngine game project
----
-
-This guide explains how to structure your ESEngine game project and the SDK architecture.
-
-## Game Project Structure
-
-A typical ESEngine game project:
-
-```
-my-game/
-├── src/
-│ ├── main.ts # Entry point
-│ ├── systems/ # Game systems
-│ │ ├── movement.ts
-│ │ ├── collision.ts
-│ │ └── input.ts
-│ └── components/ # Custom components
-│ ├── player.ts
-│ └── enemy.ts
-├── assets/ # Game assets
-│ ├── sprites/
-│ └── audio/
-├── build/ # Build output
-│ ├── main.js
-│ ├── esengine.js # WASM loader
-│ └── esengine.wasm # WASM binary
-├── index.html # HTML entry
-├── package.json
-└── tsconfig.json
-```
-
-## Entry Point
-
-Your `src/main.ts` exports a `main` function that receives the WASM module:
-
-```typescript
-import { createWebApp, defineSystem, Schedule, ... } from 'esengine';
-import type { ESEngineModule } from 'esengine';
-
-// Import your systems
-import { movementSystem } from './systems/movement';
-import { inputSystem } from './systems/input';
-
-export async function main(Module: ESEngineModule): Promise<void> {
- const app = createWebApp(Module);
-
- // Add systems
- app.addSystemToSchedule(Schedule.Startup, setupSystem);
- app.addSystemToSchedule(Schedule.Update, inputSystem);
- app.addSystemToSchedule(Schedule.Update, movementSystem);
-
- app.run();
-}
-```
-
-## Organizing Systems
-
-Create separate files for each system:
-
-```typescript
-// src/systems/movement.ts
-import { defineSystem, Res, Time, Query, LocalTransform, Velocity } from 'esengine';
-
-export const movementSystem = defineSystem(
- [Res(Time), Query(LocalTransform, Velocity)],
- (time, query) => {
- for (const [entity, transform, velocity] of query) {
- transform.position.x += velocity.linear.x * time.delta;
- transform.position.y += velocity.linear.y * time.delta;
- }
- }
-);
-```
-
-## Organizing Components
-
-Define custom components in separate files:
-
-```typescript
-// src/components/player.ts
-import { defineComponent, defineTag } from 'esengine';
-
-export const Player = defineTag('Player');
-
-export const Health = defineComponent('Health', {
- current: 100,
- max: 100
-});
-
-export const MoveSpeed = defineComponent('MoveSpeed', {
- value: 200
-});
-```
-
-## HTML Setup
-
-Your `index.html` loads the WASM and your game:
-
-```html
-<!DOCTYPE html>
-<html>
-<head>
- <title>My Game</title>
- <style>
- body { margin: 0; overflow: hidden; }
- canvas { display: block; }
- </style>
-</head>
-<body>
- <canvas id="canvas"></canvas>
- <script type="module">
- import ESEngineModule from './build/esengine.js';
- import { main } from './build/main.js';
-
- ESEngineModule().then(Module => {
- main(Module);
- });
- </script>
-</body>
-</html>
-```
-
-## SDK Architecture
-
-The ESEngine SDK is organized as a single-entry package:
-
-```
-esengine/
-├── dist/
-│ ├── index.js # Main entry
-│ ├── index.d.ts # TypeScript types
-│ ├── wasm.js # WASM types export
-│ └── wasm.d.ts
-└── src/
- ├── index.ts # Public exports
- ├── types.ts # Entity, Vec2, Vec3, etc.
- ├── component.ts # Components
- ├── resource.ts # Resources
- ├── query.ts # Query system
- ├── commands.ts # Commands
- ├── system.ts # System definitions
- ├── world.ts # World management
- ├── app.ts # App and createWebApp
- └── wasm.ts # WASM interface types
-```
-
-### Import from Single Entry
-
-```typescript
-// All imports from 'esengine'
-import {
- // App
- App, createWebApp,
-
- // ECS
- defineSystem, Schedule,
- Commands, Query,
- defineComponent, defineTag,
-
- // Resources
- Res, ResMut, defineResource, Time, Input,
-
- // Builtin Components
- LocalTransform, Sprite, Camera, Velocity,
-
- // Types
- type Entity, vec2, vec3, vec4, quat
-} from 'esengine';
-```
-
-## Best Practices
-
-### File Organization
-
-- Keep systems small and focused (one concern per system)
-- Group related components together
-- Use barrel exports (`index.ts`) for cleaner imports
-
-### Code Structure
-
-```typescript
-// src/systems/index.ts
-export { movementSystem } from './movement';
-export { inputSystem } from './input';
-export { collisionSystem } from './collision';
-
-// src/main.ts
-import { movementSystem, inputSystem, collisionSystem } from './systems';
-```
-
-### Separation of Concerns
-
-| Layer | Responsibility |
-|-------|----------------|
-| Components | Data only, no logic |
-| Systems | Game logic, operates on components |
-| Resources | Global state (time, input, game state) |
-| App | Wiring systems together |
diff --git a/docs/astro/src/content/docs/guides/rendering.mdx b/docs/astro/src/content/docs/guides/rendering.mdx
index f6cc605cc..fb95cfc37 100644
--- a/docs/astro/src/content/docs/guides/rendering.mdx
+++ b/docs/astro/src/content/docs/guides/rendering.mdx
@@ -1,114 +1,45 @@
---
title: Rendering
-description: Drawing sprites and managing the camera in ESEngine
+description: Camera, transform, and render order in ESEngine
---
import { Aside } from '@astrojs/starlight/components';
-ESEngine uses a component-based rendering system. Add rendering components to entities and the engine handles drawing automatically.
+ESEngine uses a component-based rendering system. Add rendering components to entities in the scene editor and the C++ backend handles drawing automatically.
-## Sprites
+For detailed guides on specific rendering components, see [Sprite](/microes/guides/sprite/) and [Spine Animation](/microes/guides/spine/).
-The `Sprite` component makes an entity visible:
+## Camera
-```typescript
-import { Commands, Sprite, LocalTransform } from 'esengine';
-
-defineSystem([Commands()], (cmds) => {
- cmds.spawn()
- .insert(Sprite, {
- texture: 0, // Texture ID
- color: { x: 1, y: 1, z: 1, w: 1 }, // RGBA (white)
- size: { x: 64, y: 64 }, // Width, height
- uvOffset: { x: 0, y: 0 }, // Texture offset
- uvScale: { x: 1, y: 1 }, // Texture scale
- layer: 0, // Render order
- flipX: false,
- flipY: false
- })
- .insert(LocalTransform, {
- position: { x: 100, y: 100, z: 0 }
- });
-});
-```
+A `Camera` component is required to see anything. The editor's default scene already includes one.
-### Sprite Properties
+### Camera Properties
| Property | Type | Description |
|----------|------|-------------|
-| `texture` | number | Texture resource ID |
-| `color` | Vec4 | Tint color (RGBA, 0-1) |
-| `size` | Vec2 | Sprite dimensions in pixels |
-| `uvOffset` | Vec2 | Texture coordinate offset |
-| `uvScale` | Vec2 | Texture coordinate scale |
-| `layer` | number | Render order (higher = on top) |
-| `flipX` | boolean | Flip horizontally |
-| `flipY` | boolean | Flip vertically |
-
-### Colored Rectangle
-
-For simple colored rectangles without textures:
-
-```typescript
-cmds.spawn()
- .insert(Sprite, {
- texture: 0, // No texture
- color: { x: 1, y: 0, z: 0, w: 1 }, // Red
- size: { x: 50, y: 50 }
- })
- .insert(LocalTransform, {
- position: { x: 200, y: 200, z: 0 }
- });
-```
-
-## Camera
-
-A `Camera` component is required to see anything. Create one in your startup system:
-
-```typescript
-cmds.spawn()
- .insert(Camera, {
- projectionType: 1, // 0 = Perspective, 1 = Orthographic
- fov: 60, // Field of view (perspective only)
- orthoSize: 400, // Half-height in world units (ortho only)
- nearPlane: 0.1,
- farPlane: 1000,
- aspectRatio: 1, // Usually set automatically
- isActive: true, // Only one camera should be active
- priority: 0 // Higher priority camera wins
- })
- .insert(LocalTransform, {
- position: { x: 0, y: 0, z: 10 } // Camera position
- });
-```
+| `projectionType` | number | 0 = Perspective, 1 = Orthographic |
+| `fov` | number | Field of view in degrees (perspective only) |
+| `orthoSize` | number | Half-height in world units (orthographic only) |
+| `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 |
### Orthographic Camera
-Best for 2D games. The `orthoSize` determines how much of the world is visible:
-
-```typescript
-// Camera showing 800x600 world units
-cmds.spawn()
- .insert(Camera, {
- projectionType: 1,
- orthoSize: 300, // Half of 600
- isActive: true
- })
- .insert(LocalTransform, {
- position: { x: 400, y: 300, z: 10 } // Center of 800x600 world
- });
-```
+Best for 2D games. The `orthoSize` determines how much of the world is visible. Set `projectionType` to `1` in the inspector.
### Moving the Camera
-Query and modify the camera's transform:
+Query the camera entity and modify its transform:
```typescript
-defineSystem(
- [Res(Input), Query(LocalTransform, Camera)],
+import { defineSystem, addSystem, Res, Input, Query, Mut, LocalTransform, Camera } from 'esengine';
+
+addSystem(defineSystem(
+ [Res(Input), Query(Mut(LocalTransform), Camera)],
(input, query) => {
for (const [entity, transform, camera] of query) {
- // Pan camera with arrow keys
if (input.isKeyDown('ArrowLeft')) {
transform.position.x -= 5;
}
@@ -117,34 +48,25 @@ defineSystem(
}
}
}
-);
+));
```
## Transform
-Every visible entity needs a `LocalTransform`:
-
-```typescript
-cmds.spawn()
- .insert(LocalTransform, {
- position: { x: 100, y: 200, z: 0 },
- rotation: { w: 1, x: 0, y: 0, z: 0 }, // Quaternion
- scale: { x: 1, y: 1, z: 1 }
- })
- .insert(Sprite, { ... });
-```
+Every visible entity needs a `LocalTransform`. Add it to entities in the scene editor and configure position, rotation, and scale in the inspector.
### Rotation
-Rotation uses quaternions. For 2D rotation around Z-axis:
+Rotation uses quaternions. For 2D rotation around the Z-axis:
```typescript
-// Rotate sprite over time
-defineSystem(
- [Res(Time), Query(LocalTransform, Sprite)],
+import { defineSystem, addSystem, Res, Time, Query, Mut, LocalTransform, Sprite } from 'esengine';
+
+addSystem(defineSystem(
+ [Res(Time), Query(Mut(LocalTransform), Sprite)],
(time, query) => {
for (const [entity, transform, sprite] of query) {
- const angle = time.elapsed; // Radians
+ const angle = time.elapsed;
const halfAngle = angle / 2;
transform.rotation = {
w: Math.cos(halfAngle),
@@ -154,76 +76,24 @@ defineSystem(
};
}
}
-);
+));
```
### Scale
```typescript
-// Double size
-transform.scale = { x: 2, y: 2, z: 1 };
-
-// Flip horizontally
-transform.scale = { x: -1, y: 1, z: 1 };
+transform.scale = { x: 2, y: 2, z: 1 }; // Double size
+transform.scale = { x: -1, y: 1, z: 1 }; // Flip horizontally
```
## Render Order
Sprites are drawn in order by:
-1. **Z position** - Lower Z draws first (behind)
-2. **Layer** - Higher layer draws on top
-
-```typescript
-// Background (behind everything)
-cmds.spawn()
- .insert(Sprite, { layer: 0, ... })
- .insert(LocalTransform, { position: { x: 0, y: 0, z: -10 } });
-
-// Player (middle)
-cmds.spawn()
- .insert(Sprite, { layer: 1, ... })
- .insert(LocalTransform, { position: { x: 0, y: 0, z: 0 } });
-
-// UI (on top)
-cmds.spawn()
- .insert(Sprite, { layer: 10, ... })
- .insert(LocalTransform, { position: { x: 0, y: 0, z: 10 } });
-```
-
-## Example: Animated Sprite
+1. **Z position** (`transform.position.z`) — lower Z draws first (behind)
+2. **Layer** (`sprite.layer`) — higher layer draws on top
-```typescript
-import {
- defineSystem, defineComponent, Schedule,
- Res, Time, Query, LocalTransform, Sprite
-} from 'esengine';
-
-const Animation = defineComponent('Animation', {
- frames: 4,
- currentFrame: 0,
- frameTime: 0.1,
- elapsed: 0
-});
-
-// Animation system
-app.addSystemToSchedule(Schedule.Update, defineSystem(
- [Res(Time), Query(Sprite, Animation)],
- (time, query) => {
- for (const [entity, sprite, anim] of query) {
- anim.elapsed += time.delta;
-
- if (anim.elapsed >= anim.frameTime) {
- anim.elapsed = 0;
- anim.currentFrame = (anim.currentFrame + 1) % anim.frames;
-
- // Update UV offset for sprite sheet
- sprite.uvOffset.x = anim.currentFrame / anim.frames;
- }
- }
- }
-));
-```
+Set these values in the inspector when placing entities, or modify them at runtime in systems.
<Aside type="tip">
The C++ backend handles all WebGL rendering. You just set component data and the engine draws everything automatically each frame.
diff --git a/docs/astro/src/content/docs/guides/spine.mdx b/docs/astro/src/content/docs/guides/spine.mdx
new file mode 100644
index 000000000..ae0aaad49
--- /dev/null
+++ b/docs/astro/src/content/docs/guides/spine.mdx
@@ -0,0 +1,138 @@
+---
+title: Spine Animation
+description: Spine skeletal animation in ESEngine
+---
+
+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`.
+
+## Properties
+
+| Property | Type | Default | Description |
+|----------|------|---------|-------------|
+| `skeletonPath` | string | `''` | Path to skeleton JSON file |
+| `atlasPath` | string | `''` | Path to atlas file |
+| `skin` | string | `''` | Active skin name |
+| `animation` | string | `''` | Current animation name |
+| `timeScale` | number | `1.0` | Playback speed multiplier |
+| `loop` | boolean | `true` | Whether to loop the animation |
+| `playing` | boolean | `true` | Whether currently playing |
+| `flipX` | boolean | `false` | Flip horizontally |
+| `flipY` | boolean | `false` | Flip vertically |
+| `color` | Vec4 | `{1, 1, 1, 1}` | Tint color RGBA |
+| `layer` | number | `0` | Render order |
+| `skeletonScale` | number | `1.0` | Skeleton scale factor |
+| `material` | number | `0` | Material ID |
+
+## Setup
+
+1. Place Spine export files (`.json` + `.atlas` + images) in your project's `assets/` folder
+2. In the scene editor: create an entity → add `LocalTransform` and `SpineAnimation`
+3. Set `skeletonPath` and `atlasPath` to point to your Spine files
+4. Set `animation` to the name of the animation to play
+
+## Controlling Animations
+
+Query the `SpineAnimation` component in a system to change animations at runtime:
+
+```typescript
+import { defineSystem, addSystem, Res, Input, Query, Mut, SpineAnimation } from 'esengine';
+import { Player } from './components';
+
+addSystem(defineSystem(
+ [Res(Input), Query(Mut(SpineAnimation), Player)],
+ (input, query) => {
+ for (const [entity, spine] of query) {
+ if (input.isKeyPressed('Space')) {
+ spine.animation = 'jump';
+ spine.loop = false;
+ } else if (input.isKeyDown('KeyD') || input.isKeyDown('KeyA')) {
+ spine.animation = 'run';
+ spine.loop = true;
+ } else {
+ spine.animation = 'idle';
+ spine.loop = true;
+ }
+ }
+ }
+));
+```
+
+## Skins
+
+Switch skins to change the character's appearance:
+
+```typescript
+spine.skin = 'warrior';
+```
+
+## Playback Control
+
+```typescript
+spine.playing = false; // Pause
+spine.playing = true; // Resume
+spine.timeScale = 2.0; // Double speed
+spine.timeScale = 0.5; // Half speed
+```
+
+## Flipping
+
+```typescript
+spine.flipX = true; // Face left
+spine.flipX = false; // Face right (default)
+```
+
+## Color Tinting
+
+```typescript
+spine.color = { x: 1, y: 0, z: 0, w: 1 }; // Red tint
+spine.color = { x: 1, y: 1, z: 1, w: 0.5 }; // 50% transparent
+```
+
+## Example: Character Controller
+
+Define a `CharacterState` component, attach it with `SpineAnimation` on the entity in the editor:
+
+```typescript
+import {
+ defineComponent, defineSystem, addSystem,
+ Res, Input, Time, Query, Mut, LocalTransform, SpineAnimation
+} from 'esengine';
+
+const CharacterState = defineComponent('CharacterState', {
+ speed: 200,
+ currentAnim: 'idle'
+});
+
+addSystem(defineSystem(
+ [Res(Input), Res(Time), Query(Mut(LocalTransform), Mut(SpineAnimation), CharacterState)],
+ (input, time, query) => {
+ for (const [entity, transform, spine, state] of query) {
+ let moving = false;
+
+ if (input.isKeyDown('KeyD')) {
+ transform.position.x += state.speed * time.delta;
+ spine.flipX = false;
+ moving = true;
+ }
+ if (input.isKeyDown('KeyA')) {
+ transform.position.x -= state.speed * time.delta;
+ spine.flipX = true;
+ moving = true;
+ }
+
+ const newAnim = moving ? 'run' : 'idle';
+ if (state.currentAnim !== newAnim) {
+ state.currentAnim = newAnim;
+ spine.animation = newAnim;
+ spine.loop = true;
+ }
+ }
+ }
+));
+```
+
+<Aside type="tip">
+ Spine rendering is handled by the C++ backend. The TypeScript side only sets component data — the engine handles loading, blending, and drawing automatically.
+</Aside>
diff --git a/docs/astro/src/content/docs/guides/sprite.mdx b/docs/astro/src/content/docs/guides/sprite.mdx
new file mode 100644
index 000000000..0e16a40ad
--- /dev/null
+++ b/docs/astro/src/content/docs/guides/sprite.mdx
@@ -0,0 +1,127 @@
+---
+title: Sprite
+description: 2D sprite rendering in ESEngine
+---
+
+import { Aside } from '@astrojs/starlight/components';
+
+The `Sprite` component is the primary way to display 2D graphics. Add it to an entity in the scene editor along with `LocalTransform` to make the entity visible.
+
+## Properties
+
+| Property | Type | Default | Description |
+|----------|------|---------|-------------|
+| `texture` | number | `INVALID_TEXTURE` | Texture handle. No texture = solid color |
+| `color` | Vec4 | `{1, 1, 1, 1}` | Tint color RGBA (0–1) |
+| `size` | Vec2 | `{32, 32}` | Width and height in pixels |
+| `uvOffset` | Vec2 | `{0, 0}` | Texture coordinate offset |
+| `uvScale` | Vec2 | `{1, 1}` | Texture coordinate scale |
+| `layer` | number | `0` | Render order (higher = on top) |
+| `flipX` | boolean | `false` | Flip horizontally |
+| `flipY` | boolean | `false` | Flip vertically |
+| `material` | number | `0` | Material ID |
+
+## Basic Usage
+
+In the scene editor: create an entity → add `LocalTransform` and `Sprite` → set size and color in the inspector.
+
+To modify sprites at runtime, query them in a system:
+
+```typescript
+import { defineSystem, addSystem, Res, Time, Query, Mut, LocalTransform, Sprite } from 'esengine';
+
+addSystem(defineSystem(
+ [Res(Time), Query(Mut(LocalTransform), Sprite)],
+ (time, query) => {
+ for (const [entity, transform, sprite] of query) {
+ transform.position.x = Math.sin(time.elapsed) * 100;
+ }
+ }
+));
+```
+
+## Solid Color Rectangle
+
+Without a texture (default), the sprite renders as a solid rectangle using its `color` and `size`.
+
+## Color Tinting
+
+The `color` property tints the sprite. With a texture, the texture color is multiplied by the tint.
+
+```typescript
+sprite.color = { x: 1, y: 0, z: 0, w: 1 }; // Red tint
+sprite.color = { x: 1, y: 1, z: 1, w: 0.5 }; // 50% transparent
+```
+
+## Flipping
+
+```typescript
+sprite.flipX = true; // Mirror horizontally
+sprite.flipY = true; // Mirror vertically
+```
+
+## Sprite Sheet Animation
+
+Use `uvOffset` and `uvScale` to display a portion of a texture. Define a custom `Animation` component, attach it alongside `Sprite` on the entity in the editor:
+
+```typescript
+import { defineComponent, defineSystem, addSystem, Res, Time, Query, Mut, Sprite } from 'esengine';
+
+const Animation = defineComponent('Animation', {
+ frames: 4,
+ currentFrame: 0,
+ frameTime: 0.1,
+ elapsed: 0
+});
+
+addSystem(defineSystem(
+ [Res(Time), Query(Mut(Sprite), Animation)],
+ (time, query) => {
+ for (const [entity, sprite, anim] of query) {
+ anim.elapsed += time.delta;
+
+ if (anim.elapsed >= anim.frameTime) {
+ anim.elapsed = 0;
+ anim.currentFrame = (anim.currentFrame + 1) % anim.frames;
+ sprite.uvOffset.x = anim.currentFrame / anim.frames;
+ sprite.uvScale.x = 1 / anim.frames;
+ }
+ }
+ }
+));
+```
+
+## Render Order
+
+Sprites are drawn by:
+
+1. **Z position** (`transform.position.z`) — lower Z draws first (behind)
+2. **Layer** (`sprite.layer`) — higher layer draws on top
+
+Set these in the inspector or modify at runtime.
+
+## Runtime Spawning
+
+For sprites created at runtime (bullets, particles):
+
+```typescript
+import { defineSystem, addSystem, Commands, Sprite, LocalTransform } from 'esengine';
+
+addSystem(defineSystem(
+ [Commands()],
+ (cmds) => {
+ cmds.spawn()
+ .insert(Sprite, {
+ size: { x: 10, y: 10 },
+ color: { x: 1, y: 1, z: 0, w: 1 }
+ })
+ .insert(LocalTransform, {
+ position: { x: 0, y: 0, z: 0 }
+ });
+ }
+));
+```
+
+<Aside type="tip">
+ The C++ backend handles all WebGL rendering. You just set component data and the engine draws everything automatically each frame.
+</Aside>
diff --git a/docs/astro/src/content/docs/guides/ui.mdx b/docs/astro/src/content/docs/guides/ui.mdx
new file mode 100644
index 000000000..daf3a5601
--- /dev/null
+++ b/docs/astro/src/content/docs/guides/ui.mdx
@@ -0,0 +1,127 @@
+---
+title: UI & Text
+description: Text rendering and UI layout components in ESEngine
+---
+
+import { Aside } from '@astrojs/starlight/components';
+
+The `Text` and `UIRect` components work together with `Sprite` to render text in your game. The `TextPlugin` automatically converts text content into textures each frame.
+
+## Setup
+
+In the scene editor: create an entity → add `LocalTransform`, `Sprite`, `Text`, and `UIRect` components.
+
+- **Text** — defines the text content and style (font, size, color, alignment)
+- **UIRect** — defines the layout rectangle (size, anchor, pivot)
+- **Sprite** — used internally by the text system to display the rendered texture
+
+<Aside type="note">
+ You don't need to configure the Sprite component manually. The `TextPlugin` automatically creates and updates the sprite texture from the Text content.
+</Aside>
+
+## Text Properties
+
+| Property | Type | Default | Description |
+|----------|------|---------|-------------|
+| `content` | string | `''` | Text content to display |
+| `fontFamily` | string | `'Arial'` | Font family name |
+| `fontSize` | number | `24` | Font size in pixels |
+| `color` | Vec4 | `{1, 1, 1, 1}` | Text color RGBA (0–1) |
+| `align` | TextAlign | `Left` | Horizontal alignment |
+| `verticalAlign` | TextVerticalAlign | `Top` | Vertical alignment |
+| `wordWrap` | boolean | `true` | Enable automatic word wrapping |
+| `overflow` | TextOverflow | `Visible` | Overflow handling mode |
+| `lineHeight` | number | `1.2` | Line height multiplier |
+
+## UIRect Properties
+
+| Property | Type | Default | Description |
+|----------|------|---------|-------------|
+| `size` | Vec2 | `{100, 100}` | Width and height of the UI rectangle |
+| `anchor` | Vec2 | `{0.5, 0.5}` | Anchor point (0–1 range) |
+| `pivot` | Vec2 | `{0.5, 0.5}` | Pivot point for rotation and scaling |
+
+## Enums
+
+### TextAlign
+
+| Value | Name | Description |
+|-------|------|-------------|
+| 0 | `Left` | Align text to the left edge |
+| 1 | `Center` | Center text horizontally |
+| 2 | `Right` | Align text to the right edge |
+
+### TextVerticalAlign
+
+| Value | Name | Description |
+|-------|------|-------------|
+| 0 | `Top` | Align text to the top |
+| 1 | `Middle` | Center text vertically |
+| 2 | `Bottom` | Align text to the bottom |
+
+### TextOverflow
+
+| Value | Name | Description |
+|-------|------|-------------|
+| 0 | `Visible` | Text overflows the rectangle boundary |
+| 1 | `Clip` | Text is clipped at the boundary |
+| 2 | `Ellipsis` | Truncated text shows "..." |
+
+## Modifying Text at Runtime
+
+To update text content or style during gameplay, query the `Text` component with `Mut()`:
+
+```typescript
+import { defineSystem, addSystem, Query, Mut } from 'esengine';
+import { Text } from 'esengine';
+
+addSystem(defineSystem(
+ [Query(Mut(Text))],
+ (query) => {
+ for (const [entity, text] of query) {
+ text.content = 'Updated!';
+ text.fontSize = 32;
+ }
+ }
+));
+```
+
+<Aside type="caution">
+ Always use `Mut(Text)` when modifying text properties. Without `Mut()`, the component is read-only.
+</Aside>
+
+## Example: Dynamic Scoreboard
+
+A common pattern is a score display that updates when a value changes:
+
+```typescript
+import { defineComponent, defineTag, defineSystem, addSystem, Query, Mut } from 'esengine';
+import { Text } from 'esengine';
+
+const ScoreDisplay = defineTag('ScoreDisplay');
+
+const GameState = defineComponent('GameState', {
+ score: 0,
+});
+
+addSystem(defineSystem(
+ [Query(Mut(Text), ScoreDisplay), Query(GameState)],
+ (displayQuery, stateQuery) => {
+ let score = 0;
+ for (const [, state] of stateQuery) {
+ score = state.score;
+ }
+ for (const [, text] of displayQuery) {
+ text.content = `Score: ${score}`;
+ }
+ }
+));
+```
+
+In the editor: create a text entity with `Text`, `UIRect`, `Sprite`, `LocalTransform`, and the `ScoreDisplay` tag.
+
+## Next Steps
+
+- [Components](/microes/core-concepts/components/) — all builtin components
+- [Sprite](/microes/guides/sprite/) — sprite rendering details
+- [Asset Loading](/microes/guides/assets/) — loading textures and other assets
diff --git a/docs/astro/src/content/docs/index.mdx b/docs/astro/src/content/docs/index.mdx
index d2ef38d31..f43a461b1 100644
--- a/docs/astro/src/content/docs/index.mdx
+++ b/docs/astro/src/content/docs/index.mdx
@@ -1,9 +1,9 @@
---
-title: ESEngine Documentation
-description: A lightweight C++17 game engine for WebAssembly and WeChat MiniGames
+title: ESEngine
+description: A lightweight 2D game engine for web and WeChat MiniGames
template: splash
hero:
- tagline: Build high-performance games for the web with modern C++
+ tagline: Build 2D games for the web with TypeScript and WebAssembly
image:
file: ../../assets/hero.svg
actions:
@@ -22,52 +22,52 @@ import { Card, CardGrid } from '@astrojs/starlight/components';
<CardGrid stagger>
<Card title="ECS Architecture" icon="puzzle">
- Data-oriented Entity-Component-System design for cache-friendly, high-performance game logic.
+ Data-oriented Entity-Component-System design. Compose game objects from reusable components and drive behavior with systems.
</Card>
<Card title="WebGL Rendering" icon="laptop">
- OpenGL ES 2.0/3.0 compatible graphics pipeline optimized for WebAssembly.
+ C++ rendering pipeline compiled to WebAssembly. Sprites, cameras, Spine animations, and custom shaders out of the box.
</Card>
<Card title="Cross-Platform" icon="rocket">
- Single codebase targeting Web browsers and WeChat MiniGames.
+ Single codebase targeting web browsers and WeChat MiniGames with platform-specific adapters.
</Card>
- <Card title="Lightweight" icon="seti:todo">
- Minimal dependencies with optimized binary size for fast loading.
+ <Card title="TypeScript SDK" icon="seti:typescript">
+ Type-safe API with `defineSystem`, `defineComponent`, and `Query` — write game logic in idiomatic TypeScript.
</Card>
</CardGrid>
## Quick Example
-```cpp
-#include <esengine/ESEngine.hpp>
+Define a custom component, attach it to entities in the scene editor, then write a system:
-class MyGame : public esengine::Application {
-protected:
- void onInit() override {
- auto player = getRegistry().create();
- getRegistry().emplace<Position>(player, 0.0f, 0.0f);
- }
+```typescript
+import {
+ defineComponent, defineSystem, addSystem,
+ Query, Mut, Res, Time, LocalTransform
+} from 'esengine';
+
+const Speed = defineComponent('Speed', { value: 200 });
- void onUpdate(float dt) override {
- for (auto [e, pos] : getRegistry().view<Position>().each()) {
- pos.x += 100.0f * dt;
+addSystem(defineSystem(
+ [Res(Time), Query(Mut(LocalTransform), Speed)],
+ (time, query) => {
+ for (const [entity, transform, speed] of query) {
+ transform.position.x += speed.value * time.delta;
}
}
-};
-
-ES_MAIN(MyGame)
+));
```
## Next Steps
<CardGrid>
- <Card title="Installation" icon="setting">
- Set up your development environment with CMake and Emscripten.
+ <Card title="Introduction" icon="open-book">
+ Learn what ESEngine is and how it works.
- [Read the guide →](/microes/getting-started/installation/)
+ [Read more →](/microes/getting-started/introduction/)
</Card>
- <Card title="API Reference" icon="open-book">
- Explore the complete API documentation generated from source.
+ <Card title="Quick Start" icon="rocket">
+ Create your first game in minutes.
- [Browse API →](/microes/api/overview/)
+ [Get started →](/microes/getting-started/quick-start/)
</Card>
</CardGrid>
diff --git a/docs/astro/src/content/docs/platforms/web.mdx b/docs/astro/src/content/docs/platforms/web.mdx
deleted file mode 100644
index 24d4a93e5..000000000
--- a/docs/astro/src/content/docs/platforms/web.mdx
+++ /dev/null
@@ -1,250 +0,0 @@
----
-title: Web (Emscripten)
-description: Building and deploying ESEngine games for web browsers
----
-
-import { Steps, Aside, Tabs, TabItem } from '@astrojs/starlight/components';
-
-This guide covers building ESEngine games for deployment in web browsers using Emscripten.
-
-## Build Configuration
-
-### CMake Options
-
-```bash
-emcmake cmake -B build_web \
- -DES_BUILD_WEB=ON \
- -DCMAKE_BUILD_TYPE=Release
-
-cmake --build build_web
-```
-
-### Output Files
-
-After building, you'll have:
-
-```
-build_web/
-├── MyGame.html # Standalone HTML page
-├── MyGame.js # Emscripten glue code
-├── MyGame.wasm # WebAssembly binary
-└── MyGame.data # Asset bundle (if using PRELOAD)
-```
-
-## Embedding in HTML
-
-### Standalone Page
-
-The generated `.html` file works out of the box:
-
-```bash
-npx serve build_web
-# Open http://localhost:3000/MyGame.html
-```
-
-### Custom HTML
-
-```html
-<!DOCTYPE html>
-<html>
-<head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <title>My Game</title>
- <style>
- body { margin: 0; background: #000; }
- #canvas {
- display: block;
- width: 100vw;
- height: 100vh;
- }
- </style>
-</head>
-<body>
- <canvas id="canvas"></canvas>
- <script>
- var Module = {
- canvas: document.getElementById('canvas'),
- onRuntimeInitialized: function() {
- console.log('Game loaded!');
- }
- };
- </script>
- <script src="MyGame.js"></script>
-</body>
-</html>
-```
-
-## Asset Loading
-
-### Preloading (Recommended)
-
-Bundle assets into `.data` file at build time:
-
-```cmake
-# CMakeLists.txt
-target_link_options(MyGame PRIVATE
- "SHELL:--preload-file ${CMAKE_SOURCE_DIR}/assets@/assets"
-)
-```
-
-Access normally in code:
-
-```cpp
-Texture texture = Texture::load("/assets/player.png");
-```
-
-### Runtime Loading
-
-Load assets via HTTP at runtime:
-
-```cpp
-void onInit() override {
- // Async load
- Texture::loadAsync("https://example.com/player.png",
- [this](Texture tex) {
- playerTexture = tex;
- },
- [](const std::string& error) {
- ES_LOG_ERROR("Failed to load: {}", error);
- }
- );
-}
-```
-
-## Module Configuration
-
-### Memory
-
-```cmake
-target_link_options(MyGame PRIVATE
- "SHELL:-s INITIAL_MEMORY=64MB"
- "SHELL:-s ALLOW_MEMORY_GROWTH=1"
- "SHELL:-s MAXIMUM_MEMORY=256MB"
-)
-```
-
-### WebGL
-
-```cmake
-target_link_options(MyGame PRIVATE
- "SHELL:-s USE_WEBGL2=1" # WebGL 2.0
- "SHELL:-s MIN_WEBGL_VERSION=2"
- "SHELL:-s MAX_WEBGL_VERSION=2"
-)
-```
-
-### Optimizations
-
-<Tabs>
- <TabItem label="Release">
- ```cmake
- target_link_options(MyGame PRIVATE
- "SHELL:-O3"
- "SHELL:-flto"
- "SHELL:-s ASSERTIONS=0"
- "SHELL:--closure 1"
- )
- ```
- </TabItem>
- <TabItem label="Debug">
- ```cmake
- target_link_options(MyGame PRIVATE
- "SHELL:-O0"
- "SHELL:-g"
- "SHELL:-s ASSERTIONS=2"
- "SHELL:-s SAFE_HEAP=1"
- )
- ```
- </TabItem>
-</Tabs>
-
-## Browser APIs
-
-### Local Storage
-
-```cpp
-#include <emscripten.h>
-
-void saveGame(const std::string& data) {
- EM_ASM({
- localStorage.setItem('savedata', UTF8ToString($0));
- }, data.c_str());
-}
-
-std::string loadGame() {
- char* result = (char*)EM_ASM_PTR({
- var data = localStorage.getItem('savedata') || '';
- var len = lengthBytesUTF8(data) + 1;
- var buf = _malloc(len);
- stringToUTF8(data, buf, len);
- return buf;
- });
- std::string data(result);
- free(result);
- return data;
-}
-```
-
-### Fullscreen
-
-```cpp
-void toggleFullscreen() {
- EM_ASM({
- if (!document.fullscreenElement) {
- Module.canvas.requestFullscreen();
- } else {
- document.exitFullscreen();
- }
- });
-}
-```
-
-## Deployment
-
-### GitHub Pages
-
-<Steps>
-
-1. Build with correct base path
- ```bash
- emcmake cmake -B build_web -DES_BUILD_WEB=ON
- cmake --build build_web
- ```
-
-2. Copy to `docs/` or `gh-pages` branch
- ```bash
- cp build_web/MyGame.* docs/
- ```
-
-3. Enable GitHub Pages in repository settings
-
-</Steps>
-
-### itch.io
-
-1. Zip the build output files
-2. Upload to itch.io as HTML5 game
-3. Set viewport size in itch.io dashboard
-
-### Cloudflare Pages / Vercel
-
-Just point to your build output directory. Both platforms serve static files directly.
-
-## Performance Tips
-
-<Aside type="tip">
- - Use `-O3` and `--closure 1` for production
- - Compress `.wasm` with gzip/brotli on server
- - Keep `.data` file small (compress textures)
- - Use WebGL 2.0 for better performance
-</Aside>
-
-## Troubleshooting
-
-| Issue | Solution |
-|-------|----------|
-| Blank screen | Check browser console for errors |
-| Memory error | Increase `INITIAL_MEMORY` |
-| Slow loading | Enable compression on server |
-| Touch not working | Ensure canvas has `tabindex="0"` |
diff --git a/docs/astro/src/content/docs/platforms/wechat.mdx b/docs/astro/src/content/docs/platforms/wechat.mdx
deleted file mode 100644
index f371200d3..000000000
--- a/docs/astro/src/content/docs/platforms/wechat.mdx
+++ /dev/null
@@ -1,251 +0,0 @@
----
-title: WeChat MiniGame
-description: Building and deploying ESEngine games for WeChat MiniGames
----
-
-import { Steps, Aside } from '@astrojs/starlight/components';
-
-This guide covers building ESEngine games for the WeChat MiniGame platform.
-
-## Overview
-
-WeChat MiniGames are games that run inside the WeChat app without installation. They use a custom JavaScript runtime with WebGL support.
-
-<Aside>
- WeChat MiniGames have specific requirements and limitations compared to web browsers. This guide covers the key differences.
-</Aside>
-
-## Build Configuration
-
-```bash
-emcmake cmake -B build_wxgame \
- -DES_BUILD_WXGAME=ON \
- -DCMAKE_BUILD_TYPE=Release
-
-cmake --build build_wxgame
-```
-
-### Output Structure
-
-```
-build_wxgame/
-├── game.js # Entry point
-├── game.wasm # WebAssembly binary
-├── esengine.js # Engine glue code
-├── game.json # MiniGame config
-└── assets/ # Game assets
-```
-
-## Project Setup
-
-### game.json
-
-```json
-{
- "deviceOrientation": "portrait",
- "showStatusBar": false,
- "networkTimeout": {
- "request": 10000,
- "connectSocket": 10000,
- "uploadFile": 10000,
- "downloadFile": 10000
- },
- "subpackages": []
-}
-```
-
-### project.config.json
-
-```json
-{
- "appid": "your-app-id",
- "projectname": "MyGame",
- "compileType": "game",
- "setting": {
- "es6": false,
- "minified": true
- }
-}
-```
-
-## WeChat-Specific APIs
-
-### User Info
-
-```cpp
-#ifdef ES_PLATFORM_WXGAME
-void getUserInfo() {
- EM_ASM({
- wx.getUserInfo({
- success: function(res) {
- // res.userInfo contains nickname, avatar, etc.
- Module._onUserInfo(
- allocateUTF8(res.userInfo.nickName),
- allocateUTF8(res.userInfo.avatarUrl)
- );
- }
- });
- });
-}
-
-extern "C" void EMSCRIPTEN_KEEPALIVE onUserInfo(char* name, char* avatar) {
- std::string nickname(name);
- std::string avatarUrl(avatar);
- free(name);
- free(avatar);
- // Use the user info...
-}
-#endif
-```
-
-### Share
-
-```cpp
-void shareGame(const std::string& title, const std::string& imageUrl) {
- EM_ASM({
- wx.shareAppMessage({
- title: UTF8ToString($0),
- imageUrl: UTF8ToString($1)
- });
- }, title.c_str(), imageUrl.c_str());
-}
-```
-
-### Leaderboard
-
-```cpp
-void submitScore(int score) {
- EM_ASM({
- wx.setUserCloudStorage({
- KVDataList: [{
- key: 'score',
- value: String($0)
- }]
- });
- }, score);
-}
-```
-
-### Ads (Rewarded Video)
-
-```cpp
-void showRewardedAd(std::function<void(bool)> callback) {
- static std::function<void(bool)> s_callback;
- s_callback = callback;
-
- EM_ASM({
- var ad = wx.createRewardedVideoAd({ adUnitId: 'your-ad-unit-id' });
- ad.show().then(function() {
- ad.onClose(function(res) {
- Module._onAdComplete(res && res.isEnded ? 1 : 0);
- });
- }).catch(function() {
- Module._onAdComplete(0);
- });
- });
-}
-
-extern "C" void EMSCRIPTEN_KEEPALIVE onAdComplete(int rewarded) {
- s_callback(rewarded != 0);
-}
-```
-
-## Platform Differences
-
-| Feature | Web | WeChat |
-|---------|-----|--------|
-| File System | Limited | wx.getFileSystemManager |
-| Storage | localStorage | wx.setStorage |
-| Audio | Web Audio API | wx.createInnerAudioContext |
-| HTTP | fetch/XHR | wx.request |
-| WebSocket | WebSocket API | wx.connectSocket |
-
-## Asset Management
-
-### File Size Limits
-
-- Main package: 4MB max
-- Subpackages: 2MB each, 20MB total
-- Remote assets: No limit
-
-### Using Subpackages
-
-```json
-// game.json
-{
- "subpackages": [
- {
- "name": "level1",
- "root": "levels/level1/"
- },
- {
- "name": "level2",
- "root": "levels/level2/"
- }
- ]
-}
-```
-
-```cpp
-void loadSubpackage(const std::string& name) {
- EM_ASM({
- wx.loadSubpackage({
- name: UTF8ToString($0),
- success: function() {
- Module._onSubpackageLoaded(1);
- },
- fail: function() {
- Module._onSubpackageLoaded(0);
- }
- });
- }, name.c_str());
-}
-```
-
-## Testing & Debugging
-
-<Steps>
-
-1. **Install WeChat DevTools**
-
- Download from [WeChat MiniProgram docs](https://developers.weixin.qq.com/miniprogram/dev/devtools/download.html)
-
-2. **Open your project**
-
- Point DevTools to your `build_wxgame` directory
-
-3. **Test on device**
-
- Use "Preview" to generate QR code, scan with WeChat
-
-4. **Debug**
-
- Use the built-in debugger, similar to Chrome DevTools
-
-</Steps>
-
-## Submission Checklist
-
-Before submitting to WeChat:
-
-- [ ] Test on real devices (iOS and Android)
-- [ ] Check memory usage (< 1GB recommended)
-- [ ] Verify all assets load correctly
-- [ ] Test offline behavior
-- [ ] Add privacy policy
-- [ ] Prepare screenshots and description
-- [ ] Test ads if using monetization
-
-## Common Issues
-
-| Issue | Solution |
-|-------|----------|
-| "Game too large" | Use subpackages or remote assets |
-| Black screen | Check WebGL context creation |
-| Touch unresponsive | Ensure proper event handling |
-| Memory warning | Reduce texture sizes, unload unused assets |
-| "Invalid domain" | Add domain to whitelist in settings |
-
-<Aside type="caution">
- WeChat updates frequently. Always test with the latest DevTools and on real devices before submission.
-</Aside>
diff --git a/docs/astro/src/content/docs/zh/core-concepts/components.mdx b/docs/astro/src/content/docs/zh/core-concepts/components.mdx
new file mode 100644
index 000000000..765bc6128
--- /dev/null
+++ b/docs/astro/src/content/docs/zh/core-concepts/components.mdx
@@ -0,0 +1,189 @@
+---
+title: 组件
+description: ESEngine 中的内置和自定义组件
+---
+
+import { Aside } from '@astrojs/starlight/components';
+
+组件是附加在实体上的数据。在 ESEngine 中,你在代码中**定义**组件,然后在场景编辑器中**挂载**到实体上。
+
+## 内置组件
+
+内置组件在编辑器中始终可用,由 C++ 后端支持。
+
+### LocalTransform
+
+实体的位置、旋转和缩放。
+
+| 属性 | 类型 | 说明 |
+|------|------|------|
+| `position` | Vec3 | 世界坐标 `{ x, y, z }` |
+| `rotation` | Quat | 四元数 `{ w, x, y, z }` |
+| `scale` | Vec3 | 缩放因子 `{ x, y, z }` |
+
+### Sprite
+
+2D 精灵渲染。需要 `LocalTransform` 才能显示。详见[精灵指南](/microes/zh/guides/sprite/)。
+
+### Camera
+
+视图设置。至少需要一个激活的相机才能看到内容。编辑器的默认场景已包含一个。
+
+| 属性 | 类型 | 说明 |
+|------|------|------|
+| `projectionType` | number | 0 = 透视,1 = 正交 |
+| `fov` | number | 视角角度(仅透视) |
+| `orthoSize` | number | 半高世界单位(仅正交) |
+| `nearPlane` | number | 近裁剪面 |
+| `farPlane` | number | 远裁剪面 |
+| `isActive` | boolean | 是否用于渲染 |
+| `priority` | number | 高优先级相机优先 |
+
+### Canvas
+
+渲染表面的显示设置。
+
+| 属性 | 类型 | 说明 |
+|------|------|------|
+| `designResolution` | Vec2 | 设计分辨率 `{ x, y }` |
+| `pixelsPerUnit` | number | 每世界单位像素数 |
+| `scaleMode` | number | 画布缩放模式 |
+| `matchWidthOrHeight` | number | 宽高匹配平衡 |
+| `backgroundColor` | Vec4 | 清屏颜色 RGBA |
+
+### Velocity
+
+运动速度。
+
+| 属性 | 类型 | 说明 |
+|------|------|------|
+| `linear` | Vec3 | 线速度 |
+| `angular` | Vec3 | 角速度 |
+
+### Parent / Children
+
+场景图的实体层级关系。
+
+| 组件 | 属性 | 类型 | 说明 |
+|------|------|------|------|
+| `Parent` | `entity` | Entity | 父实体 ID |
+| `Children` | `entities` | Entity[] | 子实体 ID 列表 |
+
+### SpineAnimation
+
+Spine 骨骼动画播放。需要 `LocalTransform`。详见 [Spine 动画指南](/microes/zh/guides/spine/)。
+
+### Text
+
+UI 文本渲染。配合 `UIRect` 和 `Sprite` 组件显示文本。详见 [UI 与文本指南](/microes/zh/guides/ui/)。
+
+| 属性 | 类型 | 说明 |
+|------|------|------|
+| `content` | string | 文本内容 |
+| `fontFamily` | string | 字体名称 |
+| `fontSize` | number | 字号(像素) |
+| `color` | Vec4 | 文本颜色 RGBA |
+| `align` | TextAlign | 水平对齐方式 |
+| `verticalAlign` | TextVerticalAlign | 垂直对齐方式 |
+
+### UIRect
+
+UI 布局矩形。定义 UI 元素的尺寸、锚点和旋转中心。
+
+| 属性 | 类型 | 说明 |
+|------|------|------|
+| `size` | Vec2 | 宽高 |
+| `anchor` | Vec2 | 锚点(0–1) |
+| `pivot` | Vec2 | 旋转中心点 |
+
+## 自定义组件
+
+### defineComponent
+
+在代码中定义数据组件。保存后会出现在编辑器的"添加组件"菜单中。
+
+```typescript
+import { defineComponent } from 'esengine';
+
+export const Health = defineComponent('Health', {
+ current: 100,
+ max: 100
+});
+```
+
+在编辑器中:选择实体 → 添加组件 → Health → 在检查器中设置值。
+
+系统查询拥有该组件的实体:
+
+```typescript
+import { defineSystem, addSystem, Query } from 'esengine';
+import { Health } from './components/Health';
+
+addSystem(defineSystem(
+ [Query(Health)],
+ (query) => {
+ for (const [entity, health] of query) {
+ if (health.current <= 0) {
+ // 处理死亡
+ }
+ }
+ }
+));
+```
+
+### defineTag
+
+标签组件没有数据 — 纯粹用于筛选实体。
+
+```typescript
+import { defineTag } from 'esengine';
+
+export const Player = defineTag('Player');
+export const Enemy = defineTag('Enemy');
+```
+
+在编辑器中将 `Player` 挂载到实体上,然后查询它:
+
+```typescript
+addSystem(defineSystem(
+ [Query(LocalTransform, Player)],
+ (query) => {
+ for (const [entity, transform] of query) {
+ // 只处理带有 Player 标签的实体
+ }
+ }
+));
+```
+
+<Aside type="caution">
+ 自定义组件仅存储在 TypeScript 中。内置组件与 C++ 后端同步用于渲染。
+</Aside>
+
+## 运行时创建实体
+
+需要在运行时创建实体时(如子弹、粒子、特效),使用 `Commands`:
+
+```typescript
+import { addStartupSystem, defineSystem, Commands, Sprite, LocalTransform } from 'esengine';
+
+addStartupSystem(defineSystem(
+ [Commands()],
+ (cmds) => {
+ const entity = cmds.spawn()
+ .insert(Sprite, { size: { x: 10, y: 10 } })
+ .insert(LocalTransform, { position: { x: 0, y: 0, z: 0 } })
+ .id();
+ }
+));
+```
+
+### 运行时移除组件
+
+```typescript
+cmds.entity(entity).remove(Velocity);
+```
+
+## 下一步
+
+- [系统](/microes/zh/core-concepts/systems/) — 操作组件的逻辑
+- [查询](/microes/zh/core-concepts/queries/) — 按组件查找实体
diff --git a/docs/astro/src/content/docs/zh/core-concepts/ecs.mdx b/docs/astro/src/content/docs/zh/core-concepts/ecs.mdx
new file mode 100644
index 000000000..c559f504b
--- /dev/null
+++ b/docs/astro/src/content/docs/zh/core-concepts/ecs.mdx
@@ -0,0 +1,141 @@
+---
+title: ECS 架构
+description: 理解 ESEngine 中的实体-组件-系统模式
+---
+
+import { Aside } from '@astrojs/starlight/components';
+
+ESEngine 使用实体-组件-系统(ECS)架构管理游戏对象。ECS 将**身份**(Entity)、**数据**(Component)和**行为**(System)分离。
+
+## 什么是 ECS?
+
+| 概念 | 角色 | 示例 |
+|------|------|------|
+| **实体 (Entity)** | 唯一标识符(只是一个数字) | 玩家、敌人、子弹 |
+| **组件 (Component)** | 附加在实体上的数据 | LocalTransform、Sprite、Health |
+| **系统 (System)** | 操作具有特定组件的实体的逻辑 | 移动系统、渲染系统 |
+
+<Aside type="tip">
+ ECS 倡导**组合优于继承**。不需要深层类继承结构,而是通过组合小型、可复用的组件来构建游戏对象。
+</Aside>
+
+## 为什么选择 ECS?
+
+传统 OOP 方式:
+
+```
+GameObject
+├── Player extends GameObject
+│ ├── FlyingPlayer extends Player
+│ └── SwimmingPlayer extends Player
+└── Enemy extends GameObject
+ └── FlyingEnemy extends Enemy
+```
+
+ECS 方式 — 自由组合行为:
+
+```
+Player = Entity + LocalTransform + Sprite + Health + PlayerInput
+Enemy = Entity + LocalTransform + Sprite + Health + AI
+Bullet = Entity + LocalTransform + Sprite + Velocity + Damage
+```
+
+优势:
+
+- **组合** — 自由搭配组件,无需僵化的继承层级
+- **数据局部性** — 同类型组件连续存储,提升缓存性能
+- **关注点分离** — 系统包含逻辑,组件持有数据
+- **灵活性** — 运行时添加或移除组件来改变行为
+
+## 实体
+
+实体只是一个数字(ID)。在 ESEngine 中,实体通常在**场景编辑器**中创建 — 可视化地放置、添加组件、配置属性。
+
+运行时也可以通过 `Commands` 创建实体(如子弹、粒子):
+
+```typescript
+import { defineSystem, addStartupSystem, Commands, type Entity } from 'esengine';
+
+addStartupSystem(defineSystem([Commands()], (cmds) => {
+ const bullet: Entity = cmds.spawn().id();
+ cmds.despawn(bullet);
+}));
+```
+
+## 组件
+
+组件是附加在实体上的数据。在代码中**定义**组件,然后在场景编辑器中**挂载**到实体上。
+
+- **内置组件** — LocalTransform、Sprite、Camera 等(编辑器中始终可用)
+- **自定义组件** — 用 `defineComponent` / `defineTag` 定义(保存后出现在编辑器中)
+
+```typescript
+import { defineComponent, defineTag } from 'esengine';
+
+const Health = defineComponent('Health', { current: 100, max: 100 });
+const Player = defineTag('Player');
+```
+
+定义后,在编辑器中选择实体 → 添加组件 → 从菜单中选择 `Health` 或 `Player`。
+
+详见[组件](/microes/zh/core-concepts/components/)。
+
+## 系统
+
+系统是查询具有特定组件的实体并操作它们的函数。它们自动运行在场景中所有匹配的实体上。
+
+```typescript
+import { defineSystem, addSystem, Res, Time, Query, Mut, LocalTransform } from 'esengine';
+import { Health } from './components';
+
+addSystem(defineSystem(
+ [Res(Time), Query(Mut(LocalTransform), Health)],
+ (time, query) => {
+ for (const [entity, transform, health] of query) {
+ if (health.current <= 0) {
+ transform.position.y -= 100 * time.delta;
+ }
+ }
+ }
+));
+```
+
+详见[系统](/microes/zh/core-concepts/systems/)。
+
+## ECS 流程
+
+```
+ ┌──────────────────────┐
+ │ 编辑器:场景搭建 │ 放置实体,挂载组件
+ └──────────┬───────────┘
+ ▼
+ ┌──────────────────────┐
+ │ 脚本:定义 │ defineComponent + defineSystem + addSystem
+ └──────────┬───────────┘
+ ▼
+ ┌──────────┐
+ │ 启动 │ 启动系统运行一次
+ └────┬─────┘
+ ▼
+ ┌──────────┐
+ │ 更新 │◄─┐ 系统每帧查询场景中的实体
+ └────┬─────┘ │
+ ▼ │
+ ┌──────────┐ │
+ │ 渲染 │ │ C++ 后端绘制所有 Sprite/Camera
+ └────┬─────┘ │
+ └────────┘
+```
+
+1. **场景搭建** — 在编辑器中放置实体并挂载组件
+2. **脚本** — 定义自定义组件并注册系统
+3. **启动** — 启动系统运行一次
+4. **更新循环** — 系统每帧查询和处理场景中的实体
+5. **渲染** — C++ 后端自动渲染所有拥有 `Sprite` 和 `Camera` 组件的实体
+
+## 下一步
+
+- [组件](/microes/zh/core-concepts/components/) — 内置和自定义组件
+- [系统](/microes/zh/core-concepts/systems/) — 定义和调度系统
+- [查询](/microes/zh/core-concepts/queries/) — 查询实体
+- [资源](/microes/zh/core-concepts/resources/) — 全局单例数据
diff --git a/docs/astro/src/content/docs/zh/core-concepts/queries.mdx b/docs/astro/src/content/docs/zh/core-concepts/queries.mdx
new file mode 100644
index 000000000..0a6c3c98f
--- /dev/null
+++ b/docs/astro/src/content/docs/zh/core-concepts/queries.mdx
@@ -0,0 +1,153 @@
+---
+title: 查询
+description: 在 ESEngine 中按组件查询实体
+---
+
+查询让你遍历具有特定组件的实体,是系统访问场景中实体数据的主要方式。
+
+## 基本查询
+
+查询匹配场景中所有拥有**全部**列出组件的实体:
+
+```typescript
+import { defineSystem, addSystem, Query, Mut, LocalTransform, Sprite } from 'esengine';
+
+addSystem(defineSystem([Query(Mut(LocalTransform), Sprite)], (query) => {
+ for (const [entity, transform, sprite] of query) {
+ transform.position.x += 1;
+ }
+}));
+```
+
+`for...of` 循环按查询参数的顺序返回 `[entity, ...components]` 元组。
+
+## 可变查询
+
+默认情况下,查询结果是只读的。使用 `Mut()` 获取特定组件的可变访问:
+
+```typescript
+import { Query, Mut, LocalTransform, Sprite } from 'esengine';
+
+defineSystem(
+ [Query(Mut(LocalTransform), Sprite)],
+ (query) => {
+ for (const [entity, transform, sprite] of query) {
+ transform.position.x += 1; // 可写
+ // sprite 是只读的
+ }
+ }
+);
+```
+
+## 迭代方式
+
+### for...of
+
+```typescript
+for (const [entity, transform, sprite] of query) {
+ transform.position.x += 1;
+}
+```
+
+### forEach
+
+```typescript
+query.forEach((entity, transform, sprite) => {
+ transform.position.x += 1;
+});
+```
+
+### single
+
+获取唯一匹配的实体。如果有零个或多个匹配则返回 `null`。
+
+```typescript
+const result = query.single();
+if (result) {
+ const [entity, transform, sprite] = result;
+ // ...
+}
+```
+
+### 工具方法
+
+```typescript
+query.isEmpty(); // 没有实体匹配时返回 true
+query.count(); // 匹配的实体数量
+query.toArray(); // 将所有结果收集到数组中
+```
+
+## 多个查询
+
+一个系统可以有多个查询来交叉引用不同类型的实体:
+
+```typescript
+import { defineTag } from 'esengine';
+
+const Player = defineTag('Player');
+const Enemy = defineTag('Enemy');
+
+defineSystem(
+ [Query(LocalTransform, Player), Query(LocalTransform, Enemy)],
+ (players, enemies) => {
+ for (const [_, playerTransform] of players) {
+ for (const [_, enemyTransform] of enemies) {
+ // 检查玩家和每个敌人之间的距离
+ }
+ }
+ }
+);
+```
+
+## 与资源结合
+
+查询经常与资源一起使用:
+
+```typescript
+import { Res, Time, Input, Query, Mut, LocalTransform } from 'esengine';
+
+defineSystem(
+ [Res(Time), Res(Input), Query(Mut(LocalTransform), Player)],
+ (time, input, query) => {
+ for (const [entity, transform] of query) {
+ if (input.isKeyDown('KeyD')) {
+ transform.position.x += 200 * time.delta;
+ }
+ }
+ }
+);
+```
+
+## 示例:碰撞检测
+
+定义 `Hitbox`、`Player` 和 `Enemy` 组件,在场景编辑器中挂载到实体上,然后查询:
+
+```typescript
+import { defineSystem, defineComponent, defineTag, addSystem, Query, LocalTransform } from 'esengine';
+
+const Hitbox = defineComponent('Hitbox', { width: 50, height: 50 });
+const Player = defineTag('Player');
+const Enemy = defineTag('Enemy');
+
+addSystem(defineSystem(
+ [Query(LocalTransform, Hitbox, Player), Query(LocalTransform, Hitbox, Enemy)],
+ (players, enemies) => {
+ for (const [_, pPos, pBox] of players) {
+ for (const [_, ePos, eBox] of enemies) {
+ const dx = Math.abs(pPos.position.x - ePos.position.x);
+ const dy = Math.abs(pPos.position.y - ePos.position.y);
+
+ if (dx < (pBox.width + eBox.width) / 2 &&
+ dy < (pBox.height + eBox.height) / 2) {
+ // 碰撞!
+ }
+ }
+ }
+ }
+));
+```
+
+## 下一步
+
+- [资源](/microes/zh/core-concepts/resources/) — 全局单例数据如 Time 和 Input
+- [组件](/microes/zh/core-concepts/components/) — 所有内置和自定义组件类型
diff --git a/docs/astro/src/content/docs/zh/core-concepts/resources.mdx b/docs/astro/src/content/docs/zh/core-concepts/resources.mdx
new file mode 100644
index 000000000..2997a9ffb
--- /dev/null
+++ b/docs/astro/src/content/docs/zh/core-concepts/resources.mdx
@@ -0,0 +1,167 @@
+---
+title: 资源
+description: ESEngine 中的全局单例数据
+---
+
+资源是全局单例 — 在整个应用中只存在一份,不附加在任何实体上。用于共享状态如时间、输入和游戏配置。
+
+## 访问资源
+
+### Res(只读)
+
+```typescript
+import { defineSystem, Res, Time } from 'esengine';
+
+defineSystem([Res(Time)], (time) => {
+ console.log(`Delta: ${time.delta}s, Elapsed: ${time.elapsed}s`);
+});
+```
+
+### ResMut(可变)
+
+```typescript
+import { defineSystem, ResMut } from 'esengine';
+
+defineSystem([ResMut(GameState)], (state) => {
+ state.value.score += 10;
+});
+```
+
+`ResMut` 包装了资源值。用 `.value` 访问数据,或使用 `.modify()`:
+
+```typescript
+defineSystem([ResMut(GameState)], (state) => {
+ state.modify((s) => {
+ s.score += 10;
+ s.level = Math.floor(s.score / 100) + 1;
+ });
+});
+```
+
+## 内置资源
+
+### Time
+
+帧计时信息,自动可用。
+
+```typescript
+import { Res, Time } from 'esengine';
+
+defineSystem([Res(Time)], (time) => {
+ time.delta; // 距上帧的秒数
+ time.elapsed; // 总运行秒数
+ time.frameCount; // 总渲染帧数
+});
+```
+
+| 属性 | 类型 | 说明 |
+|------|------|------|
+| `delta` | number | 距上帧的秒数 |
+| `elapsed` | number | 总运行秒数 |
+| `frameCount` | number | 总渲染帧数 |
+
+### Input
+
+键盘和鼠标状态,自动可用。
+
+```typescript
+import { Res, Input } from 'esengine';
+
+defineSystem([Res(Input)], (input) => {
+ if (input.isKeyDown('Space')) {
+ // Space 被按住
+ }
+ if (input.isKeyPressed('KeyE')) {
+ // E 在这帧被按下
+ }
+});
+```
+
+| 方法 | 说明 |
+|------|------|
+| `isKeyDown(code)` | 按键当前被按住 |
+| `isKeyPressed(code)` | 按键在这帧被按下 |
+| `isKeyReleased(code)` | 按键在这帧被释放 |
+| `getMousePosition()` | 返回 `{ x, y }` |
+| `isMouseButtonDown(button)` | 鼠标按钮被按住(0=左键,2=右键) |
+
+## 自定义资源
+
+### defineResource
+
+```typescript
+import { defineResource } from 'esengine';
+
+const GameState = defineResource({
+ score: 0,
+ level: 1,
+ paused: false
+});
+```
+
+### 插入资源
+
+通过 `Commands` 在启动系统中插入资源:
+
+```typescript
+import { addStartupSystem, defineSystem, Commands } from 'esengine';
+
+addStartupSystem(defineSystem([Commands()], (cmds) => {
+ cmds.insertResource(GameState, { score: 0, level: 1, paused: false });
+}));
+```
+
+### 读取和写入
+
+```typescript
+// 只读
+defineSystem([Res(GameState)], (state) => {
+ console.log(`Score: ${state.score}`);
+});
+
+// 可变
+defineSystem([ResMut(GameState)], (state) => {
+ state.value.score += 10;
+});
+```
+
+## 示例:分数追踪
+
+定义 `Coin` 标签,在场景中挂载到金币实体上,用资源追踪分数:
+
+```typescript
+import {
+ defineSystem, defineResource, defineTag,
+ addStartupSystem, addSystem, Commands, Query, ResMut,
+ LocalTransform
+} from 'esengine';
+
+const Score = defineResource({ value: 0 });
+const Coin = defineTag('Coin');
+const Player = defineTag('Player');
+
+addStartupSystem(defineSystem([Commands()], (cmds) => {
+ cmds.insertResource(Score, { value: 0 });
+}));
+
+addSystem(defineSystem(
+ [Commands(), ResMut(Score), Query(LocalTransform, Player), Query(LocalTransform, Coin)],
+ (cmds, score, players, coins) => {
+ for (const [_, pPos] of players) {
+ for (const [coinEntity, cPos] of coins) {
+ const dx = pPos.position.x - cPos.position.x;
+ const dy = pPos.position.y - cPos.position.y;
+ if (Math.sqrt(dx * dx + dy * dy) < 30) {
+ cmds.despawn(coinEntity);
+ score.value.value += 1;
+ }
+ }
+ }
+ }
+));
+```
+
+## 下一步
+
+- [系统](/microes/zh/core-concepts/systems/) — 系统如何使用资源和查询
+- [组件](/microes/zh/core-concepts/components/) — 附加在实体上的数据
diff --git a/docs/astro/src/content/docs/zh/core-concepts/systems.mdx b/docs/astro/src/content/docs/zh/core-concepts/systems.mdx
new file mode 100644
index 000000000..b3664b591
--- /dev/null
+++ b/docs/astro/src/content/docs/zh/core-concepts/systems.mdx
@@ -0,0 +1,157 @@
+---
+title: 系统
+description: 在 ESEngine 中定义和调度系统
+---
+
+系统包含游戏逻辑。它们通过参数声明需要的数据,ESEngine 自动注入。系统自动操作**场景中所有匹配的实体**。
+
+## 定义系统
+
+```typescript
+import { defineSystem, Res, Time, Query, Mut, LocalTransform, Velocity } from 'esengine';
+
+const movementSystem = defineSystem(
+ [Res(Time), Query(Mut(LocalTransform), Velocity)],
+ (time, query) => {
+ for (const [entity, transform, velocity] of query) {
+ transform.position.x += velocity.linear.x * time.delta;
+ transform.position.y += velocity.linear.y * time.delta;
+ }
+ }
+);
+```
+
+此系统自动处理场景中所有同时拥有 `LocalTransform` 和 `Velocity` 组件的实体。
+
+`defineSystem` 接受两个参数:
+
+1. **参数列表** — `Query`、`Res`、`ResMut` 或 `Commands` 描述符的数组
+2. **函数** — 按相同顺序接收解析后的参数
+
+## 注册系统
+
+使用顶层函数注册系统:
+
+```typescript
+import { addSystem, addStartupSystem, addSystemToSchedule, Schedule } from 'esengine';
+
+addStartupSystem(setupSystem); // Schedule.Startup
+addSystem(movementSystem); // Schedule.Update
+addSystemToSchedule(Schedule.FixedUpdate, physicsSystem);
+```
+
+### Schedule 类型
+
+| Schedule | 运行时机 |
+|----------|----------|
+| `Startup` | 启动时运行一次 |
+| `First` | 每帧最先运行 |
+| `PreUpdate` | 每帧 Update 之前 |
+| `Update` | 每帧运行(主要游戏逻辑) |
+| `PostUpdate` | 每帧 Update 之后 |
+| `Last` | 每帧最后运行 |
+| `FixedPreUpdate` | 固定间隔,FixedUpdate 之前 |
+| `FixedUpdate` | 固定间隔(物理) |
+| `FixedPostUpdate` | 固定间隔,FixedUpdate 之后 |
+
+## 系统参数
+
+### Commands
+
+在运行时创建和销毁实体:
+
+```typescript
+import { Commands } from 'esengine';
+
+defineSystem([Commands()], (cmds) => {
+ cmds.spawn()
+ .insert(Sprite, { size: { x: 50, y: 50 } })
+ .insert(LocalTransform, { position: { x: 0, y: 0, z: 0 } });
+
+ cmds.despawn(entity);
+});
+```
+
+### Query
+
+遍历具有特定组件的实体:
+
+```typescript
+import { Query, Mut, LocalTransform, Sprite } from 'esengine';
+
+defineSystem([Query(Mut(LocalTransform), Sprite)], (query) => {
+ for (const [entity, transform, sprite] of query) {
+ transform.position.x += 1;
+ }
+});
+```
+
+详见[查询](/microes/zh/core-concepts/queries/)。
+
+### Res(只读资源)
+
+```typescript
+import { Res, Time } from 'esengine';
+
+defineSystem([Res(Time)], (time) => {
+ console.log(`Delta: ${time.delta}s`);
+});
+```
+
+### ResMut(可变资源)
+
+```typescript
+import { ResMut } from 'esengine';
+
+defineSystem([ResMut(GameState)], (state) => {
+ state.value.score += 10;
+});
+```
+
+详见[资源](/microes/zh/core-concepts/resources/)。
+
+### 组合参数
+
+```typescript
+defineSystem(
+ [Commands(), Res(Time), Res(Input), Query(Mut(LocalTransform), Velocity)],
+ (cmds, time, input, query) => {
+ // 所有参数都可用
+ }
+);
+```
+
+## 示例:玩家移动
+
+定义 `Speed` 组件,在编辑器中挂载到玩家实体上,然后编写系统:
+
+```typescript
+// src/components/Speed.ts
+import { defineComponent } from 'esengine';
+export const Speed = defineComponent('Speed', { value: 200 });
+```
+
+```typescript
+// src/systems/movement.ts
+import { defineSystem, addSystem, Res, Time, Input, Query, Mut, LocalTransform } from 'esengine';
+import { Speed } from '../components/Speed';
+
+addSystem(defineSystem(
+ [Res(Time), Res(Input), Query(Mut(LocalTransform), Speed)],
+ (time, input, query) => {
+ for (const [entity, transform, speed] of query) {
+ if (input.isKeyDown('KeyD')) {
+ transform.position.x += speed.value * time.delta;
+ }
+ if (input.isKeyDown('KeyA')) {
+ transform.position.x -= speed.value * time.delta;
+ }
+ }
+ }
+));
+```
+
+## 下一步
+
+- [查询](/microes/zh/core-concepts/queries/) — 查询过滤器和迭代方法
+- [资源](/microes/zh/core-concepts/resources/) — 全局单例数据
diff --git a/docs/astro/src/content/docs/zh/getting-started/installation.mdx b/docs/astro/src/content/docs/zh/getting-started/installation.mdx
new file mode 100644
index 000000000..7a9f9a506
--- /dev/null
+++ b/docs/astro/src/content/docs/zh/getting-started/installation.mdx
@@ -0,0 +1,62 @@
+---
+title: 安装
+description: 安装 ESEngine 编辑器并创建你的第一个项目
+---
+
+import { Steps, Aside } from '@astrojs/starlight/components';
+
+## 安装编辑器
+
+从 [releases 页面](https://github.com/esengine/microes/releases) 下载 ESEngine 编辑器并安装。
+
+## 创建项目
+
+<Steps>
+
+1. **打开编辑器**,点击 **New Project**
+
+2. **输入项目名称**,选择保存位置
+
+3. **选择模板**(Empty Project),点击 **Create**
+
+</Steps>
+
+编辑器会创建如下项目结构:
+
+```
+my-game/
+├── project.esproject # 项目配置
+├── tsconfig.json # TypeScript 配置
+├── src/ # 游戏脚本
+├── assets/
+│ ├── scenes/
+│ │ └── main.esscene # 默认场景
+│ ├── textures/
+│ └── audio/
+└── .esengine/
+ ├── settings.json # 编辑器设置
+ └── sdk/ # SDK(编辑器自动导出)
+ ├── index.js
+ ├── index.d.ts
+ └── wasm.d.ts
+```
+
+<Aside type="tip">
+ 编辑器会自动将 SDK 导出到 `.esengine/sdk/`,无需手动安装。
+</Aside>
+
+## 开发流程
+
+<Steps>
+
+1. **编辑场景** — 在编辑器中可视化地添加实体、附加组件、排列精灵
+
+2. **编写脚本** — 在 `src/` 中使用 TypeScript 定义系统、自定义组件和游戏逻辑
+
+3. **按 F5** 在浏览器中预览游戏
+
+</Steps>
+
+## 下一步
+
+项目准备好后,[创建你的第一个游戏](/microes/zh/getting-started/quick-start/)。
diff --git a/docs/astro/src/content/docs/zh/getting-started/introduction.mdx b/docs/astro/src/content/docs/zh/getting-started/introduction.mdx
new file mode 100644
index 000000000..ea888f8c7
--- /dev/null
+++ b/docs/astro/src/content/docs/zh/getting-started/introduction.mdx
@@ -0,0 +1,55 @@
+---
+title: 简介
+description: 了解 ESEngine 是什么以及为什么选择它
+---
+
+ESEngine 是一个轻量级 2D 游戏引擎,提供 **TypeScript SDK**,后端由 **C++/WebAssembly** 驱动。它附带可视化编辑器用于场景编辑和项目管理,输出可运行在 Web 浏览器和微信小游戏上的游戏。
+
+## 为什么选择 ESEngine?
+
+### 可视化编辑器 + TypeScript 脚本
+
+使用编辑器创建项目、在场景中放置实体、可视化地挂载组件。在 TypeScript 中编写游戏逻辑 — 定义自定义组件和操作场景实体的系统:
+
+```typescript
+import { defineComponent, defineSystem, addSystem, Query, Res, Time, Mut, LocalTransform } from 'esengine';
+
+const Speed = defineComponent('Speed', { value: 200 });
+
+addSystem(defineSystem(
+ [Res(Time), Query(Mut(LocalTransform), Speed)],
+ (time, query) => {
+ for (const [entity, transform, speed] of query) {
+ transform.position.x += speed.value * time.delta;
+ }
+ }
+));
+```
+
+### 高性能
+
+渲染和核心系统由 C++ 实现并编译为 WebAssembly,提供原生级别的性能,同时保持小包体和快速加载。
+
+### 跨平台
+
+一套代码同时运行在 Web 浏览器和微信小游戏,通过平台适配器实现。
+
+## 适用场景
+
+ESEngine 适合:
+
+- 面向 Web 浏览器的 2D 游戏
+- 微信小游戏
+- 需要小下载体积的项目
+- 希望使用 ECS 架构的 TypeScript 开发者
+
+ESEngine 可能不适合:
+
+- 3D 游戏(仅支持 2D)
+- 仅桌面端的游戏(建议使用原生引擎)
+
+## 下一步
+
+1. [安装编辑器](/microes/zh/getting-started/installation/)
+2. [创建你的第一个游戏](/microes/zh/getting-started/quick-start/)
+3. [了解 ECS](/microes/zh/core-concepts/ecs/)
diff --git a/docs/astro/src/content/docs/zh/getting-started/quick-start.mdx b/docs/astro/src/content/docs/zh/getting-started/quick-start.mdx
new file mode 100644
index 000000000..242fc9982
--- /dev/null
+++ b/docs/astro/src/content/docs/zh/getting-started/quick-start.mdx
@@ -0,0 +1,127 @@
+---
+title: 快速开始
+description: 几分钟内创建你的第一个 ESEngine 游戏
+---
+
+import { Steps, Aside } from '@astrojs/starlight/components';
+
+让我们创建一个显示移动精灵的简单游戏,介绍 ESEngine 的核心概念。
+
+## 创建项目
+
+<Steps>
+
+1. **打开编辑器**,点击 **New Project**
+
+2. **命名项目**(如 "my-first-game"),点击 **Create**
+
+ 编辑器会创建一个包含默认 Camera 实体的场景。
+
+3. **在编辑器中添加 Sprite 实体**
+
+ 在 Hierarchy 面板中创建新实体,添加 `LocalTransform` 和 `Sprite` 组件。设置 Sprite 尺寸为 `100 x 100`,选择一个颜色。
+
+4. **创建 `src/main.ts`**,填入以下代码:
+
+ ```typescript
+ import {
+ defineSystem,
+ addSystem,
+ Query,
+ Res,
+ Time,
+ Mut,
+ LocalTransform,
+ Sprite,
+ } from 'esengine';
+
+ addSystem(defineSystem(
+ [Res(Time), Query(Mut(LocalTransform), Sprite)],
+ (time, query) => {
+ for (const [entity, transform, sprite] of query) {
+ transform.position.x = Math.sin(time.elapsed) * 100;
+ transform.position.y = Math.cos(time.elapsed) * 100;
+ }
+ }
+ ));
+ ```
+
+5. **在编辑器中按 F5** 预览 — 精灵做圆周运动
+
+</Steps>
+
+## 理解代码
+
+### 组件在场景中挂载
+
+在 ESEngine 中,实体和组件在**场景编辑器**中创建。你的代码不创建它们 — 而是定义**系统**来查询和操作场景中的实体。
+
+第 3 步放置的精灵已经有 `LocalTransform` 和 `Sprite` 组件。第 4 步的系统通过 `Query(Mut(LocalTransform), Sprite)` 找到它并执行动画。
+
+### 自定义组件
+
+你可以在代码中定义自定义组件,然后在编辑器中挂到实体上:
+
+```typescript
+// src/components/Speed.ts
+import { defineComponent } from 'esengine';
+
+export const Speed = defineComponent('Speed', { value: 200 });
+```
+
+保存后,`Speed` 组件会出现在编辑器的"Add Component"菜单中。将它挂到实体上,然后编写查询它的系统:
+
+```typescript
+// src/systems/movement.ts
+import { defineSystem, addSystem, Res, Time, Query, Mut, LocalTransform } from 'esengine';
+import { Speed } from '../components/Speed';
+
+addSystem(defineSystem(
+ [Res(Time), Query(Mut(LocalTransform), Speed)],
+ (time, query) => {
+ for (const [entity, transform, speed] of query) {
+ transform.position.x += speed.value * time.delta;
+ }
+ }
+));
+```
+
+### 注册系统
+
+```typescript
+import { addSystem, addStartupSystem, addSystemToSchedule, Schedule } from 'esengine';
+
+addStartupSystem(system); // 启动时运行一次
+addSystem(system); // 每帧运行 (Update)
+addSystemToSchedule(Schedule.FixedUpdate, system); // 固定间隔运行
+```
+
+### Schedule 类型
+
+| Schedule | 运行时机 |
+|----------|----------|
+| `Startup` | 启动时运行一次 |
+| `Update` | 每帧运行 |
+| `PostUpdate` | 每帧 Update 之后 |
+| `FixedUpdate` | 固定时间间隔运行 |
+
+### 运行时创建实体
+
+需要在运行时创建实体时(如子弹、粒子),使用 `Commands`:
+
+```typescript
+addStartupSystem(defineSystem(
+ [Commands()],
+ (cmds) => {
+ cmds.spawn()
+ .insert(Sprite, { size: { x: 10, y: 10 } })
+ .insert(LocalTransform, { position: { x: 0, y: 0, z: 0 } });
+ }
+));
+```
+
+## 下一步
+
+- [理解 ECS 模式](/microes/zh/core-concepts/ecs/)
+- [了解组件](/microes/zh/core-concepts/components/)
+- [编写系统](/microes/zh/core-concepts/systems/)
diff --git a/docs/astro/src/content/docs/zh/guides/assets.mdx b/docs/astro/src/content/docs/zh/guides/assets.mdx
new file mode 100644
index 000000000..11fd508b8
--- /dev/null
+++ b/docs/astro/src/content/docs/zh/guides/assets.mdx
@@ -0,0 +1,171 @@
+---
+title: 资源加载
+description: 在 ESEngine 中加载纹理、Spine 数据和其他资源
+---
+
+import { Aside } from '@astrojs/starlight/components';
+
+ESEngine 提供 `Assets` 资源(`AssetServer` 实例)来加载纹理、Spine 动画、材质和通用文件。在任何系统中通过 `Res(Assets)` 访问。
+
+## 访问 Assets
+
+```typescript
+import { defineSystem, addStartupSystem, Res } from 'esengine';
+import { Assets } from 'esengine';
+
+addStartupSystem(defineSystem(
+ [Res(Assets)],
+ async (assets) => {
+ const tex = await assets.loadTexture('assets/player.png');
+ console.log(`加载完成 ${tex.width}x${tex.height},handle: ${tex.handle}`);
+ }
+));
+```
+
+## 纹理加载
+
+### loadTexture(path)
+
+加载图片并返回 `TextureInfo` 对象。图片会自动垂直翻转以适配 OpenGL UV 坐标。
+
+```typescript
+const tex = await assets.loadTexture('assets/player.png');
+sprite.texture = tex.handle;
+```
+
+**返回值:** `TextureInfo { handle: TextureHandle, width: number, height: number }`
+
+### 其他纹理方法
+
+| 方法 | 说明 |
+|------|------|
+| `getTexture(path)` | 返回已缓存的 `TextureInfo`,未加载则返回 `undefined` |
+| `hasTexture(path)` | 判断纹理是否已缓存 |
+| `releaseTexture(path)` | 从 GPU 内存和缓存中释放纹理 |
+| `releaseAll()` | 释放所有已缓存的资源 |
+
+### 九宫格元数据
+
+对于九宫格精灵,加载后设置边框元数据:
+
+```typescript
+const tex = await assets.loadTexture('assets/panel.png');
+assets.setTextureMetadata(tex.handle, {
+ left: 10, right: 10, top: 10, bottom: 10
+});
+```
+
+## Spine 加载
+
+```typescript
+const result = await assets.loadSpine('assets/hero.json', 'assets/hero.atlas');
+if (!result.success) {
+ console.error(result.error);
+}
+```
+
+`loadSpine` 自动完成以下步骤:
+1. 获取 atlas 文件并写入虚拟文件系统
+2. 解析 atlas 中的纹理文件名并逐一加载
+3. 获取骨骼文件(`.json` 或 `.skel` 二进制)并写入虚拟文件系统
+
+| 方法 | 说明 |
+|------|------|
+| `loadSpine(skeleton, atlas, baseUrl?)` | 加载 Spine 骨骼和图集 |
+| `isSpineLoaded(skeleton, atlas)` | 检查 Spine 资源对是否已加载 |
+
+## 通用文件加载
+
+| 方法 | 返回值 | 说明 |
+|------|--------|------|
+| `loadJson<T>(path, options?)` | `Promise<T>` | 加载并解析 JSON 文件 |
+| `loadText(path, options?)` | `Promise<string>` | 加载文本文件 |
+| `loadBinary(path, options?)` | `Promise<ArrayBuffer>` | 加载二进制文件 |
+
+```typescript
+const config = await assets.loadJson<GameConfig>('assets/config.json');
+const csv = await assets.loadText('assets/levels.csv');
+const data = await assets.loadBinary('assets/tilemap.bin');
+```
+
+### FileLoadOptions
+
+| 选项 | 类型 | 说明 |
+|------|------|------|
+| `baseUrl` | string | 覆盖此请求的基础 URL |
+| `noCache` | boolean | 跳过缓存,始终从网络获取 |
+
+## 批量加载
+
+使用 `loadAll` 并行加载多种资源:
+
+```typescript
+const bundle = await assets.loadAll({
+ textures: ['assets/bg.png', 'assets/player.png'],
+ spine: [{ skeleton: 'assets/hero.json', atlas: 'assets/hero.atlas' }],
+ json: ['assets/config.json'],
+});
+
+// 从 bundle 中访问已加载的资源
+const bgTex = bundle.textures.get('assets/bg.png');
+const config = bundle.json.get('assets/config.json');
+```
+
+### AssetManifest
+
+| 字段 | 类型 | 说明 |
+|------|------|------|
+| `textures` | string[] | 纹理图片路径 |
+| `materials` | string[] | 材质文件路径(.material) |
+| `spine` | SpineDescriptor[] | Spine 骨骼/图集对 |
+| `json` | string[] | JSON 文件路径 |
+| `text` | string[] | 文本文件路径 |
+| `binary` | string[] | 二进制文件路径 |
+
+### AssetBundle
+
+返回的 `AssetBundle` 包含以路径为键的 Map:
+
+| 字段 | 类型 |
+|------|------|
+| `textures` | `Map<string, TextureInfo>` |
+| `materials` | `Map<string, LoadedMaterial>` |
+| `spine` | `Map<string, SpineLoadResult>` |
+| `json` | `Map<string, unknown>` |
+| `text` | `Map<string, string>` |
+| `binary` | `Map<string, ArrayBuffer>` |
+
+## 材质加载
+
+```typescript
+const loaded = await assets.loadMaterial('assets/effects/glow.material');
+sprite.material = loaded.handle;
+```
+
+详见[材质与着色器](/microes/zh/guides/materials/)了解完整的材质 API 和 `.material` 文件格式。
+
+## 缓存机制
+
+所有加载方法按路径缓存。同一路径加载两次会直接返回缓存结果,不会再次发起网络请求。使用 `noCache` 选项跳过缓存:
+
+```typescript
+const fresh = await assets.loadJson('assets/config.json', { noCache: true });
+```
+
+## 基础 URL
+
+设置 `assets.baseUrl` 为所有相对路径添加前缀:
+
+```typescript
+assets.baseUrl = 'https://cdn.example.com/game';
+const tex = await assets.loadTexture('sprites/player.png');
+// 请求 https://cdn.example.com/game/sprites/player.png
+```
+
+绝对路径和完整 URL 不受 `baseUrl` 影响。
+
+## 下一步
+
+- [材质与着色器](/microes/zh/guides/materials/) — 自定义着色器和混合模式
+- [精灵](/microes/zh/guides/sprite/) — 纹理与精灵的使用
+- [Spine 动画](/microes/zh/guides/spine/) — Spine 骨骼动画
diff --git a/docs/astro/src/content/docs/zh/guides/input.mdx b/docs/astro/src/content/docs/zh/guides/input.mdx
new file mode 100644
index 000000000..558f22bd2
--- /dev/null
+++ b/docs/astro/src/content/docs/zh/guides/input.mdx
@@ -0,0 +1,150 @@
+---
+title: 输入处理
+description: ESEngine 中的键盘、鼠标和触摸输入
+---
+
+import { Aside } from '@astrojs/starlight/components';
+
+ESEngine 通过 `Input` 资源提供输入处理。
+
+## 在系统中使用输入
+
+通过 `Res(Input)` 系统参数访问输入状态:
+
+```typescript
+import { defineSystem, addSystem, Res, Input, Query, Mut, LocalTransform } from 'esengine';
+
+addSystem(defineSystem(
+ [Res(Input), Query(Mut(LocalTransform))],
+ (input, query) => {
+ for (const [entity, transform] of query) {
+ if (input.isKeyDown('KeyW')) {
+ transform.position.y -= 5;
+ }
+ if (input.isKeyDown('KeyS')) {
+ transform.position.y += 5;
+ }
+ if (input.isKeyDown('KeyA')) {
+ transform.position.x -= 5;
+ }
+ if (input.isKeyDown('KeyD')) {
+ transform.position.x += 5;
+ }
+ }
+ }
+));
+```
+
+## 键盘输入
+
+### 按键状态
+
+```typescript
+if (input.isKeyDown('Space')) {
+ // Space 当前被按住
+}
+
+if (input.isKeyPressed('Space')) {
+ // Space 在这帧刚被按下
+}
+
+if (input.isKeyReleased('Space')) {
+ // Space 在这帧刚被释放
+}
+```
+
+### 按键码
+
+使用标准 DOM 按键码:
+
+```typescript
+// 字母
+'KeyA', 'KeyB', ... 'KeyZ'
+
+// 数字
+'Digit0', 'Digit1', ... 'Digit9'
+
+// 特殊键
+'Space', 'Enter', 'Escape', 'Tab'
+'ShiftLeft', 'ShiftRight', 'ControlLeft', 'ControlRight'
+
+// 方向键
+'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'
+
+// 功能键
+'F1', 'F2', ... 'F12'
+```
+
+## 鼠标输入
+
+```typescript
+const mousePos = input.getMousePosition();
+console.log(`鼠标位置: ${mousePos.x}, ${mousePos.y}`);
+
+if (input.isMouseButtonDown(0)) { // 左键
+ // 处理点击
+}
+if (input.isMouseButtonDown(2)) { // 右键
+ // 处理右键点击
+}
+```
+
+## 触摸输入
+
+触摸输入与鼠标输入统一处理,实现跨平台支持:
+
+```typescript
+if (input.isMouseButtonDown(0)) {
+ const pos = input.getMousePosition();
+ handleTap(pos.x, pos.y);
+}
+```
+
+<Aside type="tip">
+ 设计输入处理时应同时兼容鼠标和触摸。Input 资源提供了统一的接口。
+</Aside>
+
+## 示例:玩家移动
+
+定义 `Player` 和 `MoveSpeed` 组件,在场景编辑器中挂载到实体上,然后编写移动系统:
+
+```typescript
+import {
+ defineSystem, defineComponent, defineTag, addSystem,
+ Res, Input, Time, Query, Mut, LocalTransform
+} from 'esengine';
+
+const Player = defineTag('Player');
+const MoveSpeed = defineComponent('MoveSpeed', { value: 200 });
+
+addSystem(defineSystem(
+ [Res(Input), Res(Time), Query(Mut(LocalTransform), MoveSpeed, Player)],
+ (input, time, query) => {
+ for (const [entity, transform, speed] of query) {
+ const velocity = { x: 0, y: 0 };
+
+ if (input.isKeyDown('KeyW') || input.isKeyDown('ArrowUp')) {
+ velocity.y = -1;
+ }
+ if (input.isKeyDown('KeyS') || input.isKeyDown('ArrowDown')) {
+ velocity.y = 1;
+ }
+ if (input.isKeyDown('KeyA') || input.isKeyDown('ArrowLeft')) {
+ velocity.x = -1;
+ }
+ if (input.isKeyDown('KeyD') || input.isKeyDown('ArrowRight')) {
+ velocity.x = 1;
+ }
+
+ const len = Math.sqrt(velocity.x * velocity.x + velocity.y * velocity.y);
+ if (len > 0) {
+ velocity.x /= len;
+ velocity.y /= len;
+ }
+
+ transform.position.x += velocity.x * speed.value * time.delta;
+ transform.position.y += velocity.y * speed.value * time.delta;
+ }
+ }
+));
+```
diff --git a/docs/astro/src/content/docs/zh/guides/materials.mdx b/docs/astro/src/content/docs/zh/guides/materials.mdx
new file mode 100644
index 000000000..ebc97efdd
--- /dev/null
+++ b/docs/astro/src/content/docs/zh/guides/materials.mdx
@@ -0,0 +1,265 @@
+---
+title: 材质与着色器
+description: ESEngine 中的自定义着色器、混合模式和材质管理
+---
+
+import { Aside } from '@astrojs/starlight/components';
+
+`Material` API 管理自定义着色器和渲染效果。通过 `Sprite` 或 `SpineAnimation` 组件的 `material` 字段赋值材质。
+
+## 创建着色器
+
+```typescript
+import { Material } from 'esengine';
+
+const shader = Material.createShader(vertexSrc, fragmentSrc);
+```
+
+返回 `ShaderHandle`(number 类型),返回 `0` 表示创建失败。
+
+### 内置顶点属性
+
+所有着色器共享固定的顶点属性位置:
+
+| Location | 名称 | 类型 | 说明 |
+|----------|------|------|------|
+| 0 | `a_position` | vec3 | 顶点位置 |
+| 1 | `a_color` | vec4 | 顶点颜色 |
+| 2 | `a_texCoord` | vec2 | 纹理坐标 |
+
+### 内置着色器源码
+
+`ShaderSources` 提供默认的精灵和颜色着色器作为参考:
+
+| 常量 | 说明 |
+|------|------|
+| `ShaderSources.SPRITE_VERTEX` | 默认精灵顶点着色器 |
+| `ShaderSources.SPRITE_FRAGMENT` | 默认精灵片段着色器 |
+| `ShaderSources.COLOR_VERTEX` | 无纹理几何体的顶点着色器 |
+| `ShaderSources.COLOR_FRAGMENT` | 无纹理几何体的片段着色器 |
+
+## 创建材质
+
+```typescript
+import { Material, BlendMode } from 'esengine';
+
+const mat = Material.create({
+ shader,
+ uniforms: {
+ u_time: 0,
+ u_tint: { x: 1, y: 0, z: 0, w: 1 },
+ },
+ blendMode: BlendMode.Additive,
+});
+
+sprite.material = mat;
+```
+
+### MaterialOptions
+
+| 字段 | 类型 | 默认值 | 说明 |
+|------|------|--------|------|
+| `shader` | ShaderHandle | — | 必需。使用的着色器 |
+| `uniforms` | Record&lt;string, UniformValue&gt; | `{}` | 初始 uniform 值 |
+| `blendMode` | BlendMode | `Normal` | 混合模式 |
+| `depthTest` | boolean | `false` | 启用深度测试 |
+
+## Uniform
+
+### 设置和获取
+
+```typescript
+Material.setUniform(mat, 'u_time', elapsed);
+Material.setUniform(mat, 'u_tint', { x: 1, y: 0.5, z: 0, w: 1 });
+
+const time = Material.getUniform(mat, 'u_time');
+```
+
+### Uniform 类型
+
+| 类型 | 示例 |
+|------|------|
+| number | `1.5` |
+| Vec2 | `{ x: 0.5, y: 1.0 }` |
+| Vec3 | `{ x: 1, y: 0, z: 0 }` |
+| Vec4 | `{ x: 1, y: 1, z: 1, w: 1 }` |
+| number[] | `[1, 2, 3, 4]` |
+| TextureRef | `Material.tex(textureId, slot?)` |
+
+### 纹理 Uniform
+
+使用 `Material.tex()` 创建纹理引用用于采样器 uniform:
+
+```typescript
+const tex = await assets.loadTexture('assets/noise.png');
+Material.setUniform(mat, 'u_noiseTex', Material.tex(tex.handle, 1));
+```
+
+## BlendMode
+
+| 值 | 名称 | 说明 |
+|----|------|------|
+| 0 | `Normal` | 标准 alpha 混合 |
+| 1 | `Additive` | 加法混合(发光效果) |
+| 2 | `Multiply` | 乘法混合(变暗) |
+| 3 | `Screen` | 滤色混合(变亮) |
+| 4 | `PremultipliedAlpha` | 预乘 alpha 混合 |
+
+```typescript
+Material.setBlendMode(mat, BlendMode.Screen);
+const mode = Material.getBlendMode(mat);
+```
+
+## 材质实例
+
+创建共享着色器但拥有独立 uniform 的实例:
+
+```typescript
+const instance = Material.createInstance(sourceMat);
+Material.setUniform(instance, 'u_tint', { x: 0, y: 1, z: 0, w: 1 });
+```
+
+## 着色器文件格式(.shader)
+
+着色器文件使用 `#pragma` 指令分隔顶点和片段部分:
+
+```glsl
+#pragma vertex
+#version 300 es
+precision highp float;
+
+layout(location = 0) in vec3 a_position;
+layout(location = 1) in vec4 a_color;
+layout(location = 2) in vec2 a_texCoord;
+
+uniform mat4 u_projection;
+uniform mat4 u_model;
+
+out vec4 v_color;
+out vec2 v_texCoord;
+
+void main() {
+ v_color = a_color;
+ v_texCoord = a_texCoord;
+ gl_Position = u_projection * u_model * vec4(a_position, 1.0);
+}
+#pragma end
+
+#pragma fragment
+#version 300 es
+precision highp float;
+
+in vec4 v_color;
+in vec2 v_texCoord;
+
+uniform sampler2D u_texture;
+
+out vec4 fragColor;
+
+void main() {
+ fragColor = texture(u_texture, v_texCoord) * v_color;
+}
+#pragma end
+```
+
+通过资源服务器加载着色器文件:
+
+```typescript
+const shader = await assets.loadShader('assets/effects/glow.shader');
+```
+
+## 材质文件格式(.material)
+
+材质可以定义为 JSON 文件,通过资源服务器加载:
+
+```json
+{
+ "version": "1.0",
+ "type": "material",
+ "shader": "effects/glow.shader",
+ "blendMode": 1,
+ "depthTest": false,
+ "properties": {
+ "u_intensity": 1.5,
+ "u_color": { "x": 1, "y": 0.5, "z": 0, "w": 1 }
+ }
+}
+```
+
+| 字段 | 类型 | 说明 |
+|------|------|------|
+| `version` | string | 格式版本(`"1.0"`) |
+| `type` | string | 必须为 `"material"` |
+| `shader` | string | .shader 文件路径(相对于材质文件或绝对路径) |
+| `blendMode` | number | BlendMode 枚举值 |
+| `depthTest` | boolean | 启用深度测试 |
+| `properties` | object | uniform 名称/值对 |
+
+```typescript
+const loaded = await assets.loadMaterial('assets/effects/glow.material');
+sprite.material = loaded.handle;
+```
+
+## 示例:闪烁效果
+
+在系统中动态更新 uniform 实现闪烁效果:
+
+```typescript
+import { defineSystem, addSystem, Query, Mut, Res } from 'esengine';
+import { Sprite, Material, BlendMode, Time } from 'esengine';
+
+const flashShader = Material.createShader(
+ ShaderSources.SPRITE_VERTEX,
+ `#version 300 es
+ precision highp float;
+ in vec4 v_color;
+ in vec2 v_texCoord;
+ uniform sampler2D u_texture;
+ uniform float u_flash;
+ out vec4 fragColor;
+ void main() {
+ vec4 tex = texture(u_texture, v_texCoord) * v_color;
+ fragColor = mix(tex, vec4(1.0), u_flash * step(0.5, tex.a));
+ }`
+);
+
+const flashMat = Material.create({
+ shader: flashShader,
+ uniforms: { u_flash: 0.0 },
+});
+
+addSystem(defineSystem(
+ [Res(Time)],
+ (time) => {
+ const flash = Math.abs(Math.sin(time.elapsed * 5.0));
+ Material.setUniform(flashMat, 'u_flash', flash);
+ }
+));
+```
+
+## 完整 API 参考
+
+| 方法 | 说明 |
+|------|------|
+| `Material.createShader(vertex, fragment)` | 创建着色器程序 |
+| `Material.releaseShader(shader)` | 释放着色器 |
+| `Material.create(options)` | 创建材质 |
+| `Material.createInstance(source)` | 创建共享着色器的材质实例 |
+| `Material.createFromAsset(data, shader)` | 从解析的 .material 文件创建 |
+| `Material.setUniform(mat, name, value)` | 设置 uniform 值 |
+| `Material.getUniform(mat, name)` | 获取 uniform 值 |
+| `Material.getUniforms(mat)` | 获取所有 uniform(Map) |
+| `Material.setBlendMode(mat, mode)` | 设置混合模式 |
+| `Material.getBlendMode(mat)` | 获取混合模式 |
+| `Material.setDepthTest(mat, enabled)` | 设置深度测试 |
+| `Material.getShader(mat)` | 获取着色器句柄 |
+| `Material.release(mat)` | 释放材质 |
+| `Material.isValid(mat)` | 检查材质是否存在 |
+| `Material.toAssetData(mat, shaderPath)` | 导出为可序列化格式 |
+| `Material.tex(textureId, slot?)` | 创建纹理 uniform 引用 |
+
+## 下一步
+
+- [资源加载](/microes/zh/guides/assets/) — 从文件加载材质和着色器
+- [精灵](/microes/zh/guides/sprite/) — 为精灵分配材质
+- [渲染概览](/microes/zh/guides/rendering/) — 渲染管线
diff --git a/docs/astro/src/content/docs/zh/guides/rendering.mdx b/docs/astro/src/content/docs/zh/guides/rendering.mdx
new file mode 100644
index 000000000..de1c26ec2
--- /dev/null
+++ b/docs/astro/src/content/docs/zh/guides/rendering.mdx
@@ -0,0 +1,100 @@
+---
+title: 渲染
+description: ESEngine 中的相机、变换和渲染顺序
+---
+
+import { Aside } from '@astrojs/starlight/components';
+
+ESEngine 使用基于组件的渲染系统。在场景编辑器中为实体添加渲染组件,C++ 后端自动处理绘制。
+
+各渲染组件的详细指南参见[精灵](/microes/zh/guides/sprite/)和 [Spine 动画](/microes/zh/guides/spine/)。
+
+## 相机
+
+需要 `Camera` 组件才能看到内容。编辑器的默认场景已包含一个。
+
+### Camera 属性
+
+| 属性 | 类型 | 说明 |
+|------|------|------|
+| `projectionType` | number | 0 = 透视,1 = 正交 |
+| `fov` | number | 视角角度(仅透视) |
+| `orthoSize` | number | 半高世界单位(仅正交) |
+| `nearPlane` | number | 近裁剪面 |
+| `farPlane` | number | 远裁剪面 |
+| `isActive` | boolean | 是否用于渲染 |
+| `priority` | number | 高优先级相机优先 |
+
+### 正交相机
+
+2D 游戏最佳选择。`orthoSize` 决定可见的世界范围。在检查器中将 `projectionType` 设为 `1`。
+
+### 移动相机
+
+查询相机实体并修改其 transform:
+
+```typescript
+import { defineSystem, addSystem, Res, Input, Query, Mut, LocalTransform, Camera } from 'esengine';
+
+addSystem(defineSystem(
+ [Res(Input), Query(Mut(LocalTransform), Camera)],
+ (input, query) => {
+ for (const [entity, transform, camera] of query) {
+ if (input.isKeyDown('ArrowLeft')) {
+ transform.position.x -= 5;
+ }
+ if (input.isKeyDown('ArrowRight')) {
+ transform.position.x += 5;
+ }
+ }
+ }
+));
+```
+
+## Transform
+
+每个可见实体都需要 `LocalTransform`。在场景编辑器中添加并在检查器中配置位置、旋转和缩放。
+
+### 旋转
+
+旋转使用四元数。绕 Z 轴的 2D 旋转:
+
+```typescript
+import { defineSystem, addSystem, Res, Time, Query, Mut, LocalTransform, Sprite } from 'esengine';
+
+addSystem(defineSystem(
+ [Res(Time), Query(Mut(LocalTransform), Sprite)],
+ (time, query) => {
+ for (const [entity, transform, sprite] of query) {
+ const angle = time.elapsed;
+ const halfAngle = angle / 2;
+ transform.rotation = {
+ w: Math.cos(halfAngle),
+ x: 0,
+ y: 0,
+ z: Math.sin(halfAngle)
+ };
+ }
+ }
+));
+```
+
+### 缩放
+
+```typescript
+transform.scale = { x: 2, y: 2, z: 1 }; // 放大两倍
+transform.scale = { x: -1, y: 1, z: 1 }; // 水平翻转
+```
+
+## 渲染顺序
+
+精灵按以下顺序绘制:
+
+1. **Z 坐标** (`transform.position.z`) — Z 值越小越先绘制(在后面)
+2. **Layer** (`sprite.layer`) — layer 值越大越在上面
+
+在检查器中设置或运行时修改。
+
+<Aside type="tip">
+ C++ 后端负责所有 WebGL 渲染。你只需设置组件数据,引擎每帧自动绘制一切。
+</Aside>
diff --git a/docs/astro/src/content/docs/zh/guides/spine.mdx b/docs/astro/src/content/docs/zh/guides/spine.mdx
new file mode 100644
index 000000000..df6f82758
--- /dev/null
+++ b/docs/astro/src/content/docs/zh/guides/spine.mdx
@@ -0,0 +1,138 @@
+---
+title: Spine 动画
+description: ESEngine 中的 Spine 骨骼动画
+---
+
+import { Aside } from '@astrojs/starlight/components';
+
+`SpineAnimation` 组件播放 [Spine](http://esotericsoftware.com/) 骨骼动画。在场景编辑器中将它和 `LocalTransform` 一起添加到实体上。
+
+## 属性
+
+| 属性 | 类型 | 默认值 | 说明 |
+|------|------|--------|------|
+| `skeletonPath` | string | `''` | 骨骼 JSON 文件路径 |
+| `atlasPath` | string | `''` | 图集文件路径 |
+| `skin` | string | `''` | 当前皮肤名 |
+| `animation` | string | `''` | 当前动画名 |
+| `timeScale` | number | `1.0` | 播放速度倍率 |
+| `loop` | boolean | `true` | 是否循环 |
+| `playing` | boolean | `true` | 是否正在播放 |
+| `flipX` | boolean | `false` | 水平翻转 |
+| `flipY` | boolean | `false` | 垂直翻转 |
+| `color` | Vec4 | `{1, 1, 1, 1}` | 着色 RGBA |
+| `layer` | number | `0` | 渲染顺序 |
+| `skeletonScale` | number | `1.0` | 骨骼缩放因子 |
+| `material` | number | `0` | 材质 ID |
+
+## 设置步骤
+
+1. 将 Spine 导出文件(`.json` + `.atlas` + 图片)放到项目的 `assets/` 文件夹
+2. 在场景编辑器中:创建实体 → 添加 `LocalTransform` 和 `SpineAnimation`
+3. 设置 `skeletonPath` 和 `atlasPath` 指向 Spine 文件
+4. 设置 `animation` 为要播放的动画名
+
+## 控制动画
+
+在系统中查询 `SpineAnimation` 组件来运行时切换动画:
+
+```typescript
+import { defineSystem, addSystem, Res, Input, Query, Mut, SpineAnimation } from 'esengine';
+import { Player } from './components';
+
+addSystem(defineSystem(
+ [Res(Input), Query(Mut(SpineAnimation), Player)],
+ (input, query) => {
+ for (const [entity, spine] of query) {
+ if (input.isKeyPressed('Space')) {
+ spine.animation = 'jump';
+ spine.loop = false;
+ } else if (input.isKeyDown('KeyD') || input.isKeyDown('KeyA')) {
+ spine.animation = 'run';
+ spine.loop = true;
+ } else {
+ spine.animation = 'idle';
+ spine.loop = true;
+ }
+ }
+ }
+));
+```
+
+## 皮肤
+
+切换皮肤改变角色外观:
+
+```typescript
+spine.skin = 'warrior';
+```
+
+## 播放控制
+
+```typescript
+spine.playing = false; // 暂停
+spine.playing = true; // 恢复
+spine.timeScale = 2.0; // 两倍速
+spine.timeScale = 0.5; // 半速
+```
+
+## 翻转
+
+```typescript
+spine.flipX = true; // 面朝左
+spine.flipX = false; // 面朝右(默认)
+```
+
+## 颜色着色
+
+```typescript
+spine.color = { x: 1, y: 0, z: 0, w: 1 }; // 红色
+spine.color = { x: 1, y: 1, z: 1, w: 0.5 }; // 50% 透明
+```
+
+## 示例:角色控制器
+
+定义 `CharacterState` 组件,在编辑器中与 `SpineAnimation` 一起挂载到实体上:
+
+```typescript
+import {
+ defineComponent, defineSystem, addSystem,
+ Res, Input, Time, Query, Mut, LocalTransform, SpineAnimation
+} from 'esengine';
+
+const CharacterState = defineComponent('CharacterState', {
+ speed: 200,
+ currentAnim: 'idle'
+});
+
+addSystem(defineSystem(
+ [Res(Input), Res(Time), Query(Mut(LocalTransform), Mut(SpineAnimation), CharacterState)],
+ (input, time, query) => {
+ for (const [entity, transform, spine, state] of query) {
+ let moving = false;
+
+ if (input.isKeyDown('KeyD')) {
+ transform.position.x += state.speed * time.delta;
+ spine.flipX = false;
+ moving = true;
+ }
+ if (input.isKeyDown('KeyA')) {
+ transform.position.x -= state.speed * time.delta;
+ spine.flipX = true;
+ moving = true;
+ }
+
+ const newAnim = moving ? 'run' : 'idle';
+ if (state.currentAnim !== newAnim) {
+ state.currentAnim = newAnim;
+ spine.animation = newAnim;
+ spine.loop = true;
+ }
+ }
+ }
+));
+```
+
+<Aside type="tip">
+ Spine 渲染由 C++ 后端处理。TypeScript 只负责设置组件数据 — 引擎自动处理加载、混合和绘制。
+</Aside>
diff --git a/docs/astro/src/content/docs/zh/guides/sprite.mdx b/docs/astro/src/content/docs/zh/guides/sprite.mdx
new file mode 100644
index 000000000..551e04d5d
--- /dev/null
+++ b/docs/astro/src/content/docs/zh/guides/sprite.mdx
@@ -0,0 +1,127 @@
+---
+title: 精灵
+description: ESEngine 中的 2D 精灵渲染
+---
+
+import { Aside } from '@astrojs/starlight/components';
+
+`Sprite` 组件是显示 2D 图形的主要方式。在场景编辑器中将它和 `LocalTransform` 一起添加到实体上即可显示。
+
+## 属性
+
+| 属性 | 类型 | 默认值 | 说明 |
+|------|------|--------|------|
+| `texture` | number | `INVALID_TEXTURE` | 纹理句柄,无纹理 = 纯色 |
+| `color` | Vec4 | `{1, 1, 1, 1}` | 着色 RGBA(0–1) |
+| `size` | Vec2 | `{32, 32}` | 宽高(像素) |
+| `uvOffset` | Vec2 | `{0, 0}` | 纹理坐标偏移 |
+| `uvScale` | Vec2 | `{1, 1}` | 纹理坐标缩放 |
+| `layer` | number | `0` | 渲染顺序(越大越靠前) |
+| `flipX` | boolean | `false` | 水平翻转 |
+| `flipY` | boolean | `false` | 垂直翻转 |
+| `material` | number | `0` | 材质 ID |
+
+## 基本用法
+
+在场景编辑器中:创建实体 → 添加 `LocalTransform` 和 `Sprite` → 在检查器中设置尺寸和颜色。
+
+在系统中操作精灵:
+
+```typescript
+import { defineSystem, addSystem, Res, Time, Query, Mut, LocalTransform, Sprite } from 'esengine';
+
+addSystem(defineSystem(
+ [Res(Time), Query(Mut(LocalTransform), Sprite)],
+ (time, query) => {
+ for (const [entity, transform, sprite] of query) {
+ transform.position.x = Math.sin(time.elapsed) * 100;
+ }
+ }
+));
+```
+
+## 纯色矩形
+
+不设置纹理(默认值)时,精灵按 `color` 和 `size` 渲染为纯色矩形。
+
+## 颜色着色
+
+`color` 属性对精灵着色。有纹理时,纹理颜色会与着色相乘。
+
+```typescript
+sprite.color = { x: 1, y: 0, z: 0, w: 1 }; // 红色
+sprite.color = { x: 1, y: 1, z: 1, w: 0.5 }; // 50% 透明
+```
+
+## 翻转
+
+```typescript
+sprite.flipX = true; // 水平镜像
+sprite.flipY = true; // 垂直镜像
+```
+
+## 序列帧动画
+
+使用 `uvOffset` 和 `uvScale` 显示纹理的一部分。定义 `Animation` 组件,在编辑器中与 `Sprite` 一起挂载到实体上:
+
+```typescript
+import { defineComponent, defineSystem, addSystem, Res, Time, Query, Mut, Sprite } from 'esengine';
+
+const Animation = defineComponent('Animation', {
+ frames: 4,
+ currentFrame: 0,
+ frameTime: 0.1,
+ elapsed: 0
+});
+
+addSystem(defineSystem(
+ [Res(Time), Query(Mut(Sprite), Animation)],
+ (time, query) => {
+ for (const [entity, sprite, anim] of query) {
+ anim.elapsed += time.delta;
+
+ if (anim.elapsed >= anim.frameTime) {
+ anim.elapsed = 0;
+ anim.currentFrame = (anim.currentFrame + 1) % anim.frames;
+ sprite.uvOffset.x = anim.currentFrame / anim.frames;
+ sprite.uvScale.x = 1 / anim.frames;
+ }
+ }
+ }
+));
+```
+
+## 渲染顺序
+
+精灵按以下顺序绘制:
+
+1. **Z 坐标** (`transform.position.z`) — Z 值越小越先绘制(在后面)
+2. **Layer** (`sprite.layer`) — layer 值越大越在上面
+
+在检查器中设置或运行时修改。
+
+## 运行时创建
+
+运行时创建精灵(子弹、粒子等):
+
+```typescript
+import { defineSystem, addSystem, Commands, Sprite, LocalTransform } from 'esengine';
+
+addSystem(defineSystem(
+ [Commands()],
+ (cmds) => {
+ cmds.spawn()
+ .insert(Sprite, {
+ size: { x: 10, y: 10 },
+ color: { x: 1, y: 1, z: 0, w: 1 }
+ })
+ .insert(LocalTransform, {
+ position: { x: 0, y: 0, z: 0 }
+ });
+ }
+));
+```
+
+<Aside type="tip">
+ C++ 后端负责所有 WebGL 渲染。你只需设置组件数据,引擎每帧自动绘制一切。
+</Aside>
diff --git a/docs/astro/src/content/docs/zh/guides/ui.mdx b/docs/astro/src/content/docs/zh/guides/ui.mdx
new file mode 100644
index 000000000..aeabe2eb0
--- /dev/null
+++ b/docs/astro/src/content/docs/zh/guides/ui.mdx
@@ -0,0 +1,127 @@
+---
+title: UI 与文本
+description: ESEngine 中的文本渲染和 UI 布局组件
+---
+
+import { Aside } from '@astrojs/starlight/components';
+
+`Text` 和 `UIRect` 组件配合 `Sprite` 实现游戏中的文本渲染。`TextPlugin` 会在每帧自动将文本内容转换为纹理。
+
+## 设置步骤
+
+在场景编辑器中:创建实体 → 添加 `LocalTransform`、`Sprite`、`Text` 和 `UIRect` 组件。
+
+- **Text** — 定义文本内容和样式(字体、大小、颜色、对齐)
+- **UIRect** — 定义布局矩形(尺寸、锚点、旋转中心)
+- **Sprite** — 文本系统内部使用,用于显示渲染后的纹理
+
+<Aside type="note">
+ 无需手动配置 Sprite 组件。`TextPlugin` 会自动根据 Text 内容创建和更新精灵纹理。
+</Aside>
+
+## Text 属性
+
+| 属性 | 类型 | 默认值 | 说明 |
+|------|------|--------|------|
+| `content` | string | `''` | 显示的文本内容 |
+| `fontFamily` | string | `'Arial'` | 字体名称 |
+| `fontSize` | number | `24` | 字号(像素) |
+| `color` | Vec4 | `{1, 1, 1, 1}` | 文本颜色 RGBA(0–1) |
+| `align` | TextAlign | `Left` | 水平对齐方式 |
+| `verticalAlign` | TextVerticalAlign | `Top` | 垂直对齐方式 |
+| `wordWrap` | boolean | `true` | 启用自动换行 |
+| `overflow` | TextOverflow | `Visible` | 溢出处理模式 |
+| `lineHeight` | number | `1.2` | 行高倍率 |
+
+## UIRect 属性
+
+| 属性 | 类型 | 默认值 | 说明 |
+|------|------|--------|------|
+| `size` | Vec2 | `{100, 100}` | UI 矩形的宽高 |
+| `anchor` | Vec2 | `{0.5, 0.5}` | 锚点(0–1 范围) |
+| `pivot` | Vec2 | `{0.5, 0.5}` | 旋转和缩放的中心点 |
+
+## 枚举类型
+
+### TextAlign
+
+| 值 | 名称 | 说明 |
+|----|------|------|
+| 0 | `Left` | 左对齐 |
+| 1 | `Center` | 居中对齐 |
+| 2 | `Right` | 右对齐 |
+
+### TextVerticalAlign
+
+| 值 | 名称 | 说明 |
+|----|------|------|
+| 0 | `Top` | 顶部对齐 |
+| 1 | `Middle` | 垂直居中 |
+| 2 | `Bottom` | 底部对齐 |
+
+### TextOverflow
+
+| 值 | 名称 | 说明 |
+|----|------|------|
+| 0 | `Visible` | 文本溢出矩形边界 |
+| 1 | `Clip` | 在边界处裁剪 |
+| 2 | `Ellipsis` | 截断处显示省略号 |
+
+## 运行时修改文本
+
+在系统中通过 `Mut()` 查询 `Text` 组件来更新文本内容或样式:
+
+```typescript
+import { defineSystem, addSystem, Query, Mut } from 'esengine';
+import { Text } from 'esengine';
+
+addSystem(defineSystem(
+ [Query(Mut(Text))],
+ (query) => {
+ for (const [entity, text] of query) {
+ text.content = '已更新!';
+ text.fontSize = 32;
+ }
+ }
+));
+```
+
+<Aside type="caution">
+ 修改文本属性时必须使用 `Mut(Text)`。不使用 `Mut()` 时组件为只读。
+</Aside>
+
+## 示例:动态计分板
+
+一种常见模式是在数值变化时更新分数显示:
+
+```typescript
+import { defineComponent, defineTag, defineSystem, addSystem, Query, Mut } from 'esengine';
+import { Text } from 'esengine';
+
+const ScoreDisplay = defineTag('ScoreDisplay');
+
+const GameState = defineComponent('GameState', {
+ score: 0,
+});
+
+addSystem(defineSystem(
+ [Query(Mut(Text), ScoreDisplay), Query(GameState)],
+ (displayQuery, stateQuery) => {
+ let score = 0;
+ for (const [, state] of stateQuery) {
+ score = state.score;
+ }
+ for (const [, text] of displayQuery) {
+ text.content = `分数:${score}`;
+ }
+ }
+));
+```
+
+在编辑器中:创建一个文本实体,添加 `Text`、`UIRect`、`Sprite`、`LocalTransform` 和 `ScoreDisplay` 标签。
+
+## 下一步
+
+- [组件](/microes/zh/core-concepts/components/) — 所有内置组件
+- [精灵](/microes/zh/guides/sprite/) — 精灵渲染详解
+- [资源加载](/microes/zh/guides/assets/) — 加载纹理和其他资源
diff --git a/docs/astro/src/content/docs/zh/index.mdx b/docs/astro/src/content/docs/zh/index.mdx
new file mode 100644
index 000000000..0cf9402ac
--- /dev/null
+++ b/docs/astro/src/content/docs/zh/index.mdx
@@ -0,0 +1,73 @@
+---
+title: ESEngine
+description: 轻量级 2D 游戏引擎,适用于 Web 和微信小游戏
+template: splash
+hero:
+ tagline: 使用 TypeScript 和 WebAssembly 构建 2D 游戏
+ image:
+ file: ../../../assets/hero.svg
+ actions:
+ - text: 快速上手
+ link: /microes/zh/getting-started/introduction/
+ icon: right-arrow
+ variant: primary
+ - text: 在 GitHub 上查看
+ link: https://github.com/esengine/microes
+ icon: external
+---
+
+import { Card, CardGrid } from '@astrojs/starlight/components';
+
+## 特性
+
+<CardGrid stagger>
+ <Card title="ECS 架构" icon="puzzle">
+ 面向数据的实体-组件-系统设计。通过可复用的组件组合游戏对象,用系统驱动行为。
+ </Card>
+ <Card title="WebGL 渲染" icon="laptop">
+ C++ 渲染管线编译为 WebAssembly。开箱即用的精灵、相机、Spine 动画和自定义着色器。
+ </Card>
+ <Card title="跨平台" icon="rocket">
+ 一套代码同时运行在 Web 浏览器和微信小游戏,通过平台适配器实现。
+ </Card>
+ <Card title="TypeScript SDK" icon="seti:typescript">
+ 类型安全的 API:`defineSystem`、`defineComponent`、`Query` — 用地道的 TypeScript 编写游戏逻辑。
+ </Card>
+</CardGrid>
+
+## 快速示例
+
+定义自定义组件,在场景编辑器中挂到实体上,然后编写系统:
+
+```typescript
+import {
+ defineComponent, defineSystem, addSystem,
+ Query, Res, Time, Mut, LocalTransform
+} from 'esengine';
+
+const Speed = defineComponent('Speed', { value: 200 });
+
+addSystem(defineSystem(
+ [Res(Time), Query(Mut(LocalTransform), Speed)],
+ (time, query) => {
+ for (const [entity, transform, speed] of query) {
+ transform.position.x += speed.value * time.delta;
+ }
+ }
+));
+```
+
+## 下一步
+
+<CardGrid>
+ <Card title="简介" icon="open-book">
+ 了解 ESEngine 是什么以及它如何工作。
+
+ [阅读更多 →](/microes/zh/getting-started/introduction/)
+ </Card>
+ <Card title="快速开始" icon="rocket">
+ 几分钟内创建你的第一个游戏。
+
+ [开始 →](/microes/zh/getting-started/quick-start/)
+ </Card>
+</CardGrid>