C# XNA - 读取 .txt 文件并创建二维数组

标签 c# xna xna-4.0 streamreader

我正在尝试在 XNA 中创建一个 2D 数组,我将使用它作为我正在开发的游戏的图 block map 。我读过各种解决方案,但似乎没有一个适合我。我遇到的主要问题之一是错误:

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
    }
}

如果有人可以帮助我,或者为我指出一个可行的示例,那就太好了。

最佳答案

如果您使用 StreamReader 手动读取该文件,请在该文件的属性窗口中将构建操作更改为“无”。该消息来自尝试为您导入的内容管道。

关于C# XNA - 读取 .txt 文件并创建二维数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9673332/

相关文章:

c# - 从图像动态创建 XNA Sprite

c# - 配置错误 : Unrecognized attribute 'maxBufferSize'

c# - 如何将数据插入关系数据库

c# - 在两点之间绘制路径

c# - 无法启动 xxx.exe。先前对应用程序进行概要分析的尝试未成功完成。请重新启动应用程序

c# - “最近邻”缩放

java - Java 中的 AES 加密与 C# 输出相匹配

c# - 无法访问 Azure 上发布的 Web api

c# - 如何使用栈代替列表?

c# - xbox 性能陷阱