How can I use Extended's TiledMapRenderer separately from the content pipeline?

I’d like part of the player’s save game data to be a TMX file. I’d like to be able to load the TMX file from the user’s %appdata% and then use TiledMapRenderer to draw it. This would allow me to leverage all the features that TiledMapRenderer provides, like automatically updating tile animations and integration with the Camera class provided by MonoGame.Extended.

I’d like to avoid using a separate library altogether for loading the file (such as TiledCS) and then manually munging it into an Extended TiledMap instance, so using Extended’s TMX/TSX file reader isolated from the content pipeline would be ideal.

It… sort of seems like this is what ExternalReference is for but I think that’s meant for content pipeline compilation and support for file types not regularly supported by the pipeline. What would be preferable is if I could have a similar method to Texture2D.FromFile.

In a nutshell, I’d like something like the following to work:

var appDataPath = Path.Combine(
    Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
    "Foo",
    saveFileName);

var mapDataPath = Path.Combine(appDataPath, "savegame_map.tmx");

var tiledMap = MonoGame.Extended.Tiled.TiledMap.FromFile(mapDataPath);

var tiledMapRenderer = new MonoGame.Extended.Tiled.Renderers.TiledMapRenderer(
    graphicsDevice, tiledMap);

Is this possible with the current API?

1 Like