Browse Source

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

master
Colin McMillen 4 years ago
parent
commit
7c0eb479a6
  1. 14
      Shared/Scene.cs

14
Shared/Scene.cs

@ -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();

Loading…
Cancel
Save