我正在使用 Filestream 将分数保存在我的 android 游戏中。最近,我决定添加额外的关卡。对于这些级别,我需要跟踪多种类型的分数。这是我的一个变量的代码:
function writePion(): void { //First function to create/write in the file
var pion: Object = new Object();
pion.value = numeroPion; //value of object = variable value
trace("Pion (writeObject value)= " + pion.value);
var file2: File = File.applicationStorageDirectory.resolvePath("pion.menes");
var fileStream2: FileStream = new FileStream();
fileStream2.open(file2, FileMode.WRITE);
fileStream2.writeObject(pion);
fileStream2.close();
};
function readPion(): void { //second function to read the file and modify the variable.
var file2: File = File.applicationStorageDirectory.resolvePath("pion.menes");
if (!file2.exists) {
return;
}
var fileStream2: FileStream = new FileStream();
fileStream2.open(file2, FileMode.READ);
var pion: Object = fileStream2.readObject();
numeroPion = pion.value; //update the variable
trace("pion (readObject value)= " + numeroPion)
fileStream2.close();
};
我想知道我是否必须为每种类型的分数制作其中一个函数,或者有没有办法对其进行调整以保存(大约 10 个)新变量?谢谢 :) 杰瑞尔。