Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

Commit

Permalink
docs: translate preload.md to chinese
Browse files Browse the repository at this point in the history
  • Loading branch information
xs10l3 committed Aug 10, 2024
1 parent c37dce9 commit 0f9f9b3
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions docs/content/zh/basic/preload.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
title: 资源预加载
---

# 资源预加载

资源预加载是一个非常关键的概念,主要用于提前加载动画所需要的静态资源。预加载的资源均可以在全局变量 `$source` 中找到.

## 字体预加载

```javascript
await useFont(url)
```

在这,`url` 表示字体文件的位置,并将返回一个 `ArrayBuffer` 对象。之后,您可以在 `Text` 中使用它:

```javascript
root.add(new Text('Hello Newcar'))
```

但是由于 CanvasKit-WASM 不支持 CSS 字体,因此您需要自己准备字体文件。

## 图片预加载

```javascript
const image = await useImage(url)
```

然后,您可以在 `ImageWidget`中使用它:

```javascript
root.add(new ImageWidget(image))
```

0 comments on commit 0f9f9b3

Please sign in to comment.