/// <summary> /// Adds a background sprite to be scrolled through the screen /// </summary> /// <param name="theAssetName"></param> public void AddBackground(string theAssetName) { BackgroundPart aBackgroundSprite = new BackgroundPart(); aBackgroundSprite.AssetName = theAssetName; mBackgroundSprites.Add(aBackgroundSprite); }
public void AddBackground(string theAssetName, Vector2 size) { BackgroundPart aBackgroundSprite = new BackgroundPart(); aBackgroundSprite.AssetName = theAssetName; aBackgroundSprite.Size = new Rectangle(0, 0, (int)size.X, (int)size.Y); mBackgroundSprites.Add(aBackgroundSprite); }
public ScrollingBackground(ScrollDirection _direction, Vector2 _speed, bool _infinite) { mBackgroundSprites = new List <BackgroundPart>(); mFirstImage = null; mLastImage = null; direction = _direction; theSpeed = _speed; basicSpeed = theSpeed; infinite = _infinite; }
public LoadingScreen(MapOverview overview, TheGreatPaperGame Game) { this.Initialize(); this.Game = Game; loading1 = new Rectangle(0, 356, 270, 178); loading2 = new Rectangle(0, 178, 270, 178); loading3 = new Rectangle(0, 0, 270, 178); currentloading = loading1; background = new Rectangle(300, 0, 1024, 768); backgroundDst = background; backgroundDst.X = 0; backgroundDst.Y = 0; backgroundDst.Width = TGPAContext.Instance.ScreenWidth; backgroundDst.Height = TGPAContext.Instance.ScreenHeight; this.overview = overview; this.previewBG1 = null; this.previewBG1Fadeout = 0.0f; this.previewBG2 = null; this.previewBG2Fadeout = 0.0f; this.IsLoaded = false; }
/// <summary> /// /// </summary> /// <param name="gameTime"></param> public void Update(GameTime gameTime) { if (this.previewBG1 == null) { if ((TGPAContext.Instance.Map != null) && (TGPAContext.Instance.Map.Ended == Map.EndMode.None)) { if (TGPAContext.Instance.Map.Background1.BackgroundSprites.Count > 0) { this.previewBG1 = TGPAContext.Instance.Map.Background1.BackgroundSprites[0]; } } } else { previewBG1Fadeout += 0.01f; if (previewBG1Fadeout > 1f) { previewBG1Fadeout = 1f; if (this.previewBG2 == null) { if (TGPAContext.Instance.Map.Background2.BackgroundSprites.Count > 0) { this.previewBG2 = TGPAContext.Instance.Map.Background2.BackgroundSprites[0]; } } else { previewBG2Fadeout += 0.01f; if (previewBG2Fadeout > 1f) previewBG2Fadeout = 1f; } } } if (gameTime.TotalGameTime.TotalMilliseconds - frameTime > 500f) { frameTime = gameTime.TotalGameTime.TotalMilliseconds; if (currentloading == loading1) currentloading = loading2; else if (currentloading == loading2) currentloading = loading3; else if (currentloading == loading3) currentloading = loading1; } if (TGPAContext.Instance.MapLoaded) { if (TGPAContext.Instance.InputManager.PlayerPressButtonConfirm(TGPAContext.Instance.Player1)) { TGPAContext.Instance.CurrentGameState = GameState.Game; } } this.IsLoaded = TGPAContext.Instance.MapLoaded; }
public void Initialize() { this.previewBG1 = null; this.previewBG1Fadeout = 0.0f; this.previewBG2 = null; this.previewBG2Fadeout = 0.0f; this.IsLoaded = false; }
/// <summary> /// Update the position of the background images /// </summary> /// <param name="theGameTime"></param> public void Update(GameTime theGameTime) { this.Update(theGameTime, BackgroundPart.CalculateScroll(theGameTime, theSpeed, DirectionToVector2(direction))); }
public void Update(GameTime theGameTime, Vector2 scroll) { if (direction == ScrollDirection.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 (BackgroundPart aBackgroundSprite in mBackgroundSprites) { if (aBackgroundSprite.Position.X < -aBackgroundSprite.Size.Width && infinite) { aBackgroundSprite.Position = new Vector2(mFirstImage.Position.X + mFirstImage.Size.Width, 0); mFirstImage = aBackgroundSprite; } } } else if (direction == ScrollDirection.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 (BackgroundPart aBackgroundSprite in mBackgroundSprites) { if (aBackgroundSprite.Position.X > TGPAContext.Instance.ScreenWidth) { aBackgroundSprite.Position = new Vector2(mLastImage.Position.X - mLastImage.Size.Width, 0); mLastImage = aBackgroundSprite; } } } else if (direction == ScrollDirection.Down) { //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 (BackgroundPart aBackgroundSprite in mBackgroundSprites) { if (aBackgroundSprite.Position.Y < -aBackgroundSprite.Size.Height && infinite) { aBackgroundSprite.Position = new Vector2(0, mFirstImage.Position.Y + mFirstImage.Size.Height); mFirstImage = aBackgroundSprite; } } } else if (direction == ScrollDirection.Up) { //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 (BackgroundPart aBackgroundSprite in mBackgroundSprites) { if (aBackgroundSprite.Position.Y > TGPAContext.Instance.ScreenHeight) { aBackgroundSprite.Position = new Vector2(0, mFirstImage.Position.Y - mFirstImage.Size.Height); mFirstImage = aBackgroundSprite; } } } //Set the Direction based on movement to the left or right that was passed in Scroll += scroll; //Update the position of each of the Background sprites foreach (BackgroundPart aBackgroundSprite in mBackgroundSprites) { aBackgroundSprite.Update(theGameTime, theSpeed, DirectionToVector2(direction), scroll); } }
public void LoadContent(ContentManager theContentManager) { //Clear the Sprites currently stored as the left and right ends of the chain mFirstImage = null; mLastImage = null; //The total width of all the sprites in the chain float aWidth = 0; //The total height of all the sprites in the chain float aHeight = 0; //Cycle through all of the Background sprites that have been added //and load their content and position them. foreach (BackgroundPart aBackgroundSprite in mBackgroundSprites) { Logger.Log(LogLevel.Info, "Loading Asset : " + aBackgroundSprite.AssetName); //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 (mFirstImage == null) { //Position the first Background sprite in line at the (0,0) position aBackgroundSprite.Position = Vector2.Zero; mLastImage = aBackgroundSprite; } else { //Position the sprite after the last sprite in line if (direction == ScrollDirection.Left) { aBackgroundSprite.Position = new Vector2(mFirstImage.Position.X + mFirstImage.Size.Width, 0); } else if (direction == ScrollDirection.Right) { aBackgroundSprite.Position = new Vector2(mFirstImage.Position.X - mFirstImage.Size.Width, 0); } else if (direction == ScrollDirection.Up) { aBackgroundSprite.Position = new Vector2(0, mFirstImage.Position.Y - mFirstImage.Size.Height); } else if (direction == ScrollDirection.Down) { aBackgroundSprite.Position = new Vector2(0, mFirstImage.Position.Y + mFirstImage.Size.Height); } } //Set the sprite as the last one in line mFirstImage = aBackgroundSprite; //Increment the width of all the sprites combined in the chain aWidth += aBackgroundSprite.Size.Width; aHeight += aBackgroundSprite.Size.Height; } //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 < TGPAContext.Instance.ScreenWidth * 2) { do { //Add another background image to the chain BackgroundPart aBackgroundSprite = new BackgroundPart(); aBackgroundSprite.AssetName = mBackgroundSprites[aIndex].AssetName; aBackgroundSprite.LoadContent(theContentManager, aBackgroundSprite.AssetName); //aBackgroundSprite.Scale = mViewport.Height / aBackgroundSprite.Size.Height; aBackgroundSprite.Position = new Vector2(mFirstImage.Position.X + mFirstImage.Size.Width, 0); mBackgroundSprites.Add(aBackgroundSprite); mFirstImage = 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 < TGPAContext.Instance.ScreenWidth * 2); } //Same for Height aIndex = 0; if (mBackgroundSprites.Count > 0 && aHeight < TGPAContext.Instance.ScreenHeight * 2) { do { //Add another background image to the chain BackgroundPart aBackgroundSprite = new BackgroundPart(); aBackgroundSprite.AssetName = mBackgroundSprites[aIndex].AssetName; aBackgroundSprite.LoadContent(theContentManager, aBackgroundSprite.AssetName); //aBackgroundSprite.Scale = mViewport.Width / aBackgroundSprite.Size.Width; if (direction == ScrollDirection.Up) { aBackgroundSprite.Position = new Vector2(0, mFirstImage.Position.Y - mFirstImage.Size.Height); } else { aBackgroundSprite.Position = new Vector2(0, mFirstImage.Position.Y + mFirstImage.Size.Height); } mBackgroundSprites.Add(aBackgroundSprite); mFirstImage = aBackgroundSprite; //Add the new background Image's width to the total width of the chain aHeight += aBackgroundSprite.Size.Height; //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 (aHeight < TGPAContext.Instance.ScreenHeight * 2); } }