A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
docs: fix Assets API references from loadJson to fetchJson
esenginec097b9196823
diff --git a/docs/astro/src/content/docs/guides/assets.mdx b/docs/astro/src/content/docs/guides/assets.mdxindex 22b526198..ca8e2b686 100644--- a/docs/astro/src/content/docs/guides/assets.mdx+++ b/docs/astro/src/content/docs/guides/assets.mdx@@ -120,29 +120,22 @@ See [Prefabs](/docs/guides/prefabs/) for the full prefab API.| 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 |+| `fetchJson<T>(path)` | `Promise<T>` | Load and parse a JSON file |+| `fetchText(path)` | `Promise<string>` | Load a text file |+| `fetchBinary(path)` | `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');+const config = await assets.fetchJson<GameConfig>('assets/config.json');+const csv = await assets.fetchText('assets/levels.csv');+const data = await assets.fetchBinary('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 LoadingLoad all assets from an `AddressableManifest` in parallel with `loadAll`:```typescript-const manifest = await assets.loadJson('assets/addressable-manifest.json');+const manifest = await assets.fetchJson('assets/addressable-manifest.json');assets.setAddressableManifest(manifest);const bundle = await assets.loadAll(manifest);@@ -191,11 +184,7 @@ See [Materials & Shaders](/docs/guides/materials/) for the full material API and## 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 });-```+Typed load methods (`loadTexture`, `loadSpine`, `loadMaterial`, `loadPrefab`) cache by path. Loading the same path twice returns the cached result without a network request. Generic fetch methods (`fetchJson`, `fetchText`, `fetchBinary`) do not cache — each call fetches from the backend.## Base URL@@ -214,7 +203,7 @@ Absolute paths and full URLs are not affected by `baseUrl`.Load a scene file with all its referenced assets in a single call:```typescript-const sceneData = await assets.loadJson<SceneData>('assets/scenes/main.esscene');+const sceneData = await assets.fetchJson<SceneData>('assets/scenes/main.esscene');const entityMap = await assets.loadScene(world, sceneData);```@@ -222,7 +211,7 @@ const entityMap = await assets.loadScene(world, sceneData);## Embedded Assets-For Playable Ad builds, the editor's build pipeline automatically embeds all referenced assets as data URIs into the output bundle. At runtime, `assets.loadTexture()` / `assets.loadJson()` and other load calls resolve from the embedded data instead of fetching over the network — no code changes are needed.+For Playable Ad builds, the editor's build pipeline automatically embeds all referenced assets as data URIs into the output bundle. At runtime, `assets.loadTexture()` / `assets.fetchJson()` and other load calls resolve from the embedded data instead of fetching over the network — no code changes are needed.For custom builds, you can register embedded assets manually:@@ -278,7 +267,7 @@ The manifest is generated by the editor during build. At runtime, set it before```typescriptimport { Assets } from 'esengine';-const manifest = await assets.loadJson('assets/addressable-manifest.json');+const manifest = await assets.fetchJson('assets/addressable-manifest.json');assets.setAddressableManifest(manifest);```diff --git a/docs/astro/src/content/docs/zh/guides/assets.mdx b/docs/astro/src/content/docs/zh/guides/assets.mdxindex d0ba4dd06..b353d47b5 100644--- a/docs/astro/src/content/docs/zh/guides/assets.mdx+++ b/docs/astro/src/content/docs/zh/guides/assets.mdx@@ -120,29 +120,22 @@ const prefab = await assets.loadPrefab('prefabs/Enemy.esprefab');| 方法 | 返回值 | 说明 ||------|--------|------|-| `loadJson<T>(path, options?)` | `Promise<T>` | 加载并解析 JSON 文件 |-| `loadText(path, options?)` | `Promise<string>` | 加载文本文件 |-| `loadBinary(path, options?)` | `Promise<ArrayBuffer>` | 加载二进制文件 |+| `fetchJson<T>(path)` | `Promise<T>` | 加载并解析 JSON 文件 |+| `fetchText(path)` | `Promise<string>` | 加载文本文件 |+| `fetchBinary(path)` | `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');+const config = await assets.fetchJson<GameConfig>('assets/config.json');+const csv = await assets.fetchText('assets/levels.csv');+const data = await assets.fetchBinary('assets/tilemap.bin');```-### FileLoadOptions--| 选项 | 类型 | 说明 |-|------|------|------|-| `baseUrl` | string | 覆盖此请求的基础 URL |-| `noCache` | boolean | 跳过缓存,始终从网络获取 |-## 批量加载使用 `loadAll` 从 `AddressableManifest` 并行加载所有资源:```typescript-const manifest = await assets.loadJson('assets/addressable-manifest.json');+const manifest = await assets.fetchJson('assets/addressable-manifest.json');assets.setAddressableManifest(manifest);const bundle = await assets.loadAll(manifest);@@ -191,11 +184,7 @@ sprite.material = loaded.handle;## 缓存机制-所有加载方法按路径缓存。同一路径加载两次会直接返回缓存结果,不会再次发起网络请求。使用 `noCache` 选项跳过缓存:--```typescript-const fresh = await assets.loadJson('assets/config.json', { noCache: true });-```+类型化加载方法(`loadTexture`、`loadSpine`、`loadMaterial`、`loadPrefab`)按路径缓存。同一路径加载两次会直接返回缓存结果,不会再次发起网络请求。通用获取方法(`fetchJson`、`fetchText`、`fetchBinary`)不缓存——每次调用都从后端获取。## 基础 URL@@ -214,7 +203,7 @@ const tex = await assets.loadTexture('sprites/player.png');通过一次调用加载场景文件及其所有引用的资源:```typescript-const sceneData = await assets.loadJson<SceneData>('assets/scenes/main.esscene');+const sceneData = await assets.fetchJson<SceneData>('assets/scenes/main.esscene');const entityMap = await assets.loadScene(world, sceneData);```@@ -222,7 +211,7 @@ const entityMap = await assets.loadScene(world, sceneData);## 嵌入式资源-对于 Playable Ad 构建,编辑器的构建流程会自动将所有引用的资源以 data URI 形式嵌入输出包中。运行时 `assets.loadTexture()` / `assets.loadJson()` 等加载调用会直接从嵌入数据解析,无需网络请求,也无需修改任何代码。+对于 Playable Ad 构建,编辑器的构建流程会自动将所有引用的资源以 data URI 形式嵌入输出包中。运行时 `assets.loadTexture()` / `assets.fetchJson()` 等加载调用会直接从嵌入数据解析,无需网络请求,也无需修改任何代码。对于自定义构建,可以手动注册嵌入式资源:@@ -278,7 +267,7 @@ const bundle = await assets.loadGroup('level-1');```typescriptimport { Assets } from 'esengine';-const manifest = await assets.loadJson('assets/addressable-manifest.json');+const manifest = await assets.fetchJson('assets/addressable-manifest.json');assets.setAddressableManifest(manifest);```