Skip to content

变换与ATL动画 ​

本页属于 GenPy Ren'Py 学习路线。教程内容面向 Ren'Py 8.x,并在页面末尾连接到 GenPy 的对应工作流。

学习目标 ​

  • 了解“变换与ATL动画”在 Ren'Py 项目中的用途。
  • 能在一个最小项目里验证本章相关语法或工作流。
  • 知道发布前需要检查的常见风险,并能在 GenPy 中继续维护。

核心语法 ​

  • transform
  • at
  • linear
  • ease
  • parallel
  • repeat

可运行示例 ​

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 bounce

3. 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
        repeat

5. 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.0

6. 运动路径: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.3

8. 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.0

9. 带参数的 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 上较吃力,适度使用。

官方参考 ​

在 GenPy 里怎么做 ​

  • 在 GenPy 的代码模式中维护相关 .rpy 文件,先保持语法清晰,再逐步加入本章功能。
  • 用故事图谱、变量、校验或演出编辑器把“能运行”提升到“可维护”。
  • 导出前结合 Ren'Py Lint 和 GenPy 校验结果,确认脚本、素材和发布路径一致。

推荐继续阅读:

Built for GenPy creators.