public override void LoadContent(ContentManager theContentManager) { //Clear the Sprites currently stored as the left and right ends of the chain mRightMostSprite = null; mLeftMostSprite = null; //The total width of all the sprites in the chain float aWidth = 0; //Cycle through all of the Background sprites that have been added //and load their content and position them. foreach (ImageSprite aBackgroundSprite in mBackgroundSprites) { //Load the sprite's content and apply it's scale, the scale is calculate by figuring //out how far the sprite needs to be stretech to make it fill the height of the viewport aBackgroundSprite.LoadContent(theContentManager, aBackgroundSprite.AssetName); aBackgroundSprite.Scale = mViewport.Height / aBackgroundSprite.Size.Height; //If the Background sprite is the first in line, then mLastInLine will be null. if (mRightMostSprite == null) { //Position the first Background sprite in line at the (0,0) position aBackgroundSprite.Position = new Vector2(mViewport.X, mViewport.Y); mLeftMostSprite = aBackgroundSprite; } else { //Position the sprite after the last sprite in line aBackgroundSprite.Position = new Vector2(mRightMostSprite.Position.X + mRightMostSprite.Size.Width, mViewport.Y); } //Set the sprite as the last one in line mRightMostSprite = aBackgroundSprite; //Increment the width of all the sprites combined in the chain aWidth += aBackgroundSprite.Size.Width; } //If the Width of all the sprites in the chain does not fill the twice the Viewport width //then we need to cycle through the images over and over until we have added //enough background images to fill the twice the width. int aIndex = 0; if (mBackgroundSprites.Count > 0 && aWidth < mViewport.Width * 2) { do { //Add another background image to the chain ImageSprite aBackgroundSprite = new ImageSprite(); aBackgroundSprite.AssetName = mBackgroundSprites[aIndex].AssetName; aBackgroundSprite.LoadContent(theContentManager, aBackgroundSprite.AssetName); aBackgroundSprite.Scale = mViewport.Height / aBackgroundSprite.Size.Height; aBackgroundSprite.Position = new Vector2(mRightMostSprite.Position.X + mRightMostSprite.Size.Width, mViewport.Y); mBackgroundSprites.Add(aBackgroundSprite); mRightMostSprite = aBackgroundSprite; //Add the new background Image's width to the total width of the chain aWidth += aBackgroundSprite.Size.Width; //Move to the next image in the background images //If we've moved to the end of the indexes, start over aIndex += 1; if (aIndex > mBackgroundSprites.Count - 1) { aIndex = 0; } } while (aWidth < mViewport.Width * 2); } }