2012-03-12 120 views
2

我正在尝试在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 
    } 
} 

如果有人可以帮助我,或点我的方向一个很好的工作例子。

+0

您的文件是否名为map.txt,5x5-map.txt或5x5-map?似乎可能有一个命名问题? – Quickhorn 2012-03-12 19:15:32

+0

我已经尝试过两种方法,做同样的事情......我已将它包含在内容中。 – diggersworld 2012-03-12 19:17:02

回答

3

更改构建动作为“无”,在属性窗口中该文件,如果你手工与StreamReader的阅读。该消息来自内容管道,试图为您导入它。

+0

这一半做到了......我还必须将Copy设置为Output as Copy to always。 – diggersworld 2012-03-12 19:33:34

1

Specify the importer that handles this file type in your project.

在您的内容项目中查找文件,打开属性菜单并选择导入程序。

According to MSDN: Verifying the Content Importer

+0

看看这个......找不到包括.txt在内的文件的特定导入程序 - 除了Jimmy的解决方案工作。感谢您的帮助。 – diggersworld 2012-03-12 19:34:55