create-pixifact 0.15.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -0
- package/dist/createPixifactProject.js +19 -0
- package/dist/index.js +14 -1
- package/dist/skills/pixifact/SKILL.md +106 -0
- package/dist/skills/pixifact/agents/openai.yaml +4 -0
- package/dist/skills/pixifact/references/runtime-observation.md +89 -0
- package/dist/skills/pixifact/references/scene-authoring-decisions.md +118 -0
- package/dist/skills/pixifact/references/scene-hierarchy-patterns.md +292 -0
- package/dist/skills/pixifact/references/scene-objects.md +585 -0
- package/dist/skills/pixifact/references/scene-script-patterns.md +312 -0
- package/package.json +2 -2
- package/templates/minimal/package.json +4 -2
|
@@ -0,0 +1,585 @@
|
|
|
1
|
+
# Pixifact Scene Objects
|
|
2
|
+
|
|
3
|
+
本文件随 Pixifact skill 安装,用于下游项目离线查阅 `.scene` 可写对象和属性。新建 Scene、添加节点、修改布局、设置对象属性、使用子 Scene / slot / event / structured prop 时先读本文件;最终以 `pixifact scene validate` 为准。
|
|
4
|
+
|
|
5
|
+
## 基本结构
|
|
6
|
+
|
|
7
|
+
每个 `.scene` 文件必须以 `<Scene>` 为根:
|
|
8
|
+
|
|
9
|
+
```xml
|
|
10
|
+
<Scene name="Main" width="750" height="1334">
|
|
11
|
+
<Image id="background" texture="assets/bg/forest.png" left="0" right="0" top="0" bottom="0" fit="cover" />
|
|
12
|
+
<VBoxContainer id="menu" horizontal="0" vertical="0" gap="16" alignX="center">
|
|
13
|
+
<Text id="title" text="Adventure" fontSize="42" fill="#ffffff" />
|
|
14
|
+
</VBoxContainer>
|
|
15
|
+
</Scene>
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
`<Scene>` 只作为文件根,运行时根节点是同名 Scene 脚本类实例。根标签常用属性:
|
|
19
|
+
|
|
20
|
+
| 属性 | 类型 | 说明 |
|
|
21
|
+
| --- | --- | --- |
|
|
22
|
+
| `name` | string | 必填。必须与同目录同 basename 的 `.ts` 文件中的 `@scene()` class 名一致。 |
|
|
23
|
+
| `width` | number | 可选。Scene 设计宽度。 |
|
|
24
|
+
| `height` | number | 可选。Scene 设计高度。 |
|
|
25
|
+
|
|
26
|
+
根标签可设置其他 `Group` 通用属性。配对脚本声明的公开 `@prop` 可在根标签使用 `default.<prop>="值"` 设置 Editor 默认值;结构化字段用 `default.<prop>.<field>="值"`。取值顺序为实例显式传值、`.scene` 默认值、脚本 `@prop` 默认值,结构化字段逐个合并;不用改脚本。易混淆的字符串字面值请加 XML 转义引号,例如 `default.label=""true""`。
|
|
27
|
+
|
|
28
|
+
根和普通 Pixi 节点可用 `on:pointertap="actionName"` 绑定原生事件,支持 `pointertap`、`pointerdown`、`pointerup`、`pointerupoutside`、`pointerover`、`pointerout`、`click`。未显式设置 `eventMode` 时自动采用 `static`。先查 external actions,再查当前 Scene 脚本同名方法。子 Scene 实例的 `@eventName` 继续表示公开 `@event()` 事件。
|
|
29
|
+
|
|
30
|
+
`<Group>` 是可直接写的 Pixifact 盒子容器;它的 `width` / `height` 使用稳定的 Pixifact 盒子尺寸语义,也支持 frame layout。`<Container>` 保持 PixiJS 原生 bounds / scale 尺寸语义,适合纯分组。`<Control>` 是 runtime 布局基类,不能直接写成 `.scene` 标签。
|
|
31
|
+
|
|
32
|
+
不要在 `<Scene>` 上写 `class="..."` 或 `script="..."`。Scene 脚本由同目录同 basename 的 `.ts` 文件和其中的 `@scene()` class 推断。
|
|
33
|
+
|
|
34
|
+
## 值类型
|
|
35
|
+
|
|
36
|
+
`.scene` 属性值都写在 XML attribute 中:
|
|
37
|
+
|
|
38
|
+
| 写法 | 类型 | 示例 |
|
|
39
|
+
| --- | --- | --- |
|
|
40
|
+
| 数字 | number | `x="24"`、`rotation="0.25"` |
|
|
41
|
+
| 布尔 | boolean | `visible="false"` |
|
|
42
|
+
| 字符串 | string | `text="Start"`、`fontFamily="Inter"` |
|
|
43
|
+
| 颜色 | color | `fill="#ffffff"`、`tint="#ffcc66"` |
|
|
44
|
+
| 枚举 | enum | `fit="cover"`、`fontWeight="700"` |
|
|
45
|
+
|
|
46
|
+
颜色推荐写 `#rrggbb`。`texture` 必须是项目内相对资源路径,例如 `assets/ui/button.png`;不要使用绝对路径、`./`、`..`、URL 或反斜杠路径。
|
|
47
|
+
|
|
48
|
+
## 通用属性
|
|
49
|
+
|
|
50
|
+
所有官方基础对象和项目子 Scene 实例都支持这些通用属性。
|
|
51
|
+
|
|
52
|
+
### 标识
|
|
53
|
+
|
|
54
|
+
| 属性 | 类型 | 说明 |
|
|
55
|
+
| --- | --- | --- |
|
|
56
|
+
| `id` | string | 稳定节点 ID。可编辑节点必须写,便于 `@part()`、inspect、diff 和调试。 |
|
|
57
|
+
|
|
58
|
+
### Transform
|
|
59
|
+
|
|
60
|
+
| 属性 | 类型 | 说明 |
|
|
61
|
+
| --- | --- | --- |
|
|
62
|
+
| `x` | number | 自由定位时的横坐标。 |
|
|
63
|
+
| `y` | number | 自由定位时的纵坐标。 |
|
|
64
|
+
| `width` | number | 节点宽度。 |
|
|
65
|
+
| `height` | number | 节点高度。 |
|
|
66
|
+
| `scaleX` | number | 横向缩放。 |
|
|
67
|
+
| `scaleY` | number | 纵向缩放。 |
|
|
68
|
+
| `rotation` | number | 旋转弧度。 |
|
|
69
|
+
| `pivotX` | number | pivot 横坐标。 |
|
|
70
|
+
| `pivotY` | number | pivot 纵坐标。 |
|
|
71
|
+
| `skewX` | number | 横向 skew。 |
|
|
72
|
+
| `skewY` | number | 纵向 skew。 |
|
|
73
|
+
|
|
74
|
+
### Frame Layout
|
|
75
|
+
|
|
76
|
+
| 属性 | 类型 | 说明 |
|
|
77
|
+
| --- | --- | --- |
|
|
78
|
+
| `left` | number | 距父节点左边距离。 |
|
|
79
|
+
| `right` | number | 距父节点右边距离。 |
|
|
80
|
+
| `top` | number | 距父节点上边距离。 |
|
|
81
|
+
| `bottom` | number | 距父节点下边距离。 |
|
|
82
|
+
| `horizontal` | number | 相对父节点水平中心的偏移。 |
|
|
83
|
+
| `vertical` | number | 相对父节点垂直中心的偏移。 |
|
|
84
|
+
|
|
85
|
+
横向优先级:`left + right > left > right > horizontal > x`。纵向优先级:`top + bottom > top > bottom > vertical > y`。
|
|
86
|
+
|
|
87
|
+
常见写法:
|
|
88
|
+
|
|
89
|
+
```xml
|
|
90
|
+
<Image id="background" texture="assets/bg/forest.png" left="0" right="0" top="0" bottom="0" fit="cover" />
|
|
91
|
+
<Panel id="panel" scene="./Panel.scene" horizontal="0" vertical="0" width="640" height="420" />
|
|
92
|
+
<Button id="confirm" scene="./Button.scene" right="24" bottom="24" width="180" height="64" text="OK" />
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Display
|
|
96
|
+
|
|
97
|
+
| 属性 | 类型 | 可选值 / 说明 |
|
|
98
|
+
| --- | --- | --- |
|
|
99
|
+
| `alpha` | number | 透明度,通常 `0` 到 `1`。 |
|
|
100
|
+
| `visible` | boolean | 是否显示。 |
|
|
101
|
+
| `zIndex` | number | 同级排序值。 |
|
|
102
|
+
| `eventMode` | enum | `none` / `passive` / `auto` / `static` / `dynamic`。点击、拖拽、滚动命中常用 `static`。 |
|
|
103
|
+
| `cursor` | enum | `default` / `pointer` / `text` / `grab` / `grabbing`。 |
|
|
104
|
+
| `label` | string | Pixi display object label;通常优先用 `id`。 |
|
|
105
|
+
|
|
106
|
+
## 官方基础对象总览
|
|
107
|
+
|
|
108
|
+
| 对象 | 可放子节点 | 适合场景 |
|
|
109
|
+
| --- | --- | --- |
|
|
110
|
+
| `Group` | 是 | 有明确宽高、需要 frame layout 的普通盒子容器。 |
|
|
111
|
+
| `Container` | 是 | 轻量分组、统一移动、显示隐藏、排序。 |
|
|
112
|
+
| `HBoxContainer` | 是 | 横向按钮组、工具栏、图标加数字。 |
|
|
113
|
+
| `VBoxContainer` | 是 | 纵向菜单、列表、表单项。 |
|
|
114
|
+
| `GridContainer` | 是 | 背包格子、关卡卡片、固定列数面板。 |
|
|
115
|
+
| `ScrollContainer` | 是 | 可滚动列表、背包、任务面板。 |
|
|
116
|
+
| `Sprite` | 否 | Pixi 原生图片精灵。 |
|
|
117
|
+
| `NineSliceSprite` | 否 | Pixi 原生九宫格精灵。 |
|
|
118
|
+
| `TilingSprite` | 否 | Pixi 原生平铺精灵。 |
|
|
119
|
+
| `Label` | 否 | 带明确宽高、对齐、换行和裁剪的 UI 文本盒。 |
|
|
120
|
+
| `BitmapLabel` | 否 | 使用 bitmap font 的 UI 文本盒。 |
|
|
121
|
+
| `Text` | 否 | 普通文本。 |
|
|
122
|
+
| `BitmapText` | 否 | 高频更新或大量文本。 |
|
|
123
|
+
| `HTMLText` | 否 | 简单富文本。 |
|
|
124
|
+
| `Graphics` | 否 | 简单 `rect` / `roundRect` 矢量形状。 |
|
|
125
|
+
| `Rect` | 否 | UI 矩形、圆角矩形、色块、描边背景。 |
|
|
126
|
+
| `Image` | 否 | 带盒子尺寸和 `fit` 的图片,推荐用于大多数 UI 图片。 |
|
|
127
|
+
| `NineImage` | 否 | Pixifact runtime 九宫格图片,推荐用于可缩放 UI 背板。 |
|
|
128
|
+
| `TileImage` | 否 | Pixifact runtime 平铺图片,推荐用于重复纹理和背景。 |
|
|
129
|
+
|
|
130
|
+
叶子节点不能放 children。需要把文字放到背景上时,用容器或子 Scene 包起来,不要把 `Text` 写进 `Image`、`Rect`、`NineImage` 等叶子节点里。
|
|
131
|
+
|
|
132
|
+
## Group
|
|
133
|
+
|
|
134
|
+
`Group` 是 Pixifact 盒子容器,继承 `Container`。它可以放子节点,`width` / `height` 是明确的开发坐标盒子尺寸,不会因为子节点 bounds 或缩放而改变。需要普通容器同时固定宽高或使用 frame layout 时,直接使用 `<Group>`。
|
|
135
|
+
|
|
136
|
+
专属属性:无,只使用通用属性。
|
|
137
|
+
|
|
138
|
+
`Group` 不绘制背景,也不自动排列子节点。需要背景时放入 `Rect`、`Image` 或 `NineImage`;需要自动排列时使用 `HBoxContainer`、`VBoxContainer` 或 `GridContainer`。
|
|
139
|
+
|
|
140
|
+
```xml
|
|
141
|
+
<Group id="rewardPanel" left="24" right="24" top="160" height="140">
|
|
142
|
+
<Rect id="background" left="0" right="0" top="0" bottom="0" radius="16" fillColor="#1f2937" />
|
|
143
|
+
<Image id="coinIcon" texture="assets/icons/coin.png" x="24" y="46" width="48" height="48" />
|
|
144
|
+
<Text id="coinAmount" text="+120" x="84" y="54" fontSize="28" fill="#ffd166" />
|
|
145
|
+
</Group>
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Container
|
|
149
|
+
|
|
150
|
+
`Container` 是 PixiJS 原生容器。专属属性:无,只使用通用属性。
|
|
151
|
+
|
|
152
|
+
`Container.width` / `Container.height` 保持 Pixi 原生 bounds / scale 语义,不是 Pixifact 盒子尺寸。需要稳定盒子尺寸和 frame layout 时,使用 `<Group>` 或布局容器。
|
|
153
|
+
|
|
154
|
+
```xml
|
|
155
|
+
<Container id="rewardLayer" x="24" y="160" zIndex="10">
|
|
156
|
+
<Image id="coinIcon" texture="assets/icons/coin.png" width="48" height="48" />
|
|
157
|
+
<Text id="coinAmount" text="+120" x="60" y="8" fontSize="28" fill="#ffd166" />
|
|
158
|
+
</Container>
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Layout Containers
|
|
162
|
+
|
|
163
|
+
这些容器都可以放 children,也都支持通用属性和 frame layout。
|
|
164
|
+
|
|
165
|
+
### HBoxContainer
|
|
166
|
+
|
|
167
|
+
横向排列直接子节点。
|
|
168
|
+
|
|
169
|
+
| 属性 | 类型 | 可选值 / 说明 |
|
|
170
|
+
| --- | --- | --- |
|
|
171
|
+
| `gap` | number | 子节点之间的基础横向间距。 |
|
|
172
|
+
| `alignY` | enum | `start` / `center` / `end`。子节点纵向对齐。 |
|
|
173
|
+
| `justify` | enum | `start` / `center` / `end` / `space-between`。整组横向分布。 |
|
|
174
|
+
|
|
175
|
+
```xml
|
|
176
|
+
<HBoxContainer id="resourceBar" right="24" top="24" width="260" height="56" gap="12" alignY="center" justify="end">
|
|
177
|
+
<Image id="coinIcon" texture="assets/icons/coin.png" width="40" height="40" />
|
|
178
|
+
<Text id="coinText" text="12,800" fontSize="24" fill="#ffffff" />
|
|
179
|
+
</HBoxContainer>
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### VBoxContainer
|
|
183
|
+
|
|
184
|
+
纵向排列直接子节点。
|
|
185
|
+
|
|
186
|
+
| 属性 | 类型 | 可选值 / 说明 |
|
|
187
|
+
| --- | --- | --- |
|
|
188
|
+
| `gap` | number | 子节点之间的基础纵向间距。 |
|
|
189
|
+
| `alignX` | enum | `start` / `center` / `end`。子节点横向对齐。 |
|
|
190
|
+
| `justify` | enum | `start` / `center` / `end` / `space-between`。整组纵向分布。 |
|
|
191
|
+
|
|
192
|
+
```xml
|
|
193
|
+
<VBoxContainer id="mainMenu" horizontal="0" vertical="0" width="420" gap="18" alignX="center">
|
|
194
|
+
<Text id="title" text="PIXIFACT" fontSize="48" fill="#ffffff" />
|
|
195
|
+
<PrimaryButton id="startButton" scene="./PrimaryButton.scene" width="360" height="80" text="开始" />
|
|
196
|
+
</VBoxContainer>
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### GridContainer
|
|
200
|
+
|
|
201
|
+
按固定列数从左到右、从上到下排列直接子节点。
|
|
202
|
+
|
|
203
|
+
| 属性 | 类型 | 可选值 / 说明 |
|
|
204
|
+
| --- | --- | --- |
|
|
205
|
+
| `columns` | number | 列数。运行时向下取整,至少为 `1`。 |
|
|
206
|
+
| `gapX` | number | 列间距。 |
|
|
207
|
+
| `gapY` | number | 行间距。 |
|
|
208
|
+
| `alignX` | enum | `start` / `center` / `end`。子节点在单元格横向对齐。 |
|
|
209
|
+
| `alignY` | enum | `start` / `center` / `end`。子节点在单元格纵向对齐。 |
|
|
210
|
+
|
|
211
|
+
```xml
|
|
212
|
+
<GridContainer id="inventoryGrid" left="32" right="32" top="160" height="520" columns="4" gapX="14" gapY="14" alignX="center" alignY="center">
|
|
213
|
+
<ItemSlot id="slot1" scene="./ItemSlot.scene" width="128" height="128" />
|
|
214
|
+
<ItemSlot id="slot2" scene="./ItemSlot.scene" width="128" height="128" />
|
|
215
|
+
</GridContainer>
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### ScrollContainer
|
|
219
|
+
|
|
220
|
+
可拖拽滚动区域。作者写进去的子节点会挂到内部 content layer,并被容器尺寸裁剪。
|
|
221
|
+
|
|
222
|
+
| 属性 | 类型 | 可选值 / 说明 |
|
|
223
|
+
| --- | --- | --- |
|
|
224
|
+
| `direction` | enum | `vertical` / `horizontal` / `both`。 |
|
|
225
|
+
| `scrollX` | number | 初始横向滚动位置。 |
|
|
226
|
+
| `scrollY` | number | 初始纵向滚动位置。 |
|
|
227
|
+
|
|
228
|
+
```xml
|
|
229
|
+
<ScrollContainer id="questScroll" left="32" right="32" top="180" bottom="120" direction="vertical">
|
|
230
|
+
<VBoxContainer id="questList" width="686" gap="16">
|
|
231
|
+
<QuestRow id="quest1" scene="./QuestRow.scene" width="686" height="96" title="采集草药" />
|
|
232
|
+
</VBoxContainer>
|
|
233
|
+
</ScrollContainer>
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
## Sprite-like Nodes
|
|
237
|
+
|
|
238
|
+
### Sprite
|
|
239
|
+
|
|
240
|
+
PixiJS 原生图片精灵。大多数 UI 图片优先用 `Image`。
|
|
241
|
+
|
|
242
|
+
| 属性 | 类型 | 说明 |
|
|
243
|
+
| --- | --- | --- |
|
|
244
|
+
| `texture` | string | 项目内图片资源路径。 |
|
|
245
|
+
| `anchorX` | number | 横向 anchor,常见 `0` 到 `1`。 |
|
|
246
|
+
| `anchorY` | number | 纵向 anchor,常见 `0` 到 `1`。 |
|
|
247
|
+
| `tint` | color | 图片 tint。 |
|
|
248
|
+
|
|
249
|
+
```xml
|
|
250
|
+
<Sprite id="sparkle" texture="assets/effects/sparkle.png" x="180" y="220" width="64" height="64" anchorX="0.5" anchorY="0.5" tint="#fff2a8" />
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### NineSliceSprite
|
|
254
|
+
|
|
255
|
+
PixiJS 原生九宫格精灵。新 UI 背板通常优先用 `NineImage`。
|
|
256
|
+
|
|
257
|
+
| 属性 | 类型 | 说明 |
|
|
258
|
+
| --- | --- | --- |
|
|
259
|
+
| `texture` | string | 项目内图片资源路径。 |
|
|
260
|
+
| `anchorX` | number | 横向 anchor。 |
|
|
261
|
+
| `anchorY` | number | 纵向 anchor。 |
|
|
262
|
+
| `tint` | color | 图片 tint。 |
|
|
263
|
+
| `leftWidth` | number | 左侧不可拉伸区域宽度。 |
|
|
264
|
+
| `rightWidth` | number | 右侧不可拉伸区域宽度。 |
|
|
265
|
+
| `topHeight` | number | 顶部不可拉伸区域高度。 |
|
|
266
|
+
| `bottomHeight` | number | 底部不可拉伸区域高度。 |
|
|
267
|
+
|
|
268
|
+
```xml
|
|
269
|
+
<NineSliceSprite id="nativePanel" texture="assets/ui/panel.png" width="520" height="280" leftWidth="24" rightWidth="24" topHeight="24" bottomHeight="24" />
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### TilingSprite
|
|
273
|
+
|
|
274
|
+
PixiJS 原生平铺精灵。新重复纹理通常优先用 `TileImage`。
|
|
275
|
+
|
|
276
|
+
| 属性 | 类型 | 说明 |
|
|
277
|
+
| --- | --- | --- |
|
|
278
|
+
| `texture` | string | 项目内图片资源路径。 |
|
|
279
|
+
| `anchorX` | number | 横向 anchor。 |
|
|
280
|
+
| `anchorY` | number | 纵向 anchor。 |
|
|
281
|
+
| `tint` | color | 图片 tint。 |
|
|
282
|
+
| `tilePositionX` | number | 纹理平铺横向偏移。 |
|
|
283
|
+
| `tilePositionY` | number | 纹理平铺纵向偏移。 |
|
|
284
|
+
| `tileScaleX` | number | 纹理平铺横向缩放。 |
|
|
285
|
+
| `tileScaleY` | number | 纹理平铺纵向缩放。 |
|
|
286
|
+
| `tileRotation` | number | 纹理平铺旋转弧度。 |
|
|
287
|
+
|
|
288
|
+
```xml
|
|
289
|
+
<TilingSprite id="nativePattern" texture="assets/bg/pattern.png" width="750" height="240" tileScaleX="0.5" tileScaleY="0.5" />
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
### Image
|
|
293
|
+
|
|
294
|
+
Pixifact runtime 图片盒子,推荐用于大多数 UI 图片、头像、图标和背景图。
|
|
295
|
+
|
|
296
|
+
| 属性 | 类型 | 可选值 / 说明 |
|
|
297
|
+
| --- | --- | --- |
|
|
298
|
+
| `texture` | string | 项目内图片资源路径。 |
|
|
299
|
+
| `fit` | enum | `stretch` / `contain` / `cover` / `none`。 |
|
|
300
|
+
| `anchorX` | number | 横向 anchor。 |
|
|
301
|
+
| `anchorY` | number | 纵向 anchor。 |
|
|
302
|
+
| `tint` | color | 图片 tint。 |
|
|
303
|
+
|
|
304
|
+
`fit="stretch"` 拉伸填满盒子;`contain` 完整显示,可能留空;`cover` 铺满盒子,可能裁切;`none` 使用原始尺寸绘制。
|
|
305
|
+
|
|
306
|
+
```xml
|
|
307
|
+
<Image id="background" texture="assets/bg/forest.png" left="0" right="0" top="0" bottom="0" fit="cover" />
|
|
308
|
+
<Image id="avatar" texture="assets/characters/hero.png" left="24" top="24" width="96" height="96" fit="contain" />
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### NineImage
|
|
312
|
+
|
|
313
|
+
Pixifact runtime 九宫格图片,推荐用于按钮底图、弹窗面板、提示气泡、卡片背景。
|
|
314
|
+
|
|
315
|
+
| 属性 | 类型 | 说明 |
|
|
316
|
+
| --- | --- | --- |
|
|
317
|
+
| `texture` | string | 项目内图片资源路径。 |
|
|
318
|
+
| `leftWidth` | number | 左侧不可拉伸区域宽度。 |
|
|
319
|
+
| `rightWidth` | number | 右侧不可拉伸区域宽度。 |
|
|
320
|
+
| `topHeight` | number | 顶部不可拉伸区域高度。 |
|
|
321
|
+
| `bottomHeight` | number | 底部不可拉伸区域高度。 |
|
|
322
|
+
| `anchorX` | number | 横向 anchor。 |
|
|
323
|
+
| `anchorY` | number | 纵向 anchor。 |
|
|
324
|
+
| `tint` | color | 图片 tint。 |
|
|
325
|
+
|
|
326
|
+
```xml
|
|
327
|
+
<NineImage id="dialogPanel" texture="assets/ui/panel.png" horizontal="0" vertical="0" width="620" height="420" leftWidth="32" rightWidth="32" topHeight="32" bottomHeight="32" />
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
### TileImage
|
|
331
|
+
|
|
332
|
+
Pixifact runtime 平铺图片,推荐用于重复背景或可滚动纹理。
|
|
333
|
+
|
|
334
|
+
| 属性 | 类型 | 说明 |
|
|
335
|
+
| --- | --- | --- |
|
|
336
|
+
| `texture` | string | 项目内图片资源路径。 |
|
|
337
|
+
| `tilePositionX` | number | 纹理平铺横向偏移。 |
|
|
338
|
+
| `tilePositionY` | number | 纹理平铺纵向偏移。 |
|
|
339
|
+
| `tileScaleX` | number | 纹理平铺横向缩放。 |
|
|
340
|
+
| `tileScaleY` | number | 纹理平铺纵向缩放。 |
|
|
341
|
+
| `tileRotation` | number | 纹理平铺旋转弧度。 |
|
|
342
|
+
| `anchorX` | number | 横向 anchor。 |
|
|
343
|
+
| `anchorY` | number | 纵向 anchor。 |
|
|
344
|
+
| `tint` | color | 图片 tint。 |
|
|
345
|
+
|
|
346
|
+
```xml
|
|
347
|
+
<TileImage id="groundPattern" texture="assets/bg/grass_tile.png" left="0" right="0" bottom="0" height="180" tileScaleX="2" tileScaleY="2" />
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
## Label
|
|
351
|
+
|
|
352
|
+
`Label` 是推荐用于 UI 的 Pixifact 文本盒。`width` / `height` 是布局盒尺寸,不会缩放文字;`fontSize` 修改字号和排版;`scaleX` / `scaleY` 缩放整个控件。默认盒子为 `120 x 28`。
|
|
353
|
+
|
|
354
|
+
| 属性 | 类型 | 可选值 / 说明 |
|
|
355
|
+
| --- | --- | --- |
|
|
356
|
+
| `text` | string | 文本内容。 |
|
|
357
|
+
| `fontSize` | number | 字号。 |
|
|
358
|
+
| `fontFamily` | string | 字体族。 |
|
|
359
|
+
| `fontWeight` | enum | `400` / `500` / `600` / `700` / `bold`。 |
|
|
360
|
+
| `fill` | color | 文本颜色。 |
|
|
361
|
+
| `lineHeight` | number | 行高;`0` 使用字体自然行高。 |
|
|
362
|
+
| `letterSpacing` | number | 字符间距。 |
|
|
363
|
+
| `wordWrap` | boolean | 是否按 `width` 自动换行。 |
|
|
364
|
+
| `alignX` | enum | `start` / `center` / `end`,水平对齐。 |
|
|
365
|
+
| `alignY` | enum | `start` / `center` / `end`,垂直对齐。 |
|
|
366
|
+
| `overflow` | enum | `visible` / `clip`。 |
|
|
367
|
+
|
|
368
|
+
```xml
|
|
369
|
+
<Label id="title" width="240" height="52" text="背包" fontSize="28" fontWeight="700" fill="#ffffff" alignX="center" alignY="center" />
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
## BitmapLabel
|
|
373
|
+
|
|
374
|
+
`BitmapLabel` 与 `Label` 使用相同的盒子、排版、换行、对齐和裁剪属性,内部使用 PixiJS `BitmapText`。应用必须在实例化 Scene 前加载 `.fnt`,`fontFamily` 写字体文件声明的 family 名称。
|
|
375
|
+
|
|
376
|
+
```xml
|
|
377
|
+
<BitmapLabel id="gold" width="160" height="48" text="1280" fontFamily="寒蝉圆黑体Heavy" fontSize="32" fill="#ffdb84" alignX="end" alignY="center" />
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
## Text Nodes
|
|
381
|
+
|
|
382
|
+
`Text`、`BitmapText`、`HTMLText` 支持相同文本属性。
|
|
383
|
+
|
|
384
|
+
| 属性 | 类型 | 可选值 / 说明 |
|
|
385
|
+
| --- | --- | --- |
|
|
386
|
+
| `text` | string | 文本内容。 |
|
|
387
|
+
| `fontSize` | number | 字号。 |
|
|
388
|
+
| `fontFamily` | string | 字体族或 bitmap font family。 |
|
|
389
|
+
| `fontWeight` | enum | `400` / `500` / `600` / `700` / `bold`,数字可写成数字或字符串。 |
|
|
390
|
+
| `fill` | color | 文本颜色。 |
|
|
391
|
+
|
|
392
|
+
三者保留 Pixi 原生尺寸语义,没有 `120 x 28` 假宽高默认值。显式设置 `width` / `height` 会通过 scale 改变文字尺寸,不是设置布局盒。普通 UI 文本优先使用 `Label`;`BitmapText` 适合大量文本或频繁变化数值;`HTMLText` 适合简单 HTML 标记,因为 `.scene` 是 XML-like 格式,`text` 中的 `<`、`>`、`&` 要写成实体。
|
|
393
|
+
|
|
394
|
+
```xml
|
|
395
|
+
<Text id="scoreLabel" text="Score 1200" right="24" top="28" fontSize="28" fontWeight="700" fill="#ffffff" />
|
|
396
|
+
<BitmapText id="damageNumber" text="-358" x="320" y="260" fontSize="36" fontFamily="DamageFont" fill="#ff4d4d" />
|
|
397
|
+
<HTMLText id="richTip" text="获得 <b>稀有</b> 道具" fontSize="22" fill="#ffffff" />
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
## Graphics
|
|
401
|
+
|
|
402
|
+
当前在 `.scene` 中支持简单 `rect` 和 `roundRect`。UI 色块和面板背景通常优先用 `Rect`。
|
|
403
|
+
|
|
404
|
+
| 属性 | 类型 | 可选值 / 说明 |
|
|
405
|
+
| --- | --- | --- |
|
|
406
|
+
| `shape` | enum | `roundRect` / `rect`。只有设置 `shape` 时 compiler 才生成绘制调用。 |
|
|
407
|
+
| `radius` | number | `roundRect` 圆角半径。 |
|
|
408
|
+
| `fill` | color | 填充颜色。 |
|
|
409
|
+
| `fillAlpha` | number | 填充透明度。 |
|
|
410
|
+
| `strokeColor` | color | 描边颜色。 |
|
|
411
|
+
| `strokeWidth` | number | 描边宽度。 |
|
|
412
|
+
| `strokeAlpha` | number | 描边透明度。 |
|
|
413
|
+
|
|
414
|
+
```xml
|
|
415
|
+
<Graphics id="highlight" shape="roundRect" x="20" y="20" width="300" height="72" radius="12" fill="#fff3bf" fillAlpha="0.35" strokeColor="#ffd43b" strokeWidth="2" />
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
## Rect
|
|
419
|
+
|
|
420
|
+
Pixifact runtime 矩形节点,会按盒子尺寸自动重绘,适合 UI 背景、色块和描边框。
|
|
421
|
+
|
|
422
|
+
| 属性 | 类型 | 说明 |
|
|
423
|
+
| --- | --- | --- |
|
|
424
|
+
| `fillColor` | color | 填充颜色。 |
|
|
425
|
+
| `fillAlpha` | number | 填充透明度。 |
|
|
426
|
+
| `strokeColor` | color | 描边颜色。 |
|
|
427
|
+
| `strokeAlpha` | number | 描边透明度。 |
|
|
428
|
+
| `strokeWidth` | number | 描边宽度。默认 `0`,即不显示描边。 |
|
|
429
|
+
| `radius` | number | 圆角半径。 |
|
|
430
|
+
|
|
431
|
+
```xml
|
|
432
|
+
<Rect id="cardBackground" width="320" height="180" radius="16" fillColor="#1f2937" fillAlpha="0.92" strokeColor="#facc15" strokeWidth="2" />
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
## 项目子 Scene 实例
|
|
436
|
+
|
|
437
|
+
除了官方基础对象,`.scene` 可以引用项目里的其他 Scene:
|
|
438
|
+
|
|
439
|
+
```xml
|
|
440
|
+
<PrimaryButton id="startButton" scene="./PrimaryButton.scene" horizontal="0" bottom="96" width="420" height="88" text="开始游戏" @click="startGame" />
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
子 Scene 实例可用属性:
|
|
444
|
+
|
|
445
|
+
| 属性来源 | 说明 |
|
|
446
|
+
| --- | --- |
|
|
447
|
+
| 通用属性 | `id`、Transform、Frame Layout、Display。 |
|
|
448
|
+
| `scene` | 引用的 `.scene` 文件路径,推荐写相对当前 Scene 的路径,例如 `./PrimaryButton.scene`。 |
|
|
449
|
+
| public props | 子 Scene 脚本中用 `@prop()` 暴露的属性。 |
|
|
450
|
+
| public events | 子 Scene 脚本中用 `@event()` 暴露的事件,用 `@eventName="actionName"` 绑定。 |
|
|
451
|
+
| public slots | 子 Scene 脚本中用 `@slot()` 暴露的 slot,父 Scene 用子节点的 `slot="name"` 填入。 |
|
|
452
|
+
|
|
453
|
+
事件绑定值是 action name。运行时会优先连接 external actions;没有对应 action 时,连接当前 root 脚本实例上的同名方法。
|
|
454
|
+
|
|
455
|
+
子 Scene 脚本示例:
|
|
456
|
+
|
|
457
|
+
```ts
|
|
458
|
+
import type { Container } from 'pixi.js';
|
|
459
|
+
import { Group } from 'pixifact/runtime';
|
|
460
|
+
import { createEvent, event, prop, scene, slot } from 'pixifact/scene';
|
|
461
|
+
|
|
462
|
+
@scene()
|
|
463
|
+
export class PrimaryButton extends Group {
|
|
464
|
+
@prop({ default: 'Button' })
|
|
465
|
+
declare text: string;
|
|
466
|
+
|
|
467
|
+
@event()
|
|
468
|
+
readonly click = createEvent();
|
|
469
|
+
|
|
470
|
+
@slot()
|
|
471
|
+
readonly icon!: Container;
|
|
472
|
+
}
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
Primitive public Props 的类型从 TypeScript property type 推断,默认值写在 `@prop` 上:
|
|
476
|
+
|
|
477
|
+
```ts
|
|
478
|
+
@prop({ default: 'Button' })
|
|
479
|
+
declare text: string;
|
|
480
|
+
|
|
481
|
+
@prop({ default: 0 })
|
|
482
|
+
declare count: number;
|
|
483
|
+
|
|
484
|
+
@prop({ default: false })
|
|
485
|
+
declare disabled: boolean;
|
|
486
|
+
```
|
|
487
|
+
|
|
488
|
+
`@prop` 只能装饰无 initializer 的 `declare` property。不要写 `type` option、field initializer、accessor、getter 或 setter。
|
|
489
|
+
|
|
490
|
+
子 Scene 在自己的 `.scene` 中用完整值 Binding 消费公开 Prop:
|
|
491
|
+
|
|
492
|
+
```xml
|
|
493
|
+
<Text id="labelText" text="{text}" />
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
可复用样式使用 `defineVariants()`,并通过 `{tone.field}` 绑定。不支持表达式、字符串插值或双向绑定。
|
|
497
|
+
|
|
498
|
+
父 Scene 填充 slot:
|
|
499
|
+
|
|
500
|
+
```xml
|
|
501
|
+
<PrimaryButton id="startButton" scene="./PrimaryButton.scene" text="开始游戏" @click="startGame">
|
|
502
|
+
<Image slot="icon" id="startIcon" texture="assets/icons/play.png" width="32" height="32" />
|
|
503
|
+
</PrimaryButton>
|
|
504
|
+
```
|
|
505
|
+
|
|
506
|
+
## Slot Outlet
|
|
507
|
+
|
|
508
|
+
`<slot>` 只能写在可复用 Scene 自己的 `.scene` 里,用来声明子内容挂载位置:
|
|
509
|
+
|
|
510
|
+
```xml
|
|
511
|
+
<Scene name="PrimaryButton" width="420" height="88">
|
|
512
|
+
<NineImage id="background" texture="assets/ui/button.png" left="0" right="0" top="0" bottom="0" leftWidth="24" rightWidth="24" topHeight="24" bottomHeight="24" />
|
|
513
|
+
<HBoxContainer id="content" horizontal="0" vertical="0" gap="12" alignY="center">
|
|
514
|
+
<slot name="icon" />
|
|
515
|
+
<Text id="label" text="Button" fontSize="28" fill="#ffffff" />
|
|
516
|
+
</HBoxContainer>
|
|
517
|
+
</Scene>
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
`<slot />` 省略 `name` 时表示 `default` slot。
|
|
521
|
+
|
|
522
|
+
## Events
|
|
523
|
+
|
|
524
|
+
事件属性写在子 Scene instance 上,绑定值是 action name:
|
|
525
|
+
|
|
526
|
+
```xml
|
|
527
|
+
<PrimaryButton id="pauseButton" scene="./PrimaryButton.scene" text="暂停" @click="handlePause" />
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
事件名来自子 Scene 脚本的 `@event()`。运行时会优先连接 external actions;没有对应 action 时,连接当前 root 脚本实例上的同名方法。不要把事件写成全局函数或生成文件逻辑。
|
|
531
|
+
|
|
532
|
+
## Structured Props
|
|
533
|
+
|
|
534
|
+
结构化 props 使用 dot-path attributes,不要传 JSON string:
|
|
535
|
+
|
|
536
|
+
```xml
|
|
537
|
+
<RewardCard
|
|
538
|
+
id="reward"
|
|
539
|
+
scene="./RewardCard.scene"
|
|
540
|
+
rectTransform.x="40"
|
|
541
|
+
rectTransform.y="220"
|
|
542
|
+
rectTransform.width="670"
|
|
543
|
+
rectTransform.height="160"
|
|
544
|
+
/>
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
Scene script 中的 struct class 必须导出、可无参构造,public fields 必须有 primitive initializer:
|
|
548
|
+
|
|
549
|
+
```ts
|
|
550
|
+
export class RectTransform {
|
|
551
|
+
x = 0;
|
|
552
|
+
y = 0;
|
|
553
|
+
width = 188;
|
|
554
|
+
height = 48;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
@scene()
|
|
558
|
+
export class RewardCard extends Group {
|
|
559
|
+
@prop({})
|
|
560
|
+
declare rectTransform: RectTransform;
|
|
561
|
+
}
|
|
562
|
+
```
|
|
563
|
+
|
|
564
|
+
## 当前不要使用的标签
|
|
565
|
+
|
|
566
|
+
| 标签 | 说明 |
|
|
567
|
+
| --- | --- |
|
|
568
|
+
| `Control` | runtime 布局基类,不是 `.scene` 标签。 |
|
|
569
|
+
| `Mesh` | parser 底层类型中仍有遗留入口,但不在官方可新增和校验支持列表中。 |
|
|
570
|
+
| `DOMContainer` | parser 底层类型中仍有遗留入口,但不在官方可新增和校验支持列表中。 |
|
|
571
|
+
| `FlexLayout` / `FlexItem` | 旧协议,不再是官方内置能力。 |
|
|
572
|
+
|
|
573
|
+
如果 `scene validate` 报 “supported compiler Pixi node type”,请把标签替换成官方基础对象,或改为带 `scene="..."` 的项目子 Scene 实例。
|
|
574
|
+
|
|
575
|
+
## 快速模板
|
|
576
|
+
|
|
577
|
+
```xml
|
|
578
|
+
<Scene name="Hud" width="750" height="1334">
|
|
579
|
+
<Image id="background" texture="assets/bg/hud.png" left="0" right="0" top="0" bottom="0" fit="cover" />
|
|
580
|
+
<VBoxContainer id="content" left="32" right="32" top="80" gap="16">
|
|
581
|
+
<Text id="title" text="任务" fontSize="36" fontWeight="700" fill="#ffffff" />
|
|
582
|
+
<QuestRow id="questRow" scene="./QuestRow.scene" width="686" height="96" title="采集草药" @click="openQuest" />
|
|
583
|
+
</VBoxContainer>
|
|
584
|
+
</Scene>
|
|
585
|
+
```
|