Screen Management
Not up to date
This page is not up to date for MonoGame.Extended 4.0.3
. If you would like to contribute to updating this document, please create a new PR
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.
Usage
We start by including the Screens
and Transitions
namespaces.
using MonoGame.Extended.Screens;
using MonoGame.Extended.Screens.Transitions;
Next, we implement our GameScreens. In this example, we use 2 GameScreens with a sprite that follows the Cursor.
Screen 1
public class MyScreen1 : GameScreen
{
private new Game1 Game => (Game1) base.Game;
private Texture2D _logo;
private SpriteFont _font;
private Vector2 _position = new Vector2(50,50);
public MyScreen1(Game1 game) : base(game) { }
public override void LoadContent()
{
base.LoadContent();
_font = Game.Content.Load<SpriteFont>("font");
_logo = Game.Content.Load<Texture2D>("logo-mge");
}
public override void Update(GameTime gameTime)
{
_position = Vector2.Lerp(_position, Mouse.GetState().Position.ToVector2(), 1f * gameTime.GetElapsedSeconds());
}
public override void Draw(GameTime gameTime)
{
Game.GraphicsDevice.Clear(new Color(16, 139, 204));
Game.SpriteBatch.Begin();
Game.SpriteBatch.DrawString(_font, nameof(MyScreen1), new Vector2(10,10), Color.White);
Game.SpriteBatch.Draw(_logo, _position, Color.White);
Game.SpriteBatch.End();
}
}