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: update guides and add v0.4.0 changelog

esengined589a350529b
diff --git a/docs/astro/astro.config.mjs b/docs/astro/astro.config.mjs
index 7cf5b4162..1703a824a 100644
--- a/docs/astro/astro.config.mjs
+++ b/docs/astro/astro.config.mjs
@@ -77,6 +77,7 @@ export default defineConfig({
{ label: 'Asset Loading', translations: { 'zh-CN': '资源加载' }, slug: 'guides/assets' },
{ label: 'Materials & Shaders', translations: { 'zh-CN': '材质与着色器' }, slug: 'guides/materials' },
{ label: 'Geometry & Meshes', translations: { 'zh-CN': '几何体与网格' }, slug: 'guides/geometry' },
+ { label: 'Physics', translations: { 'zh-CN': '物理' }, slug: 'guides/physics' },
{ label: 'Editor Extensions', translations: { 'zh-CN': '编辑器扩展' }, slug: 'guides/editor-extensions' },
],
},
@@ -84,6 +85,7 @@ export default defineConfig({
label: 'Changelog',
translations: { 'zh-CN': '更新日志' },
items: [
+ { label: 'v0.4.0', slug: 'changelog-v040' },
{ label: 'v0.3.0', slug: 'changelog' },
],
},
diff --git a/docs/astro/src/content/docs/changelog-v040.mdx b/docs/astro/src/content/docs/changelog-v040.mdx
new file mode 100644
index 000000000..4aec2e4fa
--- /dev/null
+++ b/docs/astro/src/content/docs/changelog-v040.mdx
@@ -0,0 +1,51 @@
+---
+title: v0.4.0
+description: ESEngine v0.4.0 release notes
+---
+
+import { Aside } from '@astrojs/starlight/components';
+
+## Physics System
+
+- Added standalone Box2D WASM physics module, loaded as a plugin via `PhysicsPlugin`
+- New components: `RigidBody`, `BoxCollider`, `CircleCollider`, `CapsuleCollider`
+- Three body types: Static, Kinematic, Dynamic
+- Collision and sensor events via `PhysicsEvents` resource (`collisionEnters`, `collisionExits`, `sensorEnters`, `sensorExits`)
+- `Physics` API helper for runtime force/impulse/velocity control
+- Editor collider overlay visualization for debugging
+
+## Spine 4.1 Support
+
+- Added `spine41` standalone WASM module alongside existing `spine38` and `spine42`
+- Select Spine version `3.8`, `4.1`, or `4.2` in **Settings → Project → Spine Version**
+
+## Color Type Refactored
+
+- Color properties now use `{ r, g, b, a }` format instead of `{ x, y, z, w }`
+- Affects `Sprite.color`, `SpineAnimation.color`, `Canvas.backgroundColor`, `Text.color`, and Draw API color parameters
+- Old scene files with `{ x, y, z, w }` color format are auto-migrated on load
+
+## Renderer Improvements
+
+- Added triangle drawing primitives
+- Texture Y-flip moved from JS to GPU via `GL_UNPACK_FLIP_Y_WEBGL`
+- Added premultiplied alpha (PMA) blend modes
+
+## Performance
+
+- Switched from embind to `extern "C"` for C++/JS interop
+- Removed RTTI and C++ exceptions from WASM builds
+- Dead code elimination for smaller binary size
+
+## Editor
+
+- Script compilation errors now shown via toast notifications and Output panel
+- Continuous Canvas 2D rendering mode for smoother editor viewport updates
+
+## Bug Fixes
+
+- Fixed Spine sequence texture flickering
+- Fixed entity spawn flush timing
+- Fixed collider overlay PPU scaling
+- Fixed scene color property migration
+- Fixed script error reporting in editor
diff --git a/docs/astro/src/content/docs/core-concepts/components.mdx b/docs/astro/src/content/docs/core-concepts/components.mdx
index ab46f548b..ff404d1f1 100644
--- a/docs/astro/src/content/docs/core-concepts/components.mdx
+++ b/docs/astro/src/content/docs/core-concepts/components.mdx
@@ -49,7 +49,7 @@ Display settings for the rendering surface.
| `pixelsPerUnit` | number | Pixels per world unit |
| `scaleMode` | number | How the canvas scales |
| `matchWidthOrHeight` | number | Balance between width/height matching |
-| `backgroundColor` | Vec4 | Clear color RGBA |
+| `backgroundColor` | Color | Clear color RGBA |
### Velocity
@@ -82,7 +82,7 @@ UI text rendering. Works with `UIRect` and `Sprite` to display text. See [UI & T
| `content` | string | Text content |
| `fontFamily` | string | Font family |
| `fontSize` | number | Font size in pixels |
-| `color` | Vec4 | Text color RGBA |
+| `color` | Color | Text color RGBA |
| `align` | TextAlign | Horizontal alignment |
| `verticalAlign` | TextVerticalAlign | Vertical alignment |
@@ -96,6 +96,58 @@ UI layout rectangle. Defines size, anchor, and pivot for UI elements.
| `anchor` | Vec2 | Anchor point (0–1) |
| `pivot` | Vec2 | Pivot point for rotation |
+### Physics
+
+Physics components require the `PhysicsPlugin`. See [Physics guide](/microes/guides/physics/) for setup and usage.
+
+#### RigidBody
+
+Physics body attached to an entity. Requires `LocalTransform`.
+
+| Property | Type | Default | Description |
+|----------|------|---------|-------------|
+| `bodyType` | number | `2` (Dynamic) | 0=Static, 1=Kinematic, 2=Dynamic |
+| `gravityScale` | number | `1.0` | Gravity multiplier |
+| `linearDamping` | number | `0.0` | Linear velocity damping |
+| `angularDamping` | number | `0.0` | Angular velocity damping |
+| `fixedRotation` | boolean | `false` | Lock rotation |
+| `bullet` | boolean | `false` | Continuous collision detection for fast objects |
+| `enabled` | boolean | `true` | Enable physics body |
+
+#### BoxCollider
+
+| Property | Type | Default | Description |
+|----------|------|---------|-------------|
+| `halfExtents` | Vec2 | `{x: 0.5, y: 0.5}` | Half size in meters |
+| `offset` | Vec2 | `{x: 0, y: 0}` | Local offset |
+| `density` | number | `1.0` | Mass density |
+| `friction` | number | `0.3` | Surface friction |
+| `restitution` | number | `0.0` | Bounciness |
+| `isSensor` | boolean | `false` | Trigger-only (no physical response) |
+
+#### CircleCollider
+
+| Property | Type | Default | Description |
+|----------|------|---------|-------------|
+| `radius` | number | `0.5` | Circle radius in meters |
+| `offset` | Vec2 | `{x: 0, y: 0}` | Local offset |
+| `density` | number | `1.0` | Mass density |
+| `friction` | number | `0.3` | Surface friction |
+| `restitution` | number | `0.0` | Bounciness |
+| `isSensor` | boolean | `false` | Trigger-only (no physical response) |
+
+#### CapsuleCollider
+
+| Property | Type | Default | Description |
+|----------|------|---------|-------------|
+| `radius` | number | `0.25` | Capsule radius |
+| `halfHeight` | number | `0.5` | Half height of the capsule body |
+| `offset` | Vec2 | `{x: 0, y: 0}` | Local offset |
+| `density` | number | `1.0` | Mass density |
+| `friction` | number | `0.3` | Surface friction |
+| `restitution` | number | `0.0` | Bounciness |
+| `isSensor` | boolean | `false` | Trigger-only (no physical response) |
+
## Custom Components
### defineComponent
diff --git a/docs/astro/src/content/docs/guides/canvas.mdx b/docs/astro/src/content/docs/guides/canvas.mdx
index 92d4be548..e41e9fb27 100644
--- a/docs/astro/src/content/docs/guides/canvas.mdx
+++ b/docs/astro/src/content/docs/guides/canvas.mdx
@@ -21,7 +21,7 @@ You can also add the `Canvas` component manually to any entity that has a `Camer
| `pixelsPerUnit` | number | `100` | How many pixels equal one world unit |
| `scaleMode` | number | `1` | Scale strategy (see below) |
| `matchWidthOrHeight` | number | `0.5` | Blend factor for Match mode (0 = width, 1 = height) |
-| `backgroundColor` | Vec4 | `{x: 0, y: 0, z: 0, w: 1}` | Letterbox/pillarbox fill color |
+| `backgroundColor` | Color | `{r: 0, g: 0, b: 0, a: 1}` | Letterbox/pillarbox fill color |
## Pixels Per Unit
diff --git a/docs/astro/src/content/docs/guides/custom-draw.mdx b/docs/astro/src/content/docs/guides/custom-draw.mdx
index bd74ff3a2..c97434e09 100644
--- a/docs/astro/src/content/docs/guides/custom-draw.mdx
+++ b/docs/astro/src/content/docs/guides/custom-draw.mdx
@@ -15,7 +15,7 @@ Register a draw callback to execute drawing commands each frame. The engine call
import { registerDrawCallback, Draw } from 'esengine';
registerDrawCallback('my-debug', (elapsed) => {
- Draw.line({ x: 0, y: 0 }, { x: 100, y: 100 }, { x: 1, y: 0, z: 0, w: 1 }, 2);
+ Draw.line({ x: 0, y: 0 }, { x: 100, y: 100 }, { r: 1, g: 0, b: 0, a: 1 }, 2);
});
```
@@ -40,7 +40,7 @@ clearDrawCallbacks();
Draw.line(
{ x: 0, y: 0 }, // from
{ x: 200, y: 150 }, // to
- { x: 1, y: 1, z: 0, w: 1 }, // yellow
+ { r: 1, g: 1, b: 0, a: 1 }, // yellow
2 // thickness
);
```
@@ -51,14 +51,14 @@ Draw.line(
Draw.rect(
{ x: 100, y: 100 }, // center position
{ x: 80, y: 60 }, // size
- { x: 0, y: 0.5, z: 1, w: 0.5 }, // semi-transparent blue
+ { r: 0, g: 0.5, b: 1, a: 0.5 }, // semi-transparent blue
true // filled (default)
);
Draw.rectOutline(
{ x: 100, y: 100 },
{ x: 80, y: 60 },
- { x: 1, y: 0, z: 0, w: 1 }, // red
+ { r: 1, g: 0, b: 0, a: 1 }, // red
2 // thickness
);
```
@@ -69,7 +69,7 @@ Draw.rectOutline(
Draw.circle(
{ x: 200, y: 200 }, // center
50, // radius
- { x: 0, y: 1, z: 0, w: 1 }, // green
+ { r: 0, g: 1, b: 0, a: 1 }, // green
true, // filled
32 // segments
);
@@ -77,7 +77,7 @@ Draw.circle(
Draw.circleOutline(
{ x: 200, y: 200 },
50,
- { x: 1, y: 1, z: 1, w: 1 }, // white
+ { r: 1, g: 1, b: 1, a: 1 }, // white
1, // thickness
32 // segments
);
@@ -90,7 +90,7 @@ Draw.texture(
{ x: 300, y: 200 }, // position
{ x: 64, y: 64 }, // size
textureHandle,
- { x: 1, y: 1, z: 1, w: 1 } // tint (default: white)
+ { r: 1, g: 1, b: 1, a: 1 } // tint (default: white)
);
Draw.textureRotated(
@@ -98,7 +98,7 @@ Draw.textureRotated(
{ x: 64, y: 64 },
Math.PI / 4, // rotation in radians
textureHandle,
- { x: 1, y: 1, z: 1, w: 1 }
+ { r: 1, g: 1, b: 1, a: 1 }
);
```
@@ -186,7 +186,7 @@ addSystem(defineSystem(
));
registerDrawCallback('debug-colliders', () => {
- const green = { x: 0, y: 1, z: 0, w: 0.5 };
+ const green = { r: 0, g: 1, b: 0, a: 0.5 };
for (const c of colliders) {
Draw.rectOutline(
{ x: c.x, y: c.y },
diff --git a/docs/astro/src/content/docs/guides/editor-extensions.mdx b/docs/astro/src/content/docs/guides/editor-extensions.mdx
index 806cbbeea..0e8fe7967 100644
--- a/docs/astro/src/content/docs/guides/editor-extensions.mdx
+++ b/docs/astro/src/content/docs/guides/editor-extensions.mdx
@@ -560,11 +560,11 @@ registerSettingsItem({
registerDrawCallback('origin-crosshair', () => {
if (!getSettingsValue('debug-overlay.showOrigin')) return;
const size = getSettingsValue<number>('debug-overlay.size');
- const red = { x: 1, y: 0, z: 0, w: 1 };
- const green = { x: 0, y: 1, z: 0, w: 1 };
+ const red = { r: 1, g: 0, b: 0, a: 1 };
+ const green = { r: 0, g: 1, b: 0, a: 1 };
Draw.line({ x: 0, y: 0 }, { x: size, y: 0 }, red, 2);
Draw.line({ x: 0, y: 0 }, { x: 0, y: size }, green, 2);
- Draw.circleOutline({ x: 0, y: 0 }, 4, { x: 1, y: 1, z: 1, w: 1 }, 1);
+ Draw.circleOutline({ x: 0, y: 0 }, 4, { r: 1, g: 1, b: 1, a: 1 }, 1);
});
```
diff --git a/docs/astro/src/content/docs/guides/geometry.mdx b/docs/astro/src/content/docs/guides/geometry.mdx
index c8138f1d7..38ef722f2 100644
--- a/docs/astro/src/content/docs/guides/geometry.mdx
+++ b/docs/astro/src/content/docs/guides/geometry.mdx
@@ -106,7 +106,7 @@ import { registerDrawCallback, Draw, Geometry, Material, BlendMode } from 'eseng
const quad = Geometry.createQuad(100, 100);
const mat = Material.create({
shader: myShader,
- uniforms: { u_color: { x: 1, y: 0, z: 0, w: 1 } },
+ uniforms: { u_color: { r: 1, g: 0, b: 0, a: 1 } },
blendMode: BlendMode.Normal,
});
diff --git a/docs/astro/src/content/docs/guides/materials.mdx b/docs/astro/src/content/docs/guides/materials.mdx
index 566a2b29f..7195af791 100644
--- a/docs/astro/src/content/docs/guides/materials.mdx
+++ b/docs/astro/src/content/docs/guides/materials.mdx
@@ -47,7 +47,7 @@ const mat = Material.create({
shader,
uniforms: {
u_time: 0,
- u_tint: { x: 1, y: 0, z: 0, w: 1 },
+ u_tint: { r: 1, g: 0, b: 0, a: 1 },
},
blendMode: BlendMode.Additive,
});
@@ -70,7 +70,7 @@ sprite.material = mat;
```typescript
Material.setUniform(mat, 'u_time', elapsed);
-Material.setUniform(mat, 'u_tint', { x: 1, y: 0.5, z: 0, w: 1 });
+Material.setUniform(mat, 'u_tint', { r: 1, g: 0.5, b: 0, a: 1 });
const time = Material.getUniform(mat, 'u_time');
```
@@ -82,6 +82,7 @@ const time = Material.getUniform(mat, 'u_time');
| number | `1.5` |
| Vec2 | `{ x: 0.5, y: 1.0 }` |
| Vec3 | `{ x: 1, y: 0, z: 0 }` |
+| Color | `{ r: 1, g: 1, b: 1, a: 1 }` |
| Vec4 | `{ x: 1, y: 1, z: 1, w: 1 }` |
| number[] | `[1, 2, 3, 4]` |
| TextureRef | `Material.tex(textureId, slot?)` |
@@ -116,7 +117,7 @@ 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 });
+Material.setUniform(instance, 'u_tint', { r: 0, g: 1, b: 0, a: 1 });
```
## Shader File Format (.esshader)
diff --git a/docs/astro/src/content/docs/guides/spine.mdx b/docs/astro/src/content/docs/guides/spine.mdx
index 19c8c0945..a9ec62614 100644
--- a/docs/astro/src/content/docs/guides/spine.mdx
+++ b/docs/astro/src/content/docs/guides/spine.mdx
@@ -8,7 +8,7 @@ import { Aside } from '@astrojs/starlight/components';
The `SpineAnimation` component plays [Spine](http://esotericsoftware.com/) skeletal animations. Add it to an entity in the scene editor along with `LocalTransform`.
<Aside type="note">
- Since v0.3.0, Spine uses standalone WASM modules (`spine38` / `spine42`) instead of being bundled into the engine core. Select the Spine version in the editor under **Settings → Project → Spine Version** (`3.8` or `4.2`). The editor loads the matching runtime automatically — no code is needed.
+ Since v0.3.0, Spine uses standalone WASM modules (`spine38` / `spine41` / `spine42`) instead of being bundled into the engine core. Select the Spine version in the editor under **Settings → Project → Spine Version** (`3.8`, `4.1`, or `4.2`). The editor loads the matching runtime automatically — no code is needed.
</Aside>
## Properties
@@ -24,7 +24,7 @@ The `SpineAnimation` component plays [Spine](http://esotericsoftware.com/) skele
| `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 |
+| `color` | Color | `{r:1, g:1, b:1, a:1}` | Tint color RGBA |
| `layer` | number | `0` | Render order |
| `skeletonScale` | number | `1.0` | Skeleton scale factor |
| `material` | number | `0` | Material ID |
@@ -90,8 +90,8 @@ 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
+spine.color = { r: 1, g: 0, b: 0, a: 1 }; // Red tint
+spine.color = { r: 1, g: 1, b: 1, a: 0.5 }; // 50% transparent
```
## Example: Character Controller
diff --git a/docs/astro/src/content/docs/guides/sprite.mdx b/docs/astro/src/content/docs/guides/sprite.mdx
index 0e16a40ad..932d24ac9 100644
--- a/docs/astro/src/content/docs/guides/sprite.mdx
+++ b/docs/astro/src/content/docs/guides/sprite.mdx
@@ -12,7 +12,7 @@ The `Sprite` component is the primary way to display 2D graphics. Add it to an e
| 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) |
+| `color` | Color | `{r:1, g:1, b:1, a: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 |
@@ -49,8 +49,8 @@ Without a texture (default), the sprite renders as a solid rectangle using its `
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
+sprite.color = { r: 1, g: 0, b: 0, a: 1 }; // Red tint
+sprite.color = { r: 1, g: 1, b: 1, a: 0.5 }; // 50% transparent
```
## Flipping
@@ -113,7 +113,7 @@ addSystem(defineSystem(
cmds.spawn()
.insert(Sprite, {
size: { x: 10, y: 10 },
- color: { x: 1, y: 1, z: 0, w: 1 }
+ color: { r: 1, g: 1, b: 0, a: 1 }
})
.insert(LocalTransform, {
position: { x: 0, y: 0, z: 0 }
diff --git a/docs/astro/src/content/docs/guides/ui.mdx b/docs/astro/src/content/docs/guides/ui.mdx
index daf3a5601..339973250 100644
--- a/docs/astro/src/content/docs/guides/ui.mdx
+++ b/docs/astro/src/content/docs/guides/ui.mdx
@@ -26,7 +26,7 @@ In the scene editor: create an entity → add `LocalTransform`, `Sprite`, `Text`
| `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) |
+| `color` | Color | `{r:1, g:1, b:1, a:1}` | Text color RGBA (0–1) |
| `align` | TextAlign | `Left` | Horizontal alignment |
| `verticalAlign` | TextVerticalAlign | `Top` | Vertical alignment |
| `wordWrap` | boolean | `true` | Enable automatic word wrapping |
diff --git a/docs/astro/src/content/docs/zh/changelog-v040.mdx b/docs/astro/src/content/docs/zh/changelog-v040.mdx
new file mode 100644
index 000000000..d75fb57e6
--- /dev/null
+++ b/docs/astro/src/content/docs/zh/changelog-v040.mdx
@@ -0,0 +1,51 @@
+---
+title: v0.4.0
+description: ESEngine v0.4.0 更新日志
+---
+
+import { Aside } from '@astrojs/starlight/components';
+
+## 物理系统
+
+- 新增独立 Box2D WASM 物理模块,通过 `PhysicsPlugin` 以插件形式加载
+- 新增组件:`RigidBody`、`BoxCollider`、`CircleCollider`、`CapsuleCollider`
+- 三种刚体类型:Static(静态)、Kinematic(运动学)、Dynamic(动态)
+- 通过 `PhysicsEvents` 资源获取碰撞和传感器事件(`collisionEnters`、`collisionExits`、`sensorEnters`、`sensorExits`)
+- `Physics` API 辅助类,用于运行时力/冲量/速度控制
+- 编辑器碰撞体叠加可视化用于调试
+
+## Spine 4.1 支持
+
+- 新增 `spine41` 独立 WASM 模块,与现有的 `spine38` 和 `spine42` 并存
+- 在 **Settings → Project → Spine Version** 中可选择 Spine 版本 `3.8`、`4.1` 或 `4.2`
+
+## Color 类型重构
+
+- 颜色属性现在使用 `{ r, g, b, a }` 格式替代 `{ x, y, z, w }`
+- 影响 `Sprite.color`、`SpineAnimation.color`、`Canvas.backgroundColor`、`Text.color` 以及 Draw API 颜色参数
+- 使用 `{ x, y, z, w }` 颜色格式的旧场景文件在加载时自动迁移
+
+## 渲染改进
+
+- 新增三角形绘制图元
+- 纹理 Y 翻转从 JS 移至 GPU,通过 `GL_UNPACK_FLIP_Y_WEBGL` 实现
+- 新增预乘 alpha(PMA)混合模式
+
+## 性能优化
+
+- C++/JS 互操作从 embind 切换到 `extern "C"`
+- 从 WASM 构建中移除 RTTI 和 C++ 异常
+- 死代码消除,减小二进制体积
+
+## 编辑器
+
+- 脚本编译错误现在通过 toast 通知和 Output 面板显示
+- 持续 Canvas 2D 渲染模式,编辑器视口更新更流畅
+
+## Bug 修复
+
+- 修复 Spine 序列纹理闪烁
+- 修复实体生成 flush 时序问题
+- 修复碰撞体叠加 PPU 缩放
+- 修复场景颜色属性迁移
+- 修复编辑器脚本错误上报
diff --git a/docs/astro/src/content/docs/zh/core-concepts/components.mdx b/docs/astro/src/content/docs/zh/core-concepts/components.mdx
index 765bc6128..0a194cd4a 100644
--- a/docs/astro/src/content/docs/zh/core-concepts/components.mdx
+++ b/docs/astro/src/content/docs/zh/core-concepts/components.mdx
@@ -49,7 +49,7 @@ import { Aside } from '@astrojs/starlight/components';
| `pixelsPerUnit` | number | 每世界单位像素数 |
| `scaleMode` | number | 画布缩放模式 |
| `matchWidthOrHeight` | number | 宽高匹配平衡 |
-| `backgroundColor` | Vec4 | 清屏颜色 RGBA |
+| `backgroundColor` | Color | 清屏颜色 RGBA |
### Velocity
@@ -82,7 +82,7 @@ UI 文本渲染。配合 `UIRect` 和 `Sprite` 组件显示文本。详见 [UI
| `content` | string | 文本内容 |
| `fontFamily` | string | 字体名称 |
| `fontSize` | number | 字号(像素) |
-| `color` | Vec4 | 文本颜色 RGBA |
+| `color` | Color | 文本颜色 RGBA |
| `align` | TextAlign | 水平对齐方式 |
| `verticalAlign` | TextVerticalAlign | 垂直对齐方式 |
@@ -96,6 +96,58 @@ UI 布局矩形。定义 UI 元素的尺寸、锚点和旋转中心。
| `anchor` | Vec2 | 锚点(0–1) |
| `pivot` | Vec2 | 旋转中心点 |
+### 物理
+
+物理组件需要 `PhysicsPlugin`。详见[物理指南](/microes/zh/guides/physics/)。
+
+#### RigidBody
+
+附加到实体的物理刚体。需要 `LocalTransform`。
+
+| 属性 | 类型 | 默认值 | 说明 |
+|------|------|--------|------|
+| `bodyType` | number | `2`(Dynamic) | 0=静态,1=运动学,2=动态 |
+| `gravityScale` | number | `1.0` | 重力倍率 |
+| `linearDamping` | number | `0.0` | 线速度阻尼 |
+| `angularDamping` | number | `0.0` | 角速度阻尼 |
+| `fixedRotation` | boolean | `false` | 锁定旋转 |
+| `bullet` | boolean | `false` | 高速物体连续碰撞检测 |
+| `enabled` | boolean | `true` | 启用物理刚体 |
+
+#### BoxCollider
+
+| 属性 | 类型 | 默认值 | 说明 |
+|------|------|--------|------|
+| `halfExtents` | Vec2 | `{x: 0.5, y: 0.5}` | 半尺寸(米) |
+| `offset` | Vec2 | `{x: 0, y: 0}` | 局部偏移 |
+| `density` | number | `1.0` | 质量密度 |
+| `friction` | number | `0.3` | 表面摩擦力 |
+| `restitution` | number | `0.0` | 弹性(弹力) |
+| `isSensor` | boolean | `false` | 仅触发(无物理响应) |
+
+#### CircleCollider
+
+| 属性 | 类型 | 默认值 | 说明 |
+|------|------|--------|------|
+| `radius` | number | `0.5` | 圆形半径(米) |
+| `offset` | Vec2 | `{x: 0, y: 0}` | 局部偏移 |
+| `density` | number | `1.0` | 质量密度 |
+| `friction` | number | `0.3` | 表面摩擦力 |
+| `restitution` | number | `0.0` | 弹性(弹力) |
+| `isSensor` | boolean | `false` | 仅触发(无物理响应) |
+
+#### CapsuleCollider
+
+| 属性 | 类型 | 默认值 | 说明 |
+|------|------|--------|------|
+| `radius` | number | `0.25` | 胶囊半径 |
+| `halfHeight` | number | `0.5` | 胶囊体半高 |
+| `offset` | Vec2 | `{x: 0, y: 0}` | 局部偏移 |
+| `density` | number | `1.0` | 质量密度 |
+| `friction` | number | `0.3` | 表面摩擦力 |
+| `restitution` | number | `0.0` | 弹性(弹力) |
+| `isSensor` | boolean | `false` | 仅触发(无物理响应) |
+
## 自定义组件
### defineComponent
diff --git a/docs/astro/src/content/docs/zh/guides/canvas.mdx b/docs/astro/src/content/docs/zh/guides/canvas.mdx
index 199b52e68..e245a999a 100644
--- a/docs/astro/src/content/docs/zh/guides/canvas.mdx
+++ b/docs/astro/src/content/docs/zh/guides/canvas.mdx
@@ -21,7 +21,7 @@ import { Aside } from '@astrojs/starlight/components';
| `pixelsPerUnit` | number | `100` | 多少像素等于一个世界单位 |
| `scaleMode` | number | `1` | 缩放策略(见下文) |
| `matchWidthOrHeight` | number | `0.5` | Match 模式的混合系数(0 = 宽度,1 = 高度) |
-| `backgroundColor` | Vec4 | `{x: 0, y: 0, z: 0, w: 1}` | 黑边填充颜色 |
+| `backgroundColor` | Color | `{r: 0, g: 0, b: 0, a: 1}` | 黑边填充颜色 |
## Pixels Per Unit
diff --git a/docs/astro/src/content/docs/zh/guides/custom-draw.mdx b/docs/astro/src/content/docs/zh/guides/custom-draw.mdx
index 7a478cc40..32028963e 100644
--- a/docs/astro/src/content/docs/zh/guides/custom-draw.mdx
+++ b/docs/astro/src/content/docs/zh/guides/custom-draw.mdx
@@ -15,7 +15,7 @@ Draw API 提供即时模式 2D 绘图图元。所有绘制命令每帧清空,
import { registerDrawCallback, Draw } from 'esengine';
registerDrawCallback('my-debug', (elapsed) => {
- Draw.line({ x: 0, y: 0 }, { x: 100, y: 100 }, { x: 1, y: 0, z: 0, w: 1 }, 2);
+ Draw.line({ x: 0, y: 0 }, { x: 100, y: 100 }, { r: 1, g: 0, b: 0, a: 1 }, 2);
});
```
@@ -40,7 +40,7 @@ clearDrawCallbacks();
Draw.line(
{ x: 0, y: 0 }, // 起点
{ x: 200, y: 150 }, // 终点
- { x: 1, y: 1, z: 0, w: 1 }, // 黄色
+ { r: 1, g: 1, b: 0, a: 1 }, // 黄色
2 // 线宽
);
```
@@ -51,14 +51,14 @@ Draw.line(
Draw.rect(
{ x: 100, y: 100 }, // 中心位置
{ x: 80, y: 60 }, // 尺寸
- { x: 0, y: 0.5, z: 1, w: 0.5 }, // 半透明蓝色
+ { r: 0, g: 0.5, b: 1, a: 0.5 }, // 半透明蓝色
true // 填充(默认)
);
Draw.rectOutline(
{ x: 100, y: 100 },
{ x: 80, y: 60 },
- { x: 1, y: 0, z: 0, w: 1 }, // 红色
+ { r: 1, g: 0, b: 0, a: 1 }, // 红色
2 // 线宽
);
```
@@ -69,7 +69,7 @@ Draw.rectOutline(
Draw.circle(
{ x: 200, y: 200 }, // 中心
50, // 半径
- { x: 0, y: 1, z: 0, w: 1 }, // 绿色
+ { r: 0, g: 1, b: 0, a: 1 }, // 绿色
true, // 填充
32 // 段数
);
@@ -77,7 +77,7 @@ Draw.circle(
Draw.circleOutline(
{ x: 200, y: 200 },
50,
- { x: 1, y: 1, z: 1, w: 1 }, // 白色
+ { r: 1, g: 1, b: 1, a: 1 }, // 白色
1, // 线宽
32 // 段数
);
@@ -90,7 +90,7 @@ Draw.texture(
{ x: 300, y: 200 }, // 位置
{ x: 64, y: 64 }, // 尺寸
textureHandle,
- { x: 1, y: 1, z: 1, w: 1 } // 着色(默认白色)
+ { r: 1, g: 1, b: 1, a: 1 } // 着色(默认白色)
);
Draw.textureRotated(
@@ -98,7 +98,7 @@ Draw.textureRotated(
{ x: 64, y: 64 },
Math.PI / 4, // 旋转弧度
textureHandle,
- { x: 1, y: 1, z: 1, w: 1 }
+ { r: 1, g: 1, b: 1, a: 1 }
);
```
@@ -186,7 +186,7 @@ addSystem(defineSystem(
));
registerDrawCallback('debug-colliders', () => {
- const green = { x: 0, y: 1, z: 0, w: 0.5 };
+ const green = { r: 0, g: 1, b: 0, a: 0.5 };
for (const c of colliders) {
Draw.rectOutline(
{ x: c.x, y: c.y },
diff --git a/docs/astro/src/content/docs/zh/guides/editor-extensions.mdx b/docs/astro/src/content/docs/zh/guides/editor-extensions.mdx
index 2aee7b229..ee38d73aa 100644
--- a/docs/astro/src/content/docs/zh/guides/editor-extensions.mdx
+++ b/docs/astro/src/content/docs/zh/guides/editor-extensions.mdx
@@ -560,11 +560,11 @@ registerSettingsItem({
registerDrawCallback('origin-crosshair', () => {
if (!getSettingsValue('debug-overlay.showOrigin')) return;
const size = getSettingsValue<number>('debug-overlay.size');
- const red = { x: 1, y: 0, z: 0, w: 1 };
- const green = { x: 0, y: 1, z: 0, w: 1 };
+ const red = { r: 1, g: 0, b: 0, a: 1 };
+ const green = { r: 0, g: 1, b: 0, a: 1 };
Draw.line({ x: 0, y: 0 }, { x: size, y: 0 }, red, 2);
Draw.line({ x: 0, y: 0 }, { x: 0, y: size }, green, 2);
- Draw.circleOutline({ x: 0, y: 0 }, 4, { x: 1, y: 1, z: 1, w: 1 }, 1);
+ Draw.circleOutline({ x: 0, y: 0 }, 4, { r: 1, g: 1, b: 1, a: 1 }, 1);
});
```
diff --git a/docs/astro/src/content/docs/zh/guides/geometry.mdx b/docs/astro/src/content/docs/zh/guides/geometry.mdx
index e09d076a6..fa36c9598 100644
--- a/docs/astro/src/content/docs/zh/guides/geometry.mdx
+++ b/docs/astro/src/content/docs/zh/guides/geometry.mdx
@@ -106,7 +106,7 @@ import { registerDrawCallback, Draw, Geometry, Material, BlendMode } from 'eseng
const quad = Geometry.createQuad(100, 100);
const mat = Material.create({
shader: myShader,
- uniforms: { u_color: { x: 1, y: 0, z: 0, w: 1 } },
+ uniforms: { u_color: { r: 1, g: 0, b: 0, a: 1 } },
blendMode: BlendMode.Normal,
});
diff --git a/docs/astro/src/content/docs/zh/guides/materials.mdx b/docs/astro/src/content/docs/zh/guides/materials.mdx
index ab7142461..1c5297ca4 100644
--- a/docs/astro/src/content/docs/zh/guides/materials.mdx
+++ b/docs/astro/src/content/docs/zh/guides/materials.mdx
@@ -47,7 +47,7 @@ const mat = Material.create({
shader,
uniforms: {
u_time: 0,
- u_tint: { x: 1, y: 0, z: 0, w: 1 },
+ u_tint: { r: 1, g: 0, b: 0, a: 1 },
},
blendMode: BlendMode.Additive,
});
@@ -70,7 +70,7 @@ sprite.material = mat;
```typescript
Material.setUniform(mat, 'u_time', elapsed);
-Material.setUniform(mat, 'u_tint', { x: 1, y: 0.5, z: 0, w: 1 });
+Material.setUniform(mat, 'u_tint', { r: 1, g: 0.5, b: 0, a: 1 });
const time = Material.getUniform(mat, 'u_time');
```
@@ -82,6 +82,7 @@ const time = Material.getUniform(mat, 'u_time');
| number | `1.5` |
| Vec2 | `{ x: 0.5, y: 1.0 }` |
| Vec3 | `{ x: 1, y: 0, z: 0 }` |
+| Color | `{ r: 1, g: 1, b: 1, a: 1 }` |
| Vec4 | `{ x: 1, y: 1, z: 1, w: 1 }` |
| number[] | `[1, 2, 3, 4]` |
| TextureRef | `Material.tex(textureId, slot?)` |
@@ -116,7 +117,7 @@ const mode = Material.getBlendMode(mat);
```typescript
const instance = Material.createInstance(sourceMat);
-Material.setUniform(instance, 'u_tint', { x: 0, y: 1, z: 0, w: 1 });
+Material.setUniform(instance, 'u_tint', { r: 0, g: 1, b: 0, a: 1 });
```
## 着色器文件格式(.esshader)
diff --git a/docs/astro/src/content/docs/zh/guides/spine.mdx b/docs/astro/src/content/docs/zh/guides/spine.mdx
index df6e72142..bf20feafb 100644
--- a/docs/astro/src/content/docs/zh/guides/spine.mdx
+++ b/docs/astro/src/content/docs/zh/guides/spine.mdx
@@ -8,7 +8,7 @@ import { Aside } from '@astrojs/starlight/components';
`SpineAnimation` 组件播放 [Spine](http://esotericsoftware.com/) 骨骼动画。在场景编辑器中将它和 `LocalTransform` 一起添加到实体上。
<Aside type="note">
- 从 v0.3.0 起,Spine 使用独立的 WASM 模块(`spine38` / `spine42`),不再内置于引擎核心。在编辑器中通过 **Settings → Project → Spine Version** 选择版本(`3.8` 或 `4.2`),编辑器会自动加载对应的运行时,无需编写代码。
+ 从 v0.3.0 起,Spine 使用独立的 WASM 模块(`spine38` / `spine41` / `spine42`),不再内置于引擎核心。在编辑器中通过 **Settings → Project → Spine Version** 选择版本(`3.8`、`4.1` 或 `4.2`),编辑器会自动加载对应的运行时,无需编写代码。
</Aside>
## 属性
@@ -24,7 +24,7 @@ import { Aside } from '@astrojs/starlight/components';
| `playing` | boolean | `true` | 是否正在播放 |
| `flipX` | boolean | `false` | 水平翻转 |
| `flipY` | boolean | `false` | 垂直翻转 |
-| `color` | Vec4 | `{1, 1, 1, 1}` | 着色 RGBA |
+| `color` | Color | `{r:1, g:1, b:1, a:1}` | 着色 RGBA |
| `layer` | number | `0` | 渲染顺序 |
| `skeletonScale` | number | `1.0` | 骨骼缩放因子 |
| `material` | number | `0` | 材质 ID |
@@ -90,8 +90,8 @@ 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% 透明
+spine.color = { r: 1, g: 0, b: 0, a: 1 }; // 红色
+spine.color = { r: 1, g: 1, b: 1, a: 0.5 }; // 50% 透明
```
## 示例:角色控制器
diff --git a/docs/astro/src/content/docs/zh/guides/sprite.mdx b/docs/astro/src/content/docs/zh/guides/sprite.mdx
index 551e04d5d..5ca66e728 100644
--- a/docs/astro/src/content/docs/zh/guides/sprite.mdx
+++ b/docs/astro/src/content/docs/zh/guides/sprite.mdx
@@ -12,7 +12,7 @@ import { Aside } from '@astrojs/starlight/components';
| 属性 | 类型 | 默认值 | 说明 |
|------|------|--------|------|
| `texture` | number | `INVALID_TEXTURE` | 纹理句柄,无纹理 = 纯色 |
-| `color` | Vec4 | `{1, 1, 1, 1}` | 着色 RGBA(0–1) |
+| `color` | Color | `{r:1, g:1, b:1, a:1}` | 着色 RGBA(0–1) |
| `size` | Vec2 | `{32, 32}` | 宽高(像素) |
| `uvOffset` | Vec2 | `{0, 0}` | 纹理坐标偏移 |
| `uvScale` | Vec2 | `{1, 1}` | 纹理坐标缩放 |
@@ -49,8 +49,8 @@ addSystem(defineSystem(
`color` 属性对精灵着色。有纹理时,纹理颜色会与着色相乘。
```typescript
-sprite.color = { x: 1, y: 0, z: 0, w: 1 }; // 红色
-sprite.color = { x: 1, y: 1, z: 1, w: 0.5 }; // 50% 透明
+sprite.color = { r: 1, g: 0, b: 0, a: 1 }; // 红色
+sprite.color = { r: 1, g: 1, b: 1, a: 0.5 }; // 50% 透明
```
## 翻转
@@ -113,7 +113,7 @@ addSystem(defineSystem(
cmds.spawn()
.insert(Sprite, {
size: { x: 10, y: 10 },
- color: { x: 1, y: 1, z: 0, w: 1 }
+ color: { r: 1, g: 1, b: 0, a: 1 }
})
.insert(LocalTransform, {
position: { x: 0, y: 0, z: 0 }
diff --git a/docs/astro/src/content/docs/zh/guides/ui.mdx b/docs/astro/src/content/docs/zh/guides/ui.mdx
index aeabe2eb0..ea8aac69b 100644
--- a/docs/astro/src/content/docs/zh/guides/ui.mdx
+++ b/docs/astro/src/content/docs/zh/guides/ui.mdx
@@ -26,7 +26,7 @@ import { Aside } from '@astrojs/starlight/components';
| `content` | string | `''` | 显示的文本内容 |
| `fontFamily` | string | `'Arial'` | 字体名称 |
| `fontSize` | number | `24` | 字号(像素) |
-| `color` | Vec4 | `{1, 1, 1, 1}` | 文本颜色 RGBA(0–1) |
+| `color` | Color | `{r:1, g:1, b:1, a:1}` | 文本颜色 RGBA(0–1) |
| `align` | TextAlign | `Left` | 水平对齐方式 |
| `verticalAlign` | TextVerticalAlign | `Top` | 垂直对齐方式 |
| `wordWrap` | boolean | `true` | 启用自动换行 |