【发布时间】:2011-10-20 17:25:12
【问题描述】:
我正在尝试将我的 pc XNA 游戏移植到 xbox,并尝试在我现有的 pc 文件管理的同时实现 xna easystorage 以获得高分。基本上试图将http://xnaessentials.com/tutorials/highscores.aspx/tutorials/highscores.aspx与http://easystorage.codeplex.com/结合起来
我遇到了一个关于 LoadHighScores() 的特定错误,即“return (data);”错误- 使用未分配的局部变量“数据”。
我认为这是由于 easystorage/xbox 的异步设计!?但不确定如何解决 - 以下是代码示例:
原始 PC 代码:(适用于 PC)
public static HighScoreData LoadHighScores(字符串文件名) { HighScoreData 数据; // 获取游戏保存路径
string fullpath = "Content/highscores.lst";
// Open the file
FileStream stream = File.Open(fullpath, FileMode.Open,FileAccess.Read);
try
{ // Read the data from the file
XmlSerializer serializer = new XmlSerializer(typeof(HighScoreData));
data = (HighScoreData)serializer.Deserialize(stream);
}
finally
{ // Close the file
stream.Close();
}
return (data);
}
XBOX 端口:(有错误)
public static HighScoreData LoadHighScores(字符串容器,字符串文件名) { HighScoreData 数据;
if (Global.SaveDevice.FileExists(container, filename))
{
Global.SaveDevice.Load(container, filename, stream =>
{
File.Open(Global.fileName_options, FileMode.Open,//FileMode.OpenOrCreate,
FileAccess.Read);
try
{
// Read the data from the file
XmlSerializer serializer = new XmlSerializer(typeof(HighScoreData));
data = (HighScoreData)serializer.Deserialize(stream);
}
finally
{
// Close the file
stream.Close();
}
});
}
return (data);
}
有什么想法吗?
【问题讨论】: