I’m starting development within monogame for the first time and I’ve been starting out by learning about game states/screens and maps and so forth and I’ve come across an issue where I can’t seem to find much information about transitioning to a new map within the same game state/screen. Most, if not all tutorials, in Monogame deal with a single map within its gamestate and I never get to see how to handle a change in scenery. My research has led me to believe that I would need to deal with multiple content managers. This makes sense to degree but I still can’t see how I’d implement it. Within the demos folder in the GitHub repo I’ve found a lot of help as to how monogame.extended used Tiled maps and how the entity component system works through the platformer demo. It’s a seriously good demo but I’ve found that it still has only one map. The arrow leading to a new “area” makes me a little sad haha.
My idea as to how to handle transitions is as following: creating a Factory method that does essentially what the LoadContent() method does in the Platformer demo’s GameScreen class that would create a new level “stage”. When the player approaches the end of the map, this method would be triggered, loading new content into the GameScreen and disposing of the old content. However I don’t really know if this is even a good way of doing this, and for that reason I’m asking for help or even suggesting that the platformer demo be updated so that it shows how to handle this situation. It would definitely make it easier to make games and would help me a lot as well. If I haven’t explained what I mean very well, I have a gif here that shows what I’m talking about in Stardew Valley.
Haha I’ve definitely played with that demo and didn’t even realize that it does what I asked about. Thanks for pointing that out! I have another question to ask your opinion on then. I said before in my original question that a lot of people online suggest that I use separate content managers to load content for each level and a universal content manager to load universal content. Is that a good choice in your opinion?
Each ContentManager instance uses uses a Dictionary which is collection that maps keys (strings of asset names in this case) to values (the asset objects such as Texture2D or TiledMap). Each ContentManager.Load<T> will lookup if the asset is already loaded in constant time by checking the mapping. If it’s not in the mapping, load it from the disk (the expensive operation) and add it to the mapping. This is all good but the problem is that there is no way to unload a specific asset with ContentManager; it only supports unloading all the assets that were loaded via iterating the mapping. Practically this means that a new ContentManager instance should be used for each “group” of assets that you want to load/unload together.
Awesome. So for example, when I boot up my game, I could theoretically have the ContentManager inside of the Game1 class load all of the common game content. Then I could have other game states with their own ContentManagers and references to the Game1’s ContentManager. In these game states I could Game1Content.Load( ) something that was already loaded in the initial boot up because I need it for this class, and it would be an inexpensive operation because it’s only a dictionary lookup. When the class specific ContentManager loads something that wasn’t loaded in the initial bootup, however, the operation would be more expensive because it’s not a case of a dictionary lookup. Then, when I need to change maps I could unload the content in my class’s contentmanager and later use it again to load in new content for that new map. Am I understanding things correctly?
Why not It is easier than Monogame if you have problem with creating real 2D game with changing level has sometimes but without loading screen - I will find since I start to find I forget where is video…