public void Update(GameTime theGameTime, int theSpeed, HorizontalScrollDirection theDirection) { if (theDirection == HorizontalScrollDirection.Left) { //Kijkt of de sprite van het scherm af is van Links foreach (GameObject aBackgroundSprite in backgroundSprites) { if (aBackgroundSprite.mSpritePosition.X < viewport.X - aBackgroundSprite.mSpriteSize.Width) { aBackgroundSprite.mSpritePosition = new Vector2(rightMostSprite.mSpritePosition.X + rightMostSprite.mSpriteSize.Width, viewport.Y); rightMostSprite = aBackgroundSprite; } } } else if (theDirection == HorizontalScrollDirection.Right) { //Kijkt of de sprite van het scherm af is van Rechts foreach (GameObject aBackgroundSprite in backgroundSprites) { if (aBackgroundSprite.mSpritePosition.X > viewport.X + viewport.Width) { aBackgroundSprite.mSpritePosition = new Vector2(leftMostSprite.mSpritePosition.X - leftMostSprite.mSpriteSize.Width, viewport.Y); leftMostSprite = aBackgroundSprite; } } } }
//Update the posotin of the background images public void Update(GameTime theGameTime, int theSpeed, HorizontalScrollDirection theDirection) { if (theDirection == HorizontalScrollDirection.Left) { //Check to see if any of the Background sprites have moved off the screen //if they have, then move them to the right of the chain of scrolling backgrounds foreach (Sprite aBackgroundSprite in mBackgroundSprites) { if (aBackgroundSprite.Position.X < mViewport.X - aBackgroundSprite.Size.Width) { aBackgroundSprite.Position = new Vector2(mRightMostSprite.Position.X + mRightMostSprite.Size.Width, mViewport.Y); mRightMostSprite = aBackgroundSprite; } } } else if (theDirection == HorizontalScrollDirection.Right) { //Check to see if any of the background images have moved off the screen //if they have, then move them to the left of the chain of scrolling backgrounds foreach (Sprite aBackgroundSprite in mBackgroundSprites) { if (aBackgroundSprite.Position.X > mViewport.X + mViewport.Width) { aBackgroundSprite.Position = new Vector2(mLeftMostSprite.Position.X - mLeftMostSprite.Size.Width, mViewport.Y); mLeftMostSprite = aBackgroundSprite; } } } //Set the Direction based on movement to the left or right that was passed in Vector2 aDirection = Vector2.Zero; if (theDirection == HorizontalScrollDirection.Left) { aDirection.X = -1; } else if (theDirection == HorizontalScrollDirection.Right) { aDirection.X = 1; } //Update the postions of each of the Background sprites foreach (Sprite aBackgroundSprite in mBackgroundSprites) { aBackgroundSprite.Update(theGameTime, new Vector2(theSpeed, 0), aDirection); } }