Screen Management
The ScreenManager
helps you to split your game into multiple GameScreens
with their own Dispose()
,
Initialize()
,
LoadContent()
,
UnloadContent()
,
Update(GameTime gameTime)
,
and, Draw(GameTime gameTime)
methods.
Installation
The ScreenManager
and GameScreen
classes are available in the MonoGame.Extended
library.
MonoGame.Extended is distributed via a NuGet package. You can add the NuGet package to your C# project through your IDE of choice (Visual Studio, Xamarin Studio, Rider, etc) or through the Command Line Interface (CLI) using the dotnet command.
Usage
We start by including the Screens
and Transitions
namespaces.
Next, we implement our GameScreens. In this example, we use 2 GameScreens with a sprite that follows the Cursor.
Screen 1
Screen 2
Next, we define our ScreenManger
in our Game
class.
Which we then assign and register as GameComponent
in the constructor.
Then we define the following methods to load the screens.
Which we then call from the Initialize
and Update
methods.