예제 #1
0
        //Update the position of the background images
        public void Update(GameTime theGameTime, int theSpeed, VerticalScrollDirection theDirection)
        {
            for (int i = 0; i < mBackgroundSprites.Count; i++)
            {
                if (i == 0 && mBackgroundSprites[i].Position.Y > mBackgroundSprites[i].Size.Height + 400)
                {
                    mBackgroundSprites[i].Position.Y = mBackgroundSprites[mBackgroundSprites.Count - 1].Position.Y - mBackgroundSprites[i].Size.Height;
                }
                else if (i > 0 && mBackgroundSprites[i].Position.Y > mBackgroundSprites[i].Size.Height + 400)
                {
                    mBackgroundSprites[i].Position.Y = mBackgroundSprites[i - 1].Position.Y - mBackgroundSprites[i - 1].Size.Height;
                }
            }

            //Set the Direction based on movement to the left or right that was passed in
            Vector2 aDirection = Vector2.Zero;

            if (theDirection == VerticalScrollDirection.Down)
            {
                aDirection.Y = 1;
            }
            else if (theDirection == VerticalScrollDirection.Up)
            {
                aDirection.Y = -1;
            }

            //Update the postions of each of the Background sprites
            foreach (Sprite aBackgroundSprite in mBackgroundSprites)
            {
                aBackgroundSprite.Update(theGameTime, new Vector2(0, theSpeed), aDirection);
            }
        }
        //Update the position of the background images
        public void Update(GameTime theGameTime, int theSpeed, VerticalScrollDirection theDirection)
        {
            for (int i = 0; i < mBackgroundSprites.Count; i++)
            {
                if (i == 0 && mBackgroundSprites[i].Position.Y > mBackgroundSprites[i].Size.Height+400)
                    mBackgroundSprites[i].Position.Y = mBackgroundSprites[mBackgroundSprites.Count-1].Position.Y - mBackgroundSprites[i].Size.Height;
                else if (i > 0 && mBackgroundSprites[i].Position.Y > mBackgroundSprites[i].Size.Height+400)
                    mBackgroundSprites[i].Position.Y = mBackgroundSprites[i - 1].Position.Y - mBackgroundSprites[i - 1].Size.Height;
            }

            //Set the Direction based on movement to the left or right that was passed in
            Vector2 aDirection = Vector2.Zero;
            if (theDirection == VerticalScrollDirection.Down)
            {
                aDirection.Y = 1;
            }
            else if (theDirection == VerticalScrollDirection.Up)
            {
                aDirection.Y = -1;
            }

            //Update the postions of each of the Background sprites
            foreach (Sprite aBackgroundSprite in mBackgroundSprites)
            {
                aBackgroundSprite.Update(theGameTime, new Vector2(0, theSpeed), aDirection);
            }
        }