变换与ATL动画
本页属于 GenPy Ren'Py 学习路线。教程内容面向 Ren'Py 8.x,并在页面末尾连接到 GenPy 的对应工作流。
学习目标
- 了解“变换与ATL动画”在 Ren'Py 项目中的用途。
- 能在一个最小项目里验证本章相关语法或工作流。
- 知道发布前需要检查的常见风险,并能在 GenPy 中继续维护。
核心语法
transformatlineareaseparallelrepeat
可运行示例
text
transform left_in:
xalign 0.0 yalign 1.0
alpha 0.0
linear 0.5 alpha 1.0 # 0.5 秒淡入
transform bounce:
yoffset 0
block:
ease 0.5 yoffset -30
ease 0.5 yoffset 0
repeat教程正文
Transform 决定一个可显示物“在哪、多大、多透明、怎么转”。ATL(Animation and Transformation Language) 是写动画/变换的专用语法块,用来做移动、缩放、旋转、淡入淡出、循环动画等。
1. 变换属性(Transform Properties)
常用属性(完整见官方 transform-properties):
| 属性 | 含义 |
|---|---|
xpos / ypos | 像素位置(左上为基准,可用 0~1 比例) |
xalign / yalign | 对齐锚点(0=左/上,0.5=中,1=右/下) |
align (x, y) | 同时设 xalign/yalign |
pos (x, y) | 同时设 xpos/ypos |
xanchor / yanchor | 自身锚点 |
xoffset / yoffset | 像素偏移 |
zoom | 等比缩放(1.0 原始) |
xzoom / yzoom | 单轴缩放(负值=翻转) |
rotate | 旋转角度(度) |
alpha | 不透明度(0 透明 ~ 1 不透明) |
crop | 裁剪 (x, y, w, h) |
zorder | 层级 |
blur | 模糊半径 |
2. 定义 transform
text
transform left_in:
xalign 0.0 yalign 1.0
alpha 0.0
linear 0.5 alpha 1.0 # 0.5 秒淡入
transform bounce:
yoffset 0
block:
ease 0.5 yoffset -30
ease 0.5 yoffset 0
repeat应用:
text
show eileen happy at left_in
show logo at bounce3. ATL 基础:插值语句
在 transform、show ... :、image ... : 后缩进写 ATL。每一行设定目标值,配合插值函数 + 时长:
text
show eileen happy:
xalign 0.0 # 立即设到左边
linear 1.0 xalign 1.0 # 1 秒内匀速移到右边
ease 1.0 xalign 0.5 # 1 秒内缓动到中间插值函数(warper)
| 写法 | 效果 |
|---|---|
linear t | 匀速 |
ease t | 两端缓动(慢-快-慢) |
easein t | 进入缓动 |
easeout t | 退出缓动 |
<warper> t prop value | 在 t 秒内把属性插值到目标 |
不带函数直接写属性=瞬间生效。
4. pause / repeat / block
text
transform blink:
alpha 1.0
pause 0.5 # 停 0.5 秒
alpha 0.0
pause 0.5
repeat # 无限循环(可 repeat 3 限定次数)block: 把若干步打包,便于配合 repeat/parallel:
text
transform complex:
alpha 0.0
linear 1.0 alpha 1.0
block:
linear 1.0 xalign 1.0
linear 1.0 xalign 0.0
repeat5. parallel(并行动画)
多个属性同时各自动画:
text
transform fly_in:
parallel:
linear 1.0 xalign 0.5
parallel:
linear 1.0 yalign 0.5
parallel:
linear 1.0 alpha 1.06. 运动路径:knot / 圆周
text
transform arc:
linear 2.0 align (0.5, 1.0) knot (0.0, .33) knot (1.0, .66) # 贝塞尔路径
transform spin_path:
linear 2.0 yalign 0.0 clockwise circles 3 # 顺时针绕 3 圈7. 旋转、缩放、翻转
text
transform spin:
rotate 0
linear 2.0 rotate 360
repeat
show eileen happy at flip # 内置左右翻转(xzoom -1)
transform big:
zoom 1.0
ease 0.5 zoom 1.38. on 事件(不同状态动画)
on 针对状态(show/hide/replace 等)定义动画:
text
transform appear:
on show:
alpha 0.0
linear 0.3 alpha 1.0
on hide:
linear 0.3 alpha 0.09. 带参数的 transform
text
transform move_to(x):
linear 0.5 xalign x
show eileen at move_to(0.8)10. 在 show 时叠加多个 transform
text
show eileen happy at left, bounce # 先定位再弹跳常见坑
- ATL 里不写插值函数=瞬间;要动画必须
linear/ease + 时长。 repeat必须在block:/顶层循环段末尾,否则只跑一次。xalign是对齐(0~1),xpos是位置(像素或比例),别混。- 性能:大量
blur/逐帧动画在低端机/Web 上较吃力,适度使用。
官方参考
- ATL:https://www.renpy.org/doc/html/atl.html
- 变换属性:https://www.renpy.org/doc/html/transform_properties.html
在 GenPy 里怎么做
- 在 GenPy 的代码模式中维护相关 .rpy 文件,先保持语法清晰,再逐步加入本章功能。
- 用故事图谱、变量、校验或演出编辑器把“能运行”提升到“可维护”。
- 导出前结合 Ren'Py Lint 和 GenPy 校验结果,确认脚本、素材和发布路径一致。
推荐继续阅读:
