Skip to content

Commit 40d6c90

Browse files
author
Hardy--Lee
committed
docs: add animation reference
1 parent e10afa9 commit 40d6c90

4 files changed

Lines changed: 120 additions & 2 deletions

File tree

src/.vuepress/sidebar/zh.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export const zhSidebar = sidebar({
9999
prefix: "others/",
100100
children:[
101101
"transform-reference",
102+
"animation-reference",
102103
]
103104
},
104105
],

src/script-reference/commands/setAnimation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
## 语句内容
66

77
填写自定义动画名称,驱动指定目标的舞台对象执行多段动画。
8-
详情请见[自定义动画](../../webgal-script/animation.md#自定义动画)
8+
详情请见[自定义动画](../../webgal-script/animation.md#自定义动画)[动画参考](../others/animation-reference.md)
99

1010
:::info
1111
如果您想直接在脚本里设置多段动画,请使用 [setTempAnimation](setTempAnimation.md) 命令。

src/script-reference/commands/setTempAnimation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## 语句内容
66

7-
`setAnimation` 读取动画文件不同,`setTempAnimation` 允许用户直接在代码里定义多段动画。
7+
`setAnimation` 读取动画文件不同,`setTempAnimation` 允许用户直接在代码里定义多段动画,详见[动画参考](../others/animation-reference.md)
88
语句内容格式为动画文件的单行形式,即 `[{},{},{}]`
99

1010
:::info
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# 动画参考
2+
3+
WebGAL 支持设置连续的 [变换效果](../others/transform-reference.md) ,从而实现多段动画。
4+
5+
一个变换效果对象如
6+
``` json
7+
{
8+
"position": {
9+
"x":-500,
10+
"y":20
11+
},
12+
"rotation":0.3,
13+
"blur":10
14+
}
15+
```
16+
17+
一个动画片段对象则是在变换效果对象的基础上,添加了一些其他属性,如持续时间等
18+
``` json
19+
{
20+
"position": {
21+
"x":-500,
22+
"y":20
23+
},
24+
"rotation":0.3,
25+
"blur":10,
26+
"duration":500,
27+
"ease":"easeInOut"
28+
}
29+
```
30+
31+
多个动画片段对象可以组成一个动画
32+
``` json
33+
[
34+
{
35+
"duration":0
36+
},
37+
{
38+
"position": {
39+
"x":-500,
40+
"y":20
41+
},
42+
"duration":500
43+
},
44+
{
45+
"rotation":0.3,
46+
"duration":300
47+
},
48+
{
49+
"blur":10,
50+
"duration":200
51+
}
52+
]
53+
```
54+
55+
除了一些必要的属性外(如 duration),动画片段对象的很多属性都可以省略,WebGAL 会根据情况使用默认值或者继承现有值来补全。
56+
57+
:::info
58+
继承现有值的「现有值」是指,在执行动画前,目标对象的变换效果快照,而不是上一个动画片段的结束状态。
59+
:::
60+
61+
```webgal
62+
; 立绘对象初始坐标为 (-500,0)
63+
changeFigure:character_a/normal.png -id=aaa -transform={"position":{"x":-500,"y":0}};
64+
; 多段动画的坐标依次为
65+
; (-500,0) -> (500,0) -> (-500,20)
66+
setTempAnimation:[{"duration":0},{"position":{"x":500},"duration":500},{"position":{"y":20},"duration":500}] -target=aaa;
67+
```
68+
69+
动画里的第一个片段为起始状态,通常 duration 设为 0 即可,即使设置了大于 0 的数,也不会有动画效果。
70+
您仍然可以为第一个片段设置变换效果属性,这样可以在动画开始时直接跳转到指定状态。
71+
72+
```webgal
73+
; 立绘对象初始坐标为 (-500,0)
74+
changeFigure:character_a/normal.png -id=aaa;
75+
; 从左走到右,动画开始时直接跳转到左边
76+
setTempAnimation:[{"position":{"x":-500},"duration":0},{"position":{"x":500},"duration":1000}] -target=aaa;
77+
```
78+
79+
## 参数
80+
81+
### duration
82+
- 数字
83+
- 单位:毫秒
84+
- 必填
85+
86+
每个动画片段的持续时间。
87+
88+
```webgal
89+
changeFigure:1/open_eyes.png -id=aaa;
90+
setTempAnimation:[{"position":{"x":-500},"duration":0},{"position":{"x":500},"duration":1000}] -target=aaa;
91+
```
92+
93+
### ease
94+
- 字符串
95+
96+
填写缓动类型,控制动画的缓动效果,默认值为 `easeInOut`,可选值包括
97+
- `linear`:线性
98+
- `easeIn`:缓入
99+
- `easeOut`:缓出
100+
- `easeInOut`:缓入缓出
101+
- `circIn`:圆形缓入
102+
- `circOut`:圆形缓出
103+
- `circInOut`:圆形缓入缓出
104+
- `backIn`:起点回弹
105+
- `backOut`:终点回弹
106+
- `backInOut`:起止回弹
107+
- `bounceIn`:起点弹跳
108+
- `bounceOut`:终点弹跳
109+
- `bounceInOut`:起止弹跳
110+
- `anticipate`:预先反向
111+
112+
任何其他字符串都会回退到默认值。
113+
114+
```webgal
115+
changeFigure:1/open_eyes.png -id=aaa;
116+
setTempAnimation:[{"position":{"x":-500},"duration":0},{"position":{"x":500},"duration":1000,"ease":"bounceOut"}] -target=aaa;
117+
```

0 commit comments

Comments
 (0)