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

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
sheepbox8646 committed Aug 10, 2024
2 parents fae9d91 + 0f9f9b3 commit 50953e2
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 25 deletions.
2 changes: 2 additions & 0 deletions docs/content/basic/animation.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ title: Property Animation

<script setup lang="ts">
import { default as DemoDiscolorate } from './demos/animation/discolorate.vue'
import { default as DemoFadeIn} from './demos/animation/fadeIn.vue'
</script>

# Animation
Expand Down Expand Up @@ -67,6 +68,7 @@ new Circle(100)
)
)
```
<DemoFadeIn/>

## change property

Expand Down
47 changes: 22 additions & 25 deletions docs/content/basic/demos/animation/discolorate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,35 @@ import * as nc from 'newcar'
import { onMounted, ref } from 'vue'
const canvas = ref<HTMLCanvasElement>()
const engine = await new nc.CarEngine().init('https://unpkg.com/canvaskit-wasm@latest/bin/canvaskit.wasm')
const app = engine.createApp(canvas.value!).setBackgroundColor('transparent')
async function create_app() {
const engine = await new nc.CarEngine().init('https://unpkg.com/canvaskit-wasm@latest/bin/canvaskit.wasm')
const app = engine.createApp(canvas.value!).setBackgroundColor('transparent')
return app
}
const app = create_app()
onMounted(async () => {
const root = new nc.Circle(100,{
x:100,
y:100
const root = new nc.Circle(100, {
x: 100,
y: 100
})
.animate(
nc.parallel(
nc.create().withAttr({ duration: 1 }),
// nc.discolorate().withAttr({ duration: 1, to: nc.Color.parse('skyblue') })
.animate(
nc.parallel(
nc.create().withAttr({ duration: 1 }),
// nc.discolorate().withAttr({ duration: 1, to: nc.Color.fromName('skyblue') })
)
)
)
const scene = nc.createScene(root)
app.checkout(scene)
; (await app).checkout(scene)
})
function play(){
app.play()
async function play() {
(await app).play();
}
</script>

<template>
<div class="div">
<button calss="bottom" @click.once="play">play</button>
<canvas ref="canvas" width="200" height="300"></canvas>
</div>
</template>

<style scoped lang="css">
.div{
}
</style>
<button @click="play()">run</button>
<canvas ref="canvas" width="200" height="300"></canvas>
</template>
40 changes: 40 additions & 0 deletions docs/content/basic/demos/animation/fadeIn.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<script setup lang="ts">
import * as nc from 'newcar'
import { onMounted, ref } from 'vue'
const canvas = ref<HTMLCanvasElement>()
async function create_app() {
const engine = await new nc.CarEngine().init('https://unpkg.com/canvaskit-wasm@latest/bin/canvaskit.wasm')
const app = engine.createApp(canvas.value!).setBackgroundColor('transparent')
return app
}
const app = create_app()
onMounted(async () => {
const root = new nc.Circle(100, {
x: 100,
y: 100
})
.animate(
nc.parallel(
nc.sequence(
nc.create().withAttr({ duration: 0.5 }),
nc.fadeIn().withAttr({ duration: 0.5 })
),
// nc.discolorate().withAttr({ duration: 1, to: nc.Color.parse('skyblue') })
)
)
const scene = nc.createScene(root)
; (await app).checkout(scene)
})
async function play() {
(await app).play()
}
</script>

<template>
<button @click="play()">run</button>
<canvas ref="canvas" width="200" height="300"></canvas>
</template>
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 50953e2

Please sign in to comment.