2

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.

2
  • Is your file named map.txt, 5x5-map.txt or 5x5-map? It seems like there may be a naming issue? Commented Mar 12, 2012 at 19:15
  • I've tried it both ways, does the same thing... I have it included with the Content. Commented Mar 12, 2012 at 19:17

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

That half did it... I also had to set Copy to Output as Copy always.
1

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

1 Comment

Had a look at this... couldn't find a specific importer for files including .txt - besides the solution from Jimmy worked. Thank you for your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.