Loading maps without XNA content pipeline?

Feb 24, 2012 at 9:02 PM

Is it possible to load .tide maps without using the XNA content pipeline? The XNA content pipeline requires the maps to be compiled into .xnb files and they can't be edited after the game is compiled.

We have a team member that will concentrate only on map making and graphics (I've already found a way to load textures without using the XNA CP and allowing textures to be changed without having to compile the whole game, or even have visual studio open) so we want him to simply have a debug version of the current version of the game and being able to edit the maps and simply starting the game again to see the changes. The same goes for the tilesets.

Is this even possible? I've been searching around for a whole day and haven't found anything useful so far. 

Feb 24, 2012 at 9:24 PM

Ironically, I just figured out how to do what you're asking about this morning.

  1. Save your map files as *.tbin
  2. In your program, define "xTile.FormatManager formatManager = xTile.FormatManager.Instance;"
  3. Load the map by calling "formatManager.LoadMap(string filePath);"
Feb 24, 2012 at 9:39 PM

Actually you don't need to work with the .tbin format at all. The formatManager should be able to load a .tide format file directly using the same code as in step 3 - it determines the format from the file extension and chooses the appropriate map format loader.

Feb 24, 2012 at 9:44 PM
Edited Feb 24, 2012 at 9:49 PM

Thanks or incredibly quick answers, wasn't expecting them so soon!

 

I tried this and it works:

xTile.Format.FormatManager formatManager = xTile.Format.FormatManager.Instance;           
_map = formatManager.LoadMap("Content/Maps/Map02.tbin");

But, _map.LoadTileSheets(_mapDisplayDevice); fails on "Error loading "..\TileSheets\Background01.png". File not found.", I'm thinking it has something to do with me having to add "Content/" to the LoadMap path.. 

Oh and colinvella, I tried using the .tide extension and it worked just as well, so is seems there is not need to use .tbin. But I still have the problem with the tilesheets.. 

There may be some super simple solution to it, but since I'm not the programmer that added the xTile engine to our game and did the ground work, I'm not really familiar with it (He's currently travelling, so I can't contact him right now)

Feb 24, 2012 at 9:56 PM
Edited Feb 24, 2012 at 9:56 PM

Make sure that your tilesheet files are being copied correctly to the output directory with relative paths intact. It's looking for them in PNG format, so I don't think their build action shouldn't be compile.

I was having trouble with the regular format in MonoDevelop, but tbin worked there. I'm getting xTile maps to load in a project that uses a different API, and that's as far as I've gotten.

Feb 24, 2012 at 10:14 PM

Ah okay. I'm not compiling the tilesheets and the path is the same as it was before.. I'm just wondering where the "..\TileSheets\Background01.png" path is coming from, I might have to change it to ..\Content\TileSheets\ or something like that, I'm not really sure what path it is relative to there, since it is backing out of a directory.

Like it was originally (with the XNA Pipeline) the path to the map was "/Maps/Map02", so I suspect the ..\ is to back out of the Maps folder and then going into the TileSheets folder. Just came from a break so I'm going to keep looking into this. I'll post an update if I figure something out.

Feb 24, 2012 at 10:47 PM
The tilesheet paths are indeed relative to the location of the map file so you need to ensure the same folder structure is used even when not using the content pipeline.

On 24 February 2012 23:14, XanderDelores <notifications@codeplex.com> wrote:

From: XanderDelores

Ah okay. I'm not compiling the tilesheets and the path is the same as it was before.. I'm just wondering where the "..\TileSheets\Background01.png" path is coming from, I might have to change it to ..\Content\TileSheets\ or something like that, I'm not really sure what path it is relative to there, since it is backing out of a directory.

Like it was originally (with the XNA Pipeline) the path to the map was "/Maps/Map02", so I suspect the ..\ is to back out of the Maps folder and then going into the TileSheets folder. Just came from a break so I'm going to keep looking into this. I'll post an update if I figure something out.

Read the full discussion online.

To add a post to this discussion, reply to this email (tIDE@discussions.codeplex.com)

To start a new discussion for this project, email tIDE@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Feb 24, 2012 at 10:55 PM
Edited Feb 24, 2012 at 10:57 PM

Yeah, the paths are correct.. but I figured out what the error is about, when I realized I could see more details about the error:

{"Error loading \"Content\\TileSheets\\Background01.png.xnb\". File not found.":null}

Seems that XNA is appending .xnb to the path.. that has to have something to do with the XNA Content Pipeline still being used on the tilesheets (Even though they're not set to be processed by XNA), must have something to do with "_map.LoadTileSheets(_mapDisplayDevice);"

Seems I need to find another way to load the tilesheets than using LoadTileSheets

Feb 25, 2012 at 3:39 PM
Edited Feb 25, 2012 at 3:44 PM

I think I'm getting a little closed to solving this problem..

Currently, the error is at "_map.LoadTileSheets(_mapDisplayDevice);"

Earlier, _mapDisplayDevice is initiated as "_mapDisplayDevice = new XnaDisplayDevice(this.Content, this.GraphicsDevice);"

XnaDisplayDevice is xTile.Display.XnaDisplayDevice.

When checking the definitions in that class I found a LoadTileSheet method with the following summary:

        // Summary:       
 //     Loads the given tile sheet. The image source is loaded from the content pipeline       
//     by stripping any extension from the image source and using the resulting       
//     path into the content pipeline

So this XnaDisplayDevice tries to load the tilesheets through the XNA CP.. I think. Anyone have any ideas?

 

EDIT:

By looking at the source, I can see this method is implemented this way:

        public void LoadTileSheet(TileSheet tileSheet)
        {
            Texture2D texture2D = m_contentManager.Load(tileSheet.ImageSource);
            m_tileSheetTextures[tileSheet] = texture2D;
        }

This is using the XNA CP, but I'd need something that works the same way, but loads from stream, similarly as I load the animations:

            using (Stream titleStream = TitleContainer.OpenStream("Content/Player/" + fileName + ".png"))
            {
                anim = new Animation(Texture2D.FromStream(GraphicsDevice, titleStream), frameTime, isLooping);
            }

Feb 25, 2012 at 4:06 PM
Edited Feb 25, 2012 at 4:08 PM

The way I got it to work involved some odd folder rearrangement. Say you have your maps in a folder called Maps, and Maps is in the root of your project. The *.tide files in Maps all reference tilesheets stored in ("Maps\TileSheets"), so they reference a relative path of (".\\TileSheets"). I got it to work by putting the TileSheets folder in the root of the project. This seems to be necessary because the "current selected directory" seems to be lost when avoiding the pipeline, and it thinks the ".\" folder is the root folder rather than ("Maps\").

Feb 25, 2012 at 4:08 PM

I actually solved this, by changing the original source a little, to this

        public void LoadTileSheet(TileSheet tileSheet)
        {
            Texture2D texture2D;
            using (Stream titleStream = TitleContainer.OpenStream("Content/" + tileSheet.ImageSource))
            {
                texture2D = Texture2D.FromStream(m_graphicsDevice, titleStream);
            }
            //Texture2D texture2D = m_contentManager.Load(tileSheet.ImageSource);
            m_tileSheetTextures[tileSheet] = texture2D;
        }

Now I just need to read up on the licencing, to see if I am allowed to do this and use it in a project.