我是YAML的新手并试图让一个例子运行起来。我有来自http://www.gamedev.net/page/resources/_/technical/apis-and-tools/yaml-basics-and-parsing-with-yaml-cpp-r3508的Sprites_list YAML文件,并且root / base节点始终为Null,但是大小为Always 0,类型为Scalar,并且尝试访问节点会抛出YAML :: BadSubscript异常。 Yaml 0.5.3的impl.h中的第118行。为什么根节点的大小为0,为什么不能访问节点?
YAML::Node root_node_ = YAML::Load( file );
if( root_node_.IsNull() )
{
// Never entered
}
int sz = root_node_.size(); // Always 0
YAML::Node a_node = root_node_[ "Sprites_List" ]; // Exception
编辑 - > 完整的文件内容(粘贴到名为sprites.yml的文件中)
Sprites_List: [Player, Monster, Gem]
Player:
SpriteSheet: /Resources/Textures/duotone.png
Anim_Names: [run, idle, jump, die]
run:
Offset: {x: 0, y: 0}
Size: {w: 32, h: 32}
Frame_Durations: [80, 80, 80, 80, 80, 80]
idle:
Offset: {x: 0, y: 32}
Size: {w: 32, h: 32}
Frame_Durations: [80, 120, 80, 30, 30, 130] #Notice the different durations!
jump:
Offset: {x: 0, y: 64}
Size: {w: 32, h: 32}
Frame_Durations: [80, 80, 120, 80, 80, 0] #Can I say 0 mean no skipping?
die:
Offset: {x: 0, y: 192} #192? Yup, it is the last row in that sheet.
Size: {w: 32, h: 32}
Frame_Durations: [80, 80, 80, 80, 80] #this one has only 5 frames.
Monster: #lol that lam nam
SpriteSheet: /Resources/Textures/duotone.png
Anim_Names: [hover, die]
hover:
Offset: {x: 0, y: 128}
Size: {w: 32, h: 32}
Frame_Durations: [120, 80, 120, 80]
die:
Offset: {x: 0, y: 160}
Size: {w: 32, h: 32}
Frame_Durations: [80, 80, 80, 80, 80]
Gem:
SpriteSheet: /Resources/Textures/duotone.png
Anim_Names: [shine]
shine:
Offset: {x: 0, y: 96}
Size: {w: 32, h: 32}
Frame_Durations: [80, 80, 80, 80, 80, 80]
在课堂宣言中 -
YAML::Node root_node_;
在课堂定义中 -
CConfigFile( std::string const & file ) :
root_node_ ( YAML::Load( file ) )
文件路径是完整的绝对路径,并且每个\都以\\转义。
答案 0 :(得分:0)
YAML::LoadFile
加载YAML字符串,而不是文件。要加载文件,您需要使用{{1}}。