starfleetcadet75 / TiledMapImporter

A C# library for using custom maps made with the Tiled Map Editor in MonoGame/Xna.
MIT License
10 stars 1 forks source link

Map not loading #1

Closed joseasv closed 9 years ago

joseasv commented 9 years ago

Hello there. I've been looking for an easy way to load a Tiled map in MonoGame and your library is a godsend. Although, I've been trying to load a test map without luck. I'm using Visual Studio Express 2013 for Windows Desktop and MonoGame 3.2. The DemoGame project runs fine and even my test map gets loaded.

I create a MonoGame Windows Project, add the MapImporter.dll and add the Tiled map in json and the tileset png turned xnb to the Content folder (Using this http://www.monogame.net/documentation/?page=Using_The_Pipeline_Tool). Then, I load the map and texture in LoadContent():

map = Importer.ImportMap(@"Content/test.json");
map.LoadTilesetTextures(Content);

And this is drawing call in Draw():

spriteBatch.Begin();
// TODO: Add your drawing code here
mapa.Draw(spriteBatch, graphics.GraphicsDevice.Viewport.Bounds, new Vector2(0, 0));
spriteBatch.End();

I run the program and I got this Exception: A first chance exception of type 'System.NullReferenceException' occurred in test.exe Additional information: Object reference not set to an instance of an object.

I even get this exception loading your NewBarkTown map in my test project.

starfleetcadet75 commented 9 years ago

So your the first person to start a new project from scratch with the importer and I believe the issue is that you need to add Newtonsoft.Json (http://www.newtonsoft.com/json) to the project otherwise the Importer can't parse the map, returning a null reference. I recommend downloading it using the NuGet package manager in Visual Studio.

Other issues that are easily fixed and I forget about: 1) Make sure to set the properties for all of the JSON and XNB files to 'Content' and 'Copy if newer' 2) Chances are the filepaths inside the JSON file that have the location of your tileset images (XNB files) are not correct and need to be changed. My image tag looks like this: "image": "your_tileset_name". Tiled will give you something by default. Notice that for XNBs I do not include any extension. 3) You have a problem somewhere with your filepaths and need to tweak them a bit.

joseasv commented 9 years ago

Oops, sorry for the late reply. I added that json library and now it works just fine. Thanks and keep the good work!