アプリケーションで、xml ファイルの属性を介してオブジェクトにロードできる関数を作成しようとしています。TinyXML2 は非常に簡単でゲームに適していると聞いているので、TinyXML2 を使用したいと考えています。
現在、次のxmlファイルがあります。
<?xml version="1.0" encoding="UTF-8"?>
<Level>
<Pulsator starttime="0" type="0" higherradius="100" lowerradius="10" time="60" y="500" x="300" bpm="60"/>
</Level>
Pulsator の各属性は、私の Pulsator クラスの変数です。followign 関数を使用して Pulsators をインポートし、それらをオブジェクトのベクトルに追加します。
void Game::LoadLevel(string filename)
{
tinyxml2::XMLDocument level;
level.LoadFile(filename.c_str());
tinyxml2::XMLNode* root = level.FirstChild();
tinyxml2::XMLNode* childNode = root->FirstChild();
while (childNode)
{
Pulsator* tempPulse = new Pulsator();
float bpm;
float type;
std::string::size_type sz;
tinyxml2::XMLElement* data = childNode->ToElement();
string inputdata = data->Attribute("bpm");
bpm = std::stof(inputdata, &sz);
if (type == 0)
{
tempPulse->type = Obstacle;
tempPulse->SetColor(D2D1::ColorF(D2D1::ColorF::Black));
}
if (type == 1)
{
tempPulse->type = Enemy;
tempPulse->SetColor(D2D1::ColorF(D2D1::ColorF::Red));
}
if (type == 2)
{
tempPulse->type = Score;
tempPulse->SetColor(D2D1::ColorF(D2D1::ColorF::Green));
}
else
{
tempPulse->type = No_Type;
}
objects.push_back(tempPulse);
}
}
ルート ノードに到達するたびに、間違って読み込まれ、子ノードが null になります。これを間違って使用していますか、それとも XML ファイルに問題がありますか?