コード例 #1
0
        /* The Draw() function is in charge of rendering the BattleLog to the screen. It takes a reference to the game's SpriteBatch. */
        public override void Draw(SpriteBatch spriteBatch)
        {
            /* A Vector2 variable called drawTo is used to hold the current location of the drawing "pen".
             * First, the background is drawn to the BattleLog's position, with no tint colour.
             * Then, the "pen" is moved down and right by 10 pixels. */
            Vector2 drawTo = position;

            spriteBatch.Draw(background, drawTo, Color.White);
            drawTo.X += 10;
            drawTo.Y += 10;

            /* If there's a valid string in currentString, then it will be split into an IEnumerable of lines using PkmnUtils.SplitString(), passing in the string and background width, as well as the width of one character.
             * Then, each of the lines is drawn using the BattleLog's spriteFont in black.
             * Each time a new line is drawn, the "pen" is moved down by the font's line spacing plus three pixels. */
            if (currentString != null)
            {
                IEnumerable <string> lines = PkmnUtils.SplitString(currentString, background.Width / (int)(spriteFont.MeasureString(" ").X));
                foreach (string s in lines)
                {
                    spriteBatch.DrawString(spriteFont, s, drawTo, Color.Black);
                    drawTo.Y += spriteFont.LineSpacing + 3f;
                }
            }
        }