Parallax-scroll the background by Y.
This commit is contained in:
parent
fccca0c676
commit
4a598fb377
@ -11,6 +11,8 @@ namespace SemiColinGames {
|
||||
public int Height { get => bbox.Height; }
|
||||
public int Left { get => bbox.Left; }
|
||||
public int Top { get => bbox.Top; }
|
||||
public int Bottom { get => bbox.Bottom; }
|
||||
|
||||
public Point HalfSize { get => new Point(Width / 2, Height / 2); }
|
||||
|
||||
private readonly Random random = new Random();
|
||||
|
@ -74,13 +74,14 @@ namespace SemiColinGames {
|
||||
spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.LinearWrap, null, null);
|
||||
Rectangle bgTarget = new Rectangle(0, 0, camera.Width, camera.Height);
|
||||
|
||||
float xScale = 1f / 16;
|
||||
float bgScale = 1f / 16;
|
||||
for (int i = 0; i < Textures.Backgrounds.Length; i++) {
|
||||
int yOffset = Textures.Backgrounds[i].Get.Height - camera.Height - 24;
|
||||
float yDiff = (world.Height - camera.Bottom) * bgScale;
|
||||
float yOffset = Textures.Backgrounds[i].Get.Height - camera.Height - yDiff;
|
||||
Rectangle bgSource = new Rectangle(
|
||||
(int) (camera.Left * xScale), yOffset, camera.Width, camera.Height);
|
||||
(int) (camera.Left * bgScale), (int) yOffset, camera.Width, camera.Height);
|
||||
spriteBatch.Draw(Textures.Backgrounds[i].Get, bgTarget, bgSource, Color.White);
|
||||
xScale *= 2;
|
||||
bgScale *= 2;
|
||||
}
|
||||
spriteBatch.End();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user