scroll y by a constant scale instead of per-layer.

This commit is contained in:
Colin McMillen 2020-03-25 12:38:56 -04:00
parent 4a598fb377
commit 7c0eb479a6

View File

@ -74,14 +74,16 @@ namespace SemiColinGames {
spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.LinearWrap, null, null);
Rectangle bgTarget = new Rectangle(0, 0, camera.Width, camera.Height);
float bgScale = 1f / 16;
float xScale = 1f / 16; // Changes with each layer (the layers further back scroll less).
float yScale = 1f / 4; // Constant across all layers.
for (int i = 0; i < Textures.Backgrounds.Length; i++) {
float yDiff = (world.Height - camera.Bottom) * bgScale;
float yOffset = Textures.Backgrounds[i].Get.Height - camera.Height - yDiff;
Texture2D background = Textures.Backgrounds[i].Get;
float yDiff = (world.Height - camera.Bottom) * yScale;
float yOffset = background.Height - camera.Height - yDiff;
Rectangle bgSource = new Rectangle(
(int) (camera.Left * bgScale), (int) yOffset, camera.Width, camera.Height);
spriteBatch.Draw(Textures.Backgrounds[i].Get, bgTarget, bgSource, Color.White);
bgScale *= 2;
(int) (camera.Left * xScale), (int) yOffset, camera.Width, camera.Height);
spriteBatch.Draw(background, bgTarget, bgSource, Color.White);
xScale *= 2;
}
spriteBatch.End();