This repository has been archived by the owner on Sep 8, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main'
- Loading branch information
Showing
6 changed files
with
2,007 additions
and
2,046 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<template> | ||
<canvas ref="canvas" width="200" height="300"></canvas> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import * as nc from 'newcar' | ||
import { onMounted, ref } from 'vue' | ||
const canvas = ref<HTMLCanvasElement>() | ||
onMounted(async () => { | ||
const engine = await new nc.CarEngine().init('https://unpkg.com/canvaskit-wasm@latest/bin/canvaskit.wasm') | ||
const app = engine.createApp(canvas.value!).setBackgroundColor('transparent') | ||
const root = new nc.Circle(100, { | ||
x: 100, | ||
y: 100 | ||
}) | ||
const scene = nc.createScene(root) | ||
app.checkout(scene) | ||
app.play() | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--- | ||
title: 颜色系统 | ||
--- | ||
|
||
# 颜色系统 | ||
|
||
Newcar 中的 Widget 对象可以设置为你喜欢的任何颜色,这些颜色由 `Color` 对象管理。目前,有三种设置颜色的方法,并且在未来的版本中,我们将引入渐变和其他颜色特性。 | ||
|
||
## 直接引用 | ||
|
||
这种方法只能支持两种颜色 - 黑色和白色。 | ||
|
||
```javascript | ||
const rect = new Rect([0, 0], [100, 100], { | ||
style: { | ||
fillColor: Color.WHITE, | ||
border: true, | ||
borderColor: Color.BLACK | ||
} | ||
}) | ||
``` | ||
|
||
## 使用颜色名称字符串 | ||
|
||
```javascript | ||
const RED = Color.parse('red') | ||
``` | ||
|
||
颜色名称字符串解析支持所有 CSS 支持的颜色名称。 | ||
|
||
## RGBA | ||
|
||
```javascript | ||
Color.rgba(255, 255, 255, 0.5) | ||
``` | ||
|
||
## 转换 | ||
|
||
你可以将 `Color` 对象转换为各种形式。 | ||
|
||
### `toString()` | ||
|
||
你可以使用这个函数将 `Color` 转换为 CSS 颜色字符串。 | ||
|
||
### `toFloat4()` | ||
|
||
你可以使用这个函数将 `Color` 转换为 Skia 颜色。 | ||
|
||
## 更多 | ||
|
||
你可以访问 [https://apis.newcarjs.org/classes/newcar.color](https://apis.newcarjs.org/classes/newcar.color) 获取更多 API 信息。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
title: 父子组件 | ||
--- | ||
|
||
# 父子组件 | ||
|
||
In `newcar`, objects can be nested using the `children` property. Here's how to add them: | ||
|
||
```javascript | ||
const child = new $.Circle(200, { | ||
x: 200, | ||
y: 300 | ||
}) | ||
|
||
const father = new $.Circle(300, { | ||
x: 100, | ||
y: 200 | ||
}) | ||
|
||
// Add child Widget | ||
father.add(child) | ||
``` | ||
|
||
In this case, the coordinates `(200, 300)` of `child` are not relative to the top-left corner of the canvas, but rather to the position of its parent component. | ||
|
||
:::tip | ||
In addition, parent-child components follow the principle of **"child follows parent, parent does not follow child"**. This means that when the parent component moves, the child component moves with it. When the child component moves, the parent component remains still. | ||
|
||
With this feature, you can set up a background and make objects in the scene "child objects" of the background, so that when you manipulate the character's movement, the background moves backwards. | ||
::: | ||
|
||
:::info | ||
Besides coordinates, **rotation angle** and **scaling ratio** also follow the parent-child component principle. | ||
|
||
> The rotation angle here refers to the rotation angle of the entire coordinate system relative to the parent component, not the rotation angle value of each component. | ||
::: | ||
|
||
However, storing objects in variables is both cumbersome and inefficient, so after version 0.7.0, we recommend using chain syntax: | ||
|
||
```javascript | ||
const root = new Widget().add(new Circle(200).setUpdate((elapsed, widget) => {})) | ||
``` |
Oops, something went wrong.