Pergunta

I have created TMX map in Tiled map editor and I use XTiled to load the map in MonoGame. In xna project the maps loads perfeclty, but in MonoGame can't. I build the .tmx file with xna project(in the content project) than build in my monogame project like .xnb file with all the references set. The build succeeds but the map can't load.

I would appreciate if someone could tell me the steps to load the TMX map in Monogame or provide me with some tutorials to do this.

Thanks in advance.

Foi útil?

Solução

In any case, I can assure you it's possible to load Tiled maps using xTile in MonoGame. I did it for one of our games called Rock Run.

The trick is to recompile xTile with MonoGame dependencies. Here's a snippet of our level loading code that might help:

string levelPath = string.Format (@"Content\level{0:00}.tbin", level);
var stream = TitleContainer.OpenStream(levelPath);
_map = xTile.Format.FormatManager.Instance.BinaryFormat.Load(stream);

_mapDisplayDevice = new XnaDisplayDevice(Content, GraphicsDevice, ScreenScale);
_map.LoadTileSheets(_mapDisplayDevice);

var viewportSize = new xTile.Dimensions.Size(ScreenWidth, ScreenHeight);
_viewportRectangle = new xTile.Dimensions.Rectangle(viewportSize);

There's a few things to note here. We didn't bother pre-compiling the content to XNB files first. They are just exported from the map editor as binary (tbin) files and added as direct content. Although, I don't think that's your problem, and from memory we had to make some minor changes to get it to work this way. So using XNB files should work just as well.

Secondly, we use the TitleContainer to read the file as a stream, because on Android devices the files are stored in isolated storage and you can't find them with typical file system operations.

Everything else should be pretty self explanatory if you've followed the tutorial.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top