我正在开发一个简单的 iOS 游戏,其中你有 10 个级别,一旦你完成一个,下一个级别就会解锁。我在这里创建 xml 文件:
private function SaveProgress()
{
addChild(myTextField);
var GameSaveXML:XML =
<LEVEL>
<LEVEL_01>false</LEVEL_01>
<LEVEL_02>false</LEVEL_02>
<LEVEL_03>false</LEVEL_03>
<LEVEL_04>false</LEVEL_04>
<LEVEL_05>false</LEVEL_05>
<LEVEL_06>false</LEVEL_06>
<LEVEL_07>false</LEVEL_07>
<LEVEL_08>false</LEVEL_08>
<LEVEL_09>false</LEVEL_09>
<LEVEL_10>false</LEVEL_10>
</LEVEL>;;
//file.deleteFile();
var file:File = File.documentsDirectory.resolvePath("LevelsSaved.xml");
if (file.exists)
{
trace("EXISTS");
trace(GameSaveXML);
}
else
{
var fileStream = new FileStream();
fileStream.open(file, FileMode.WRITE);
var outputString:String = '<?xml version="1.0" encoding="utf-8"?>\n';
outputString += GameSaveXML.toXMLString();
fileStream.writeUTFBytes(outputString);
//GameSaveXML.replace(2,<LEVEL_03>true</LEVEL_03>);
trace(GameSaveXML);
fileStream.close();
trace("File Was Created");
}
}
我真的很难加载文件并检查哪些级别已解锁(true)以及哪些级别仍被锁定(false)。你能帮忙吗?非常感谢!