Support 4-layer parallax-scrolling backgrounds.

GitOrigin-RevId: 58c1d1fee99e56dd656af5bbf628fbdc16d55e14
This commit is contained in:
Colin McMillen 2020-02-19 13:07:11 -05:00
parent 8405f32f3c
commit 05638483a4
2 changed files with 27 additions and 8 deletions

View File

@ -51,14 +51,29 @@ namespace SemiColinGames {
spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.LinearWrap, null, null);
// Draw background.
Color bgBlend = Color.FromNonPremultiplied(new Vector4(1, 1, 1, 0.5f));
Rectangle bgSource = new Rectangle(
(int) (camera.Left * 0.25), 0, camera.Width, camera.Height);
// We assume that all backgrounds are the same size; if not, the computation of yOffset needs
// to be computed separately for every background.
int yOffset = Textures.Background1.Height - camera.Height - 64;
Color bgBlend = Color.FromNonPremultiplied(new Vector4(1, 1, 1, 1));
Rectangle bgTarget = new Rectangle(0, 0, camera.Width, camera.Height);
spriteBatch.Draw(Textures.Background2, bgTarget, bgSource, bgBlend);
bgSource = new Rectangle(
(int) (camera.Left * 0.5), 0, camera.Width, camera.Height);
Rectangle bgSource = new Rectangle(
(int) (camera.Left * 1f / 16), yOffset, camera.Width, camera.Height);
spriteBatch.Draw(Textures.Background1, bgTarget, bgSource, bgBlend);
bgSource = new Rectangle(
(int) (camera.Left * 1f / 8), yOffset, camera.Width, camera.Height);
spriteBatch.Draw(Textures.Background2, bgTarget, bgSource, bgBlend);
bgSource = new Rectangle(
(int) (camera.Left * 1f / 4), yOffset, camera.Width, camera.Height);
spriteBatch.Draw(Textures.Background3, bgTarget, bgSource, bgBlend);
bgSource = new Rectangle(
(int) (camera.Left * 1f / 2), yOffset, camera.Width, camera.Height);
spriteBatch.Draw(Textures.Background4, bgTarget, bgSource, bgBlend);
spriteBatch.End();
// Set up transformation matrix for drawing world objects.

View File

@ -8,6 +8,8 @@ namespace SemiColinGames {
public static Texture2D Background1;
public static Texture2D Background2;
public static Texture2D Background3;
public static Texture2D Background4;
public static Texture2D Cemetery;
public static Texture2D Crypt;
@ -25,8 +27,10 @@ namespace SemiColinGames {
public static void Load(ContentManager content) {
Player = content.Load<Texture2D>("sprites/ccg/ninja_female");
Background1 = content.Load<Texture2D>("backgrounds/anokolisa/grassland_bg1");
Background2 = content.Load<Texture2D>("backgrounds/anokolisa/grassland_bg2");
Background1 = content.Load<Texture2D>("backgrounds/szadiart/pf4/background1_day");
Background2 = content.Load<Texture2D>("backgrounds/szadiart/pf4/background2a_day");
Background3 = content.Load<Texture2D>("backgrounds/szadiart/pf4/background3_day");
Background4 = content.Load<Texture2D>("backgrounds/szadiart/pf4/background4_day");
Cemetery = content.Load<Texture2D>("tiles/anokolisa/cemetery");
Crypt = content.Load<Texture2D>("tiles/anokolisa/crypt");