MOD 制作教程 🏠 主页

八、.r 素材格式详解

.r 是 MOD 系统新建的脚本素材格式,用纯文本描述一张图由哪些图形组成,无需外部图片文件。一个 .r 文件可以包含多个素材(多个 [素材名] 段),渲染时按 TILE 等比缩放。

8.1 完整示例

; 火焰坦克 .r 素材(一个文件包含两个素材)
[flameTank]
size=16x16
rect x=-6 y=-8 w=12 h=10 fill=#4a2a12 stroke=#1a0e04
ellipse cx=6 cy=-10 rx=2 ry=3 fill=#d86a2a
triangle x1=6 y1=-10 x2=12 y2=-10 x3=9 y3=-16 fill=#e04b3a
line x1=-6 y1=-2 x2=-9 y2=-6 stroke=#1a0e04

[flameTurret]
size=8x8
circle cx=0 cy=0 r=3 fill=#8a4a1a
规则:每个 [素材名] 段 = 一个素材。无段时默认素材名 = 文件名(去 .r 扩展名)。size=WxH 声明逻辑尺寸,渲染时坐标按 画布尺寸 ÷ size 缩放。

8.2 绘制指令

指令行格式:op 键=值 键=值 ...。数值自动转数字,颜色字符串保留。

rect — 矩形。
字段:x y w h fill stroke lineWidth。左上角坐标 + 宽高。
ellipse — 椭圆。
字段:cx cy rx ry fill stroke lineWidth。中心坐标 + 两个半径。
circle — 圆。
字段:cx cy r fill stroke lineWidth。
triangle — 三角形。
字段:x1 y1 x2 y2 x3 y3 fill stroke lineWidth。三个顶点。
line — 线段。
字段:x1 y1 x2 y2 stroke lineWidth。必填 stroke。
poly — 多边形。
字段:pts="x,y;x,y;..." fill stroke lineWidth。pts 用分号分隔的坐标对。

通用字段

字段说明
fill=#hex填充色(可选,省略则不填充)
stroke=#hex描边色(可选,省略则不描边)
lineWidth=number描边宽度(默认 1)
alpha=0~1整条指令透明度(可选)

8.3 常见形状写法

; 车身
rect x=-8 y=-6 w=16 h=10 fill=#5a5a6a stroke=#1a1a2a
; 履带
rect x=-8 y=4 w=16 h=3 fill=#2a2a3a
; 炮塔(中心圆)
circle cx=0 cy=-4 r=4 fill=#7a7a8a
; 炮管(细线)
line x1=0 y1=-4 x2=10 y2=-4 stroke=#1a1a2a lineWidth=2
; 炮口火焰(三角形)
triangle x1=10 y1=-5 x2=14 y2=-4 x3=10 y3=-3 fill=#e8a020

8.4 如何在 MOD 中使用

  1. 把 .r 文件放入包内 res/(如 res/flameTank.r);
  2. 在 mod.ini 的 res= 字段列出:res=flameTank.r;
  3. 单位/建筑的 art=flameTank 即自动使用该 .r 素材;
  4. 若 .r 内使用 [其他名] 段,则 art=其他名 引用对应段。
坐标系统:原点(0,0)位于素材中心,向上为负 Y。渲染时整个画布 = 素材逻辑尺寸 × 缩放,自动居中。负数坐标完全正常。
渲染优先级:.r 素材 最高,会覆盖 PNG 与程序化绘制。想保留官方外观时不要定义同名 artKey 的 .r 素材。