立绘与界面交互特效
本页属于 GenPy Ren'Py 学习路线。教程内容面向 Ren'Py 8.x,并在页面末尾连接到 GenPy 的对应工作流。
学习目标
- 了解“立绘与界面交互特效”在 Ren'Py 项目中的用途。
- 能在一个最小项目里验证本章相关语法或工作流。
- 知道发布前需要检查的常见风险,并能在 GenPy 中继续维护。
核心语法
speaker highlightidle breathinghover zoombutton feedbackATLscreen action
可运行示例
text
transform bright:
matrixcolor BrightnessMatrix(0.0)
linear 0.25 matrixcolor BrightnessMatrix(0.0) # 正常亮度
transform dim:
linear 0.25 matrixcolor BrightnessMatrix(-0.35) # 压暗(也可配合 zoom 0.97 后移)
label talk:
show eileen happy at bright
show lucy normal at dim
e "这句话是我说的。"
show eileen happy at dim
show lucy normal at bright
l "现在轮到我了。"教程正文
让角色立绘与 UI“有生命”:说话者高亮、待机时轻微呼吸、按钮悬停放大、按下回弹。 这些细节大幅提升画面的精致感与沉浸感。
1. 说话者高亮 / 非说话者变暗
最稳妥的做法:定义 bright/dim 两个 transform,谁说话谁亮、其余变暗。
text
transform bright:
matrixcolor BrightnessMatrix(0.0)
linear 0.25 matrixcolor BrightnessMatrix(0.0) # 正常亮度
transform dim:
linear 0.25 matrixcolor BrightnessMatrix(-0.35) # 压暗(也可配合 zoom 0.97 后移)
label talk:
show eileen happy at bright
show lucy normal at dim
e "这句话是我说的。"
show eileen happy at dim
show lucy normal at bright
l "现在轮到我了。"进阶可结合“说话者上移/放大、其他下移/缩小”增强焦点:
text
transform speaker:
linear 0.2 zoom 1.0 yoffset 0 matrixcolor BrightnessMatrix(0.0)
transform listener:
linear 0.2 zoom 0.96 yoffset 10 matrixcolor BrightnessMatrix(-0.3)想自动化“谁说话谁亮”,可用
Character的回调统一切换,但手动at切换最直观可控、零猜测。
2. 待机呼吸 / 漂浮(Idle Motion)
让站着的立绘轻微起伏,避免“纸片人”僵硬感:
text
transform breathe:
block:
ease 2.0 yoffset -6
ease 2.0 yoffset 0
repeat
transform sway: # 轻微左右摇摆
block:
ease 3.0 xoffset 8
ease 3.0 xoffset -8
repeat
show eileen happy at breathe呼吸 + 入场可组合:先淡入,再进入循环呼吸(用 on show 事件,见第 11/30 章)。
3. 悬停放大按钮(Hover Zoom)
用 ATL 的 on hover, idle 事件,让按钮在鼠标悬停时放大、移开时回弹:
text
transform pulse_button:
on hover, idle:
linear 0.25 zoom 1.25
linear 0.25 zoom 1.0
transform hover_grow:
on idle:
linear 0.15 zoom 1.0
on hover:
linear 0.15 zoom 1.1在 screen 中应用到按钮:
text
screen main_menu():
textbutton "开始游戏" action Start() at hover_grow
imagebutton:
idle "btn_idle.png"
hover "btn_hover.png"
at hover_grow
action Start()4. 按下回弹反馈(Press Feedback)
点击瞬间缩小再弹回,给操作“手感”:
text
transform press_fx:
on hover:
linear 0.1 zoom 1.08
on idle:
linear 0.1 zoom 1.0
on selected_idle:
zoom 1.0或用样式三态(idle/hover/selected)直接换图/位移,是最常规的按钮反馈方式。
5. 进出场动画(立绘登场更有戏)
text
transform enter_left:
xoffset -200 alpha 0.0
easein 0.4 xoffset 0 alpha 1.0
transform exit_right:
easeout 0.4 xoffset 200 alpha 0.0
label scene:
show eileen happy at enter_left
e "我来了!"
hide eileen
# 退场:show ... at exit_right 后再 hide,或用 ATL on hide6. 焦点景深(突出立绘、虚化背景)
结合第 31 章:背景 blur + 压暗,立绘清晰,自然形成焦点。
text
transform bg_defocus:
blur 6.0 matrixcolor BrightnessMatrix(-0.08)
show bg room at bg_defocus
show eileen happy at bright常见坑
on hover/idle是 ATL 事件,按钮/可获得焦点的可显示物才会触发。- 呼吸/摇摆等循环动画用
block: ... repeat,注意ease时长别太短(会显得抽搐)。 - 多个立绘同时高亮切换时,统一用同一组
bright/dimtransform,过渡时长保持一致。 - 大量立绘同时做逐帧 matrixcolor/blur 会有性能开销,移动端注意控制数量。
- 自动“说话者高亮”若用回调,务必处理“旁白/无立绘说话”的情况,否则可能误暗全部。
官方参考
- ATL 事件(on hover/idle/show/hide):https://www.renpy.org/doc/html/atl.html
- 屏幕语言与按钮:https://www.renpy.org/doc/html/screens.html
- 变换属性(zoom/offset/alpha/blur/matrixcolor):https://www.renpy.org/doc/html/transform_properties.html
在 GenPy 里怎么做
- 在 GenPy 的代码模式中维护相关 .rpy 文件,先保持语法清晰,再逐步加入本章功能。
- 用故事图谱、变量、校验或演出编辑器把“能运行”提升到“可维护”。
- 导出前结合 Ren'Py Lint 和 GenPy 校验结果,确认脚本、素材和发布路径一致。
推荐继续阅读:
