背景图与立绘的显示控制
图层系统基础
吉里吉里2 用图层(Layer)来管理画面元素。每个背景、立绘、UI 都是一个图层。图层有编号(layer number),编号大的在上面(后绘制)。
典型图层布局:
Layer 0 → 背景图(最底层)
Layer 1~3 → 角色立绘
Layer 4~5 → 特效层
Layer 6 → UI 层(名字框、对话框)
Layer 7 → 文字层(最顶层)
背景切换
基础用法
; 切换背景(淡入淡出 500ms)
[bg storage="bg/school.tlg" time=500]
; 瞬间切换(无动画)
[bg storage="bg/night.tlg" time=0]
; 切换并指定图层
[bg storage="bg/rain.tlg" layer=0 time=1000]
过渡效果
; 默认:淡出旧图 → 淡入新图
[bg storage="bg/next.tlg" time=500]
; 只做淡入(旧图直接消失,新图淡入)
[bg storage="bg/next.tlg" method="crossfade" time=500]
; 自定义过渡(溶解、百叶窗等,取决于 KAG 版本)
[bg storage="bg/next.tlg" method="dissolve" time=800]
清空背景
[bg clear layer=0 time=300]
立绘显示
基础用法
; 在图层 1 显示立绘(立绘一般是透明 PNG 或 TLG)
[chara storage="chara/hero.tlg" layer=1 time=300]
; 指定位置(left 或 center 或 right,也可以写像素坐标)
[chara storage="chara/hero.tlg" layer=1 position=center time=300]
[chara storage="chara/hero.tlg" layer=1 x=100 y=200 time=300]
; 指定缩放
[chara storage="chara/hero.tlg" layer=1 scale=1.2 time=300]
立绘切换
; 同一个角色换表情,用同一个图层覆盖
[chara storage="chara/hero_smile.tlg" layer=1 time=200]
立绘隐藏
; 淡出隐藏
[chara clear layer=1 time=300]
; 直接移除
[chara clear layer=1 time=0]
多层立绘
同时显示多个角色:
; 左边角色
[chara storage="chara/hero.tlg" layer=1 position=left time=300]
; 中间角色(叠在 hero 上面,layer 更大)
[chara storage="chara/heroine.tlg" layer=2 position=center time=300]
; 右边角色
[chara storage="chara/rival.tlg" layer=3 position=right time=300]
位置参数详解
| 参数 | 说明 | 示例 |
|---|---|---|
position | 预设位置 | left、center、right、top、bottom |
x / y | 像素坐标 | x=300 y=400 |
scale | 缩放倍率 | scale=1.2(120%) |
opacity | 不透明度 0~255 | opacity=128(半透明) |
visible | 初始可见性 | visible=false(先隐藏再显示) |
自定义图层
除了 bg 和 chara,可以用通用的 image 标签:
; 在图层 10 放一张装饰图
[image storage="img/flower.tlg" layer=10 x=500 y=300 time=300]
; 移除
[image clear layer=10 time=300]
动画效果
移动动画
; 立绘从左往右滑入
[tjs]
Layer.get(1).moveTo(800, 400, 1000); // 1秒内移动到 (800, 400)
抖动
; 整个画面抖动 500ms
[effect shake time=500 intensity=5]
闪白/闪黑
; 闪白
[effect flash color=white time=200]
; 闪黑(常见于场景切换)
[effect flash color=black time=500]
[bg storage="bg/new_scene.tlg" time=0]
[effect flash color=black time=500 reverse=true]
性能注意
- 同时活跃的图层太多(>15)可能影响低端机性能
- 大图(>1920x1080)预加载到内存更流畅:
Image.load("bg/school.tlg", true)第二个参数 preload=true - 切换场景时先清理上一组图层再加载下一组,避免显存堆积
特殊图层:文字层
文字层是独立于图形图层的,编号由 KAG 自动管理。不要用 bg/chara 标签的图层参数去碰文字层。