Map transition within game screen

Hello all,
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 :frowning: 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.

The Tiled demo shows some basic switching of what map to render. From there it’s likely going to be very specific to your game’s needs.

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.

So basically the only way to get rid of resources that you no longer need is to create multiple content managers because of the fact that a content manager can only unload ALL of its contents.

Yes, that’s how it works. Though if you want you could create a custom class for managing content that allows to selectively unload stuff.

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?

Yes, that’s exactly how it works :slight_smile:

Just beware that loading the same asset with different ContentManager instances will load the asset twice.

Good to know. Also, is doing what I described generally regarded as good practice? It just seems weird because the Content.Load<T>( ) calls could seem redundant.

Honestly I agree that the ContentManager API is not intuitive. Calling Load<T> multiple times with the same string is fine though and does not load the content multiple times.

Hello dear why not use Unity3D easy :slight_smile:

Like Ufo flies movement :stuck_out_tongue:

Youtube Explanation with 2D game easy, If you want player like Supermairo or Jazz JackRabbit 1/2 than you can read it.

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…

This has been discussed before. See Monogame(2D) or Unity3D(2D)? and Monogame vs. Unity3D
Also these forums are for MonoGame, not Unity. If you like Unity better, that’s great, but not everyone holds that same opinion.

2 Likes

Ops I’m sorry I don’t see any threads in MonoGame. Thanks!