我目前正在学习 Yaml,并且对此代码有疑问:
http://hastebin.com/focokeqawo.sm
---
classes:
audio:
- &Music components.audio.Music
- &Sound components.audio.Sound
graphic:
- &Animation components.graphic.Animation
- &Image components.graphic.Image
- &Text components.graphic.Text
misc:
- &Camera components.misc.Camera
- &Debug components.misc.Debug
collider:
- &Circle components.physics.Circle
- &Hitbox components.physics.Hitbox
- &Polygon components.physics.Polygon
common:
- &Physics components.Physics
- &Transform components.Transform
&Wabbit Wabbit:
name: Wabbit
components:
-
type: *Transform
x: 150
y: 120
-
type: *Image
file: Wabbit
-
type: *Physics
-
type: *Debug
&Coin Coin:
name: Coin
components:
-
type: *Transform
x: 370
y: 180
scaleX: 5
scaleY: 5
-
type: *Physics
-
type: *Debug
&Ground Ground:
name: Ground
components:
-
type: *Transform
x: 320
y: 475
&TestScene TestScene:
type: Scene
gameObjects: [*Wabbit, *Coin, *Ground]
extensions: [Nape]
Engine:
name: Example
scene: *TestScene
paused: false
debug: true
Screen:
color: [146, 150, 152] #grey
scaleX: 1
scaleY: 1
zoom: 1
底部的“gameObjects”数组被解析为字符串数组,但我希望它包含锚点(&)的实际数据。我还在顶部使用了锚点,它们工作得很好。
问题:yaml 锚点也适用于复杂数据吗?
您的锚点可能需要放置在别名之前,即将锚点放在文件的顶部。
要排除解析器而不是 YAML 定义中出现错误的可能性,请使用在线 YAML 解析器(例如 https://jsonformatter.org/yaml-parser)测试您的 YAML 配置以帮助排除故障。
祝你好运🍀