I am making a 2d game that has several different game states. I basically add gamestates to a stack, and just call updates and draws to the topmost instance. I start the spritebatch before the draw call, and close it after.
I’ve done so since I have couple of different things going on. Menues. Part where you navigate the world map. Ship to ship combat. Some minigames. A platformer.
From my Game object.
protected override void LoadContent()
{
var viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 320 * (int)scale, 180 * (int)scale);
_camera = new OrthographicCamera(viewportAdapter);
_spriteBatch = new SpriteBatch(GraphicsDevice);
transformMatrix = _camera.GetViewMatrix() * Matrix.CreateScale(Game1.scale, Game1.scale, 1.0f);
GameStateManager.Instance.SetContent(Content);
GameStateManager.Instance.AddScreen(new TitleScreenGameState(GraphicsDevice, _camera));
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
_spriteBatch.Begin(sortMode: SpriteSortMode.Immediate, samplerState: SamplerState.PointClamp, transformMatrix: transformMatrix);
GameStateManager.Instance.Draw(_spriteBatch);
base.Draw(gameTime);
_spriteBatch.End();
}
The problem I’ve run into is that I am unable to move the monogame extended ortographic camera. Everything renders just fine. Sprites that have the same coordinates as the camera moves, but the view remains fixed and the hero gladly just walks off the screen, never to be seen again.
I have suspected that it’s because I don’t pass the camera as a reference, but I’ve tried calling a static camera from the game class, but that did not fix the issue.