我正在尝试在XNA中创建二维数组,我将使用它作为我正在处理的游戏的瓷砖贴图。我已经阅读了各种解决方案,但他们都没有为我工作。其中一个我遇到的主要问题是错误的:C#XNA - 读取.txt文件并创建二维数组
Cannot autodetect which importer to use for "map.txt". There are no importers which handle this file type. Specify the importer that handles this file type in your project.
这似乎是由StreamReader
类,我试图使用引起的。
我使用的是XNA 4.0。
我的.txt文件看起来像这样(举例):
0,0,0,0,0
0,0,0,0,0
0,0,1,0,0
0,1,1,1,0
1,1,1,1,1
我的C#和XNA看起来是这样的:
string line = string.Empty;
using (StreamReader sr = new StreamReader("5x5-map"))
{
while ((line = sr.ReadLine()) != null)
{
//reads line by line until eof
//do whatever you want with the text
}
}
如果有人可以帮助我,或点我的方向一个很好的工作例子。
您的文件是否名为map.txt,5x5-map.txt或5x5-map?似乎可能有一个命名问题? – Quickhorn 2012-03-12 19:15:32
我已经尝试过两种方法,做同样的事情......我已将它包含在内容中。 – diggersworld 2012-03-12 19:17:02