Example implementation of ComplexSprite. Uses 3 sprites: An "Achievement!" title, a description text field, and a black background. Also raises events upon state change.
Inheritance: FontEffectsLib.SpriteTypes.ComplexSprite, IStateful
コード例 #1
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            bgSprite = new GameSprite(Content.Load <Texture2D>("bgImage"), Vector2.Zero, Color.White);
            bgSprite.ScaleToViewport(GraphicsDevice.Viewport);

            titleText1 = new DropInFont(Content.Load <SpriteFont>("GameFont"), new Vector2(viewport.HalfWidth(), -1000), screenSize / 2, new Vector2(0, 20), "Great Minds", Color.OrangeRed);
            titleText1.TargetPosition = new Vector2(titleText1.TargetPosition.X, titleText1.TargetPosition.Y - titleText1.Size.Y / 4);
            titleText1.SetCenterAsOrigin();
            titleText1.ShadowPosition = new Vector2(titleText1.Position.X - 4, titleText1.Position.Y + 4);
            titleText1.ShadowColor    = Color.Black;
            titleText1.StateChanged  += new EventHandler <StateEventArgs>(statefulFont_StateChanged);

            Vector2 titleText2Pos = new Vector2(titleText1.Position.X + titleText1.Size.X / 2, viewport.HalfHeight() + titleText1.Size.Y / 4);

            titleText2 = new FadingFont(Content.Load <SpriteFont>("GameFont"), titleText2Pos, Color.Orange);
            titleText2.Text.Append("Robotics");
            titleText2.FadeStep       /= 5f;
            titleText2.StateChanged   += new EventHandler <StateEventArgs>(titleText2_StateChanged);
            titleText2.Fade            = false;
            titleText2.Position       -= new Vector2(titleText2.Size.X / 2, 0);
            titleText2.ShadowPosition -= new Vector2(titleText2.Size.X / 2, 0);
            titleText2.SetCenterAsOrigin();

            titleText1.Text.Clear();
            titleText1.Text.Append("Great ");

            Vector2 titleText3Pos = new Vector2(titleText1.Position.X + titleText1.Size.X / 2, -2000);

            titleText3 = new DropInFont(Content.Load <SpriteFont>("GameFont"), titleText3Pos, screenSize / 2, new Vector2(0, 20), "Minds", Color.OrangeRed);
            titleText3.TargetPosition = titleText1.TargetPosition;
            titleText3.SetCenterAsOrigin();
            titleText3.ShadowPosition = new Vector2(titleText3.Position.X - 4, titleText3.Position.Y + 4);
            titleText3.ShadowColor    = Color.Black;
            titleText3.StateChanged  += new EventHandler <StateEventArgs>(statefulFont_StateChanged);
            titleText3.Tag            = GameTags.StartTitleFadeIn;

            Vector2 byPos = new Vector2(titleText1.Position.X - 100, -1000);

            by = new AccelDropInFont(Content.Load <SpriteFont>("GameFont"), byPos, screenSize / 2, new Vector2(0, 5), "By:", Color.Orange, new Vector2(0, 1.5f));
            by.TargetPosition = titleText1.TargetPosition - new Vector2(100, 100);
            by.SetCenterAsOrigin();
            by.ShadowPosition = new Vector2(by.Position.X - 4, by.Position.Y + 4);
            by.ShadowColor    = Color.Black;
            by.MaxDropSpeed   = new Vector2(15, 15);

            crashEffect = Content.Load <SoundEffect>("Crash");

            //Obtained from http://www.freesound.org/people/EdgardEdition/sounds/113095/
            coinsEffect = Content.Load <SoundEffect>("insertcoin");

            insertCoins = new ArcadeFont(Content.Load <SpriteFont>("ArcadeFont"), new Vector2(300, 400), Color.Red, Color.White, Color.Yellow, Color.Blue);
            insertCoins.ShadowPosition       = new Vector2(insertCoins.Position.X - 1, insertCoins.Position.Y + 1);
            insertCoins.ColorCyclesPerSecond = 15;  //Default is 10; smaller number blinks slower
            insertCoins.Text.Append("INSERT COINS");
            insertCoins.IsVisible = false;

            slidingText = new StatefulSequence <SlidingFont>(SlidingFont.FontState.Done, typeof(SlidingFont.FontState));

            Vector2 targetPos = new Vector2(505, 400);

            foreach (char letter in "COOL")
            {
                slidingText.Add(new SlidingFont(Content.Load <SpriteFont>("SlidingFont"), new Vector2(50, 350), targetPos, 2f, letter.ToString(), Color.Red)
                {
                    EnableShadow = false, IsVisible = false, TargetTolerance = 0.625f
                });
                targetPos.X += slidingText[slidingText.Count - 1].Size.X; //Magic # - bad idea
            }

            targetPos = new Vector2(505, 420);
            random    = new Random();

            foreach (char letter in "Effects!")
            {
                slidingText.Add(new SlidingFont(Content.Load <SpriteFont>("SlidingFont"), new Vector2(random.Next(0, GraphicsDevice.Viewport.Width), random.Next(0, GraphicsDevice.Viewport.Height)), targetPos, 1f + (float)random.NextDouble(), letter.ToString(), Color.Red)
                {
                    EnableShadow = false, IsVisible = false
                });
                targetPos.X += slidingText[slidingText.Count - 1].Size.X; //Magic # - bad idea
            }

            coolPanel           = new TexturePanel(Content.Load <Texture2D>("WavyEffect"), new Vector2(120, 60), Vector2.One * .5f, new Vector2(550, 425), new Color(60, 60, 60, 128));
            coolPanel.IsVisible = false;

            insertFive           = new AchievementPanel(0, Content.Load <SpriteFont>("SlidingFont"), Content.Load <SpriteFont>("ArcadeFont"), "Insert 5 coins", GraphicsDevice);
            insertFive.Condition = AchievementPanel.AreFiveCoinsInsert;

            donateHundred           = new AchievementPanel(0, Content.Load <SpriteFont>("SlidingFont"), Content.Load <SpriteFont>("ArcadeFont"), "Donate $100 to GMR", GraphicsDevice);
            donateHundred.Condition = AchievementPanel.AreHundredDollarsDonated;

            noCoinSpam           = new AchievementPanel(0, Content.Load <SpriteFont>("SlidingFont"), Content.Load <SpriteFont>("ArcadeFont"), "Don't insert coins for 30 seconds", GraphicsDevice);
            noCoinSpam.Position  = new Vector2(GraphicsDevice.Viewport.Width - noCoinSpam.Width, noCoinSpam.Position.Y);
            noCoinSpam.Condition = AchievementPanel.IsNoCoinsInsertedAtThirtySeconds;

            allAchievementsDone           = new AchievementPanel(0, Content.Load <SpriteFont>("SlidingFont"), Content.Load <SpriteFont>("ArcadeFont"), "Finish all achievements", GraphicsDevice);
            allAchievementsDone.Condition = delegate(GameTime gt) { return(standardAchievementsCompleted); };

            StatefulSequence <AchievementPanel> allAchievementPanels = new StatefulSequence <AchievementPanel>(AchievementPanel.PanelState.Done, typeof(AchievementPanel.PanelState));

            allAchievementPanels.Add(noCoinSpam);
            allAchievementPanels.Add(donateHundred);
            allAchievementPanels.Add(insertFive);

            allAchievementPanels.SequenceReachedMonitoredState += new StatefulSequence <AchievementPanel> .MonitoredStateReached(allAchievementPanels_SequenceReachedMonitoredState);

            slidingText.SequenceReachedMonitoredState += new StatefulSequence <SlidingFont> .MonitoredStateReached(slidingText_SequenceReachedMonitoredState);

            colorfulTypingText = new TypingFont(Content.Load <SpriteFont>("ArcadeFont"), new Vector2(200, 0), Color.Black, "Typing text here", TimeSpan.FromMilliseconds(200));
            colorfulTypingText.StateChanged   += new EventHandler <StateEventArgs>(typingText_StateChanged);
            colorfulTypingText.CharacterTyped += new EventHandler <TypingFont.CharacterTypedEventArgs>(typingText_CharacterTyped);
            colorfulTypingText.Tag             = "1";
            colorfulTypingText.Start();

            regularTypingText = new TypingFont(Content.Load <SpriteFont>("ArcadeFont"), new Vector2(400, 0), Color.Black, "... and more typing text here...", TimeSpan.FromMilliseconds(50));
            regularTypingText.StateChanged += new EventHandler <StateEventArgs>(typingText_StateChanged);
            regularTypingText.Tag           = "2";
        }
コード例 #2
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            bgSprite = new GameSprite(Content.Load<Texture2D>("bgImage"), Vector2.Zero, Color.White);
            bgSprite.ScaleToViewport(GraphicsDevice.Viewport);

            titleText1 = new DropInFont(Content.Load<SpriteFont>("GameFont"), new Vector2(viewport.HalfWidth(), -1000), screenSize / 2, new Vector2(0, 20), "Great Minds", Color.OrangeRed);
            titleText1.TargetPosition = new Vector2(titleText1.TargetPosition.X, titleText1.TargetPosition.Y - titleText1.Size.Y / 4);
            titleText1.SetCenterAsOrigin();
            titleText1.ShadowPosition = new Vector2(titleText1.Position.X - 4, titleText1.Position.Y + 4);
            titleText1.ShadowColor = Color.Black;
            titleText1.StateChanged += new EventHandler<StateEventArgs>(statefulFont_StateChanged);

            Vector2 titleText2Pos = new Vector2(titleText1.Position.X + titleText1.Size.X / 2, viewport.HalfHeight() + titleText1.Size.Y / 4);
            titleText2 = new FadingFont(Content.Load<SpriteFont>("GameFont"), titleText2Pos, Color.Orange);
            titleText2.Text.Append("Robotics");
            titleText2.FadeStep /= 5f;
            titleText2.StateChanged += new EventHandler<StateEventArgs>(titleText2_StateChanged);
            titleText2.Fade = false;
            titleText2.Position -= new Vector2(titleText2.Size.X / 2, 0);
            titleText2.ShadowPosition -= new Vector2(titleText2.Size.X / 2, 0);
            titleText2.SetCenterAsOrigin();

            titleText1.Text.Clear();
            titleText1.Text.Append("Great ");

            Vector2 titleText3Pos = new Vector2(titleText1.Position.X + titleText1.Size.X / 2, -2000);
            titleText3 = new DropInFont(Content.Load<SpriteFont>("GameFont"), titleText3Pos, screenSize / 2, new Vector2(0, 20), "Minds", Color.OrangeRed);
            titleText3.TargetPosition = titleText1.TargetPosition;
            titleText3.SetCenterAsOrigin();
            titleText3.ShadowPosition = new Vector2(titleText3.Position.X - 4, titleText3.Position.Y + 4);
            titleText3.ShadowColor = Color.Black;
            titleText3.StateChanged += new EventHandler<StateEventArgs>(statefulFont_StateChanged);
            titleText3.Tag = GameTags.StartTitleFadeIn;

            Vector2 byPos = new Vector2(titleText1.Position.X - 100, -1000);
            by = new AccelDropInFont(Content.Load<SpriteFont>("GameFont"), byPos, screenSize / 2, new Vector2(0, 5), "By:", Color.Orange, new Vector2(0, 1.5f));
            by.TargetPosition = titleText1.TargetPosition - new Vector2(100, 100);
            by.SetCenterAsOrigin();
            by.ShadowPosition = new Vector2(by.Position.X - 4, by.Position.Y + 4);
            by.ShadowColor = Color.Black;
            by.MaxDropSpeed = new Vector2(15, 15);

            crashEffect = Content.Load<SoundEffect>("Crash");

            //Obtained from http://www.freesound.org/people/EdgardEdition/sounds/113095/
            coinsEffect = Content.Load<SoundEffect>("insertcoin");

            insertCoins = new ArcadeFont(Content.Load<SpriteFont>("ArcadeFont"), new Vector2(300, 400), Color.Red, Color.White, Color.Yellow, Color.Blue);
            insertCoins.ShadowPosition = new Vector2(insertCoins.Position.X - 1, insertCoins.Position.Y + 1);
            insertCoins.ColorCyclesPerSecond = 15;  //Default is 10; smaller number blinks slower
            insertCoins.Text.Append("INSERT COINS");
            insertCoins.IsVisible = false;

            slidingText = new StatefulSequence<SlidingFont>(SlidingFont.FontState.Done, typeof(SlidingFont.FontState));

            Vector2 targetPos = new Vector2(505, 400);
            foreach (char letter in "COOL")
            {
                slidingText.Add(new SlidingFont(Content.Load<SpriteFont>("SlidingFont"), new Vector2(50, 350), targetPos, 2f, letter.ToString(), Color.Red) { EnableShadow = false, IsVisible = false, TargetTolerance = 0.625f });
                targetPos.X += slidingText[slidingText.Count - 1].Size.X; //Magic # - bad idea
            }

            targetPos = new Vector2(505, 420);
            random = new Random();

            foreach (char letter in "Effects!")
            {
                slidingText.Add(new SlidingFont(Content.Load<SpriteFont>("SlidingFont"), new Vector2(random.Next(0, GraphicsDevice.Viewport.Width), random.Next(0, GraphicsDevice.Viewport.Height)), targetPos, 1f + (float)random.NextDouble(), letter.ToString(), Color.Red) { EnableShadow = false, IsVisible = false });
                targetPos.X += slidingText[slidingText.Count - 1].Size.X; //Magic # - bad idea
            }

            coolPanel = new TexturePanel(Content.Load<Texture2D>("WavyEffect"), new Vector2(120, 60), Vector2.One * .5f, new Vector2(550, 425), new Color(60, 60, 60, 128));
            coolPanel.IsVisible = false;

            insertFive = new AchievementPanel(0, Content.Load<SpriteFont>("SlidingFont"), Content.Load<SpriteFont>("ArcadeFont"), "Insert 5 coins", GraphicsDevice);
            insertFive.Condition = AchievementPanel.AreFiveCoinsInsert;

            donateHundred = new AchievementPanel(0, Content.Load<SpriteFont>("SlidingFont"), Content.Load<SpriteFont>("ArcadeFont"), "Donate $100 to GMR", GraphicsDevice);
            donateHundred.Condition = AchievementPanel.AreHundredDollarsDonated;

            noCoinSpam = new AchievementPanel(0, Content.Load<SpriteFont>("SlidingFont"), Content.Load<SpriteFont>("ArcadeFont"), "Don't insert coins for 30 seconds", GraphicsDevice);
            noCoinSpam.Position = new Vector2(GraphicsDevice.Viewport.Width - noCoinSpam.Width, noCoinSpam.Position.Y);
            noCoinSpam.Condition = AchievementPanel.IsNoCoinsInsertedAtThirtySeconds;

            allAchievementsDone = new AchievementPanel(0, Content.Load<SpriteFont>("SlidingFont"), Content.Load<SpriteFont>("ArcadeFont"), "Finish all achievements", GraphicsDevice);
            allAchievementsDone.Condition = delegate(GameTime gt) { return standardAchievementsCompleted; };

            StatefulSequence<AchievementPanel> allAchievementPanels = new StatefulSequence<AchievementPanel>(AchievementPanel.PanelState.Done, typeof(AchievementPanel.PanelState));
            allAchievementPanels.Add(noCoinSpam);
            allAchievementPanels.Add(donateHundred);
            allAchievementPanels.Add(insertFive);

            allAchievementPanels.SequenceReachedMonitoredState += new StatefulSequence<AchievementPanel>.MonitoredStateReached(allAchievementPanels_SequenceReachedMonitoredState);

            slidingText.SequenceReachedMonitoredState += new StatefulSequence<SlidingFont>.MonitoredStateReached(slidingText_SequenceReachedMonitoredState);

            colorfulTypingText = new TypingFont(Content.Load<SpriteFont>("ArcadeFont"), new Vector2(200, 0), Color.Black, "Typing text here", TimeSpan.FromMilliseconds(200));
            colorfulTypingText.StateChanged += new EventHandler<StateEventArgs>(typingText_StateChanged);
            colorfulTypingText.CharacterTyped += new EventHandler<TypingFont.CharacterTypedEventArgs>(typingText_CharacterTyped);
            colorfulTypingText.Tag = "1";
            colorfulTypingText.Start();

            regularTypingText = new TypingFont(Content.Load<SpriteFont>("ArcadeFont"), new Vector2(400, 0), Color.Black, "... and more typing text here...", TimeSpan.FromMilliseconds(50));
            regularTypingText.StateChanged += new EventHandler<StateEventArgs>(typingText_StateChanged);
            regularTypingText.Tag = "2";
        }