Reloading a Map

Dec 12, 2012 at 9:24 AM

This might be a stupid question but is there any way to reload a map? In my game tiles can change and if the player dies I want them to be able to go back to the main menu and restart the map from it's original state.

I guess I could keep track of what tiles change and just loop through to reset them but I'd rather just reload the map.

Dec 13, 2012 at 8:34 PM

The ContentManager caches all loaded content by default so if you alter your map and then attempt to reload it, you will actually get the same map object instance.

One way around this is to call the Unload() method of your ContentManager (usually the Content property within the Game class), before reloading your map. However, Unload() clears the content manager's whole cache and any other content loaded through this manager will need to be reloaded. One option to avoid this, is to create multiple ContentManager instances and reserve one for map objects. That way, calling Unload() on this specific manager will only unload the map object.

Hope that helps.