Hello All. I have been making various demos using Monogame.Extended so that I can get all the fundamental building blocks working before making my game, and I would like to accomplish parallax scrolling of a Tiled TMX Map. I have a working solution, but am not sure if there is a better way.
I have a 2 layered map, and I want the background layer to scroll at half the speed. So my solution was to make 2 Camera2Ds, one for the foreground layer of the map, and one for the background layer of the map. On the Update() function, I adjusted the background camera position according to the position of the foreground camera like so:
backgroundCamera.Position = new Vector2(foregroundCamera.Position.X * 0.5f, foregroundCamera.Position.Y * 0.5f);
Then on the Draw() function, I call Draw on both cameras, by drawing specific layers, rather than the entire map, like this:
mapRenderer.Draw(map.GetLayer("Background"), backgroundCamera.GetViewMatrix());//draw background layer
mapRenderer.Draw(map.GetLayer("Foreground"), foregroundCamera.GetViewMatrix());//draw foreground layer
My question is, is there a way to adjust the background layer position, so that I only need a single camera to render both layers, but with the background layer re-positioned for parallax? Couldn't there be a settable offset for the tile layer perhaps?
Thank you for reading.