diggersworld
diggersworld

Reputation: 13080

C# XNA - Read .txt file and create 2D array

I'm trying to create a 2D array in XNA which I'll be using as a tile map for a game I'm working on. I've read various solutions but none of them seem to be working for me. One of the main issues I'm having is an error:

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.

This appears to be caused by the StreamReader class that I'm attempting to use.

I'm using XNA 4.0.

My .txt file looks like this (example):

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

My C# and XNA looks like this:

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

If anyone could help me, or point me in the direction of a working example that would be great.

Upvotes: 2

Views: 6779

Answers (2)

Jimmy
Jimmy

Reputation: 91432

Change the build action to "None" in the properties window for that file, if you're manually reading it with StreamReader. The message comes from the content pipeline trying to import it for you.

Upvotes: 3

ClassicThunder
ClassicThunder

Reputation: 1936

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

Find the file in your content project, open the properties menu, and select an importer.

According to MSDN: Verifying the Content Importer

Upvotes: 1

Related Questions