コード例 #1
0
ファイル: TextEffects.cs プロジェクト: ARLM-Attic/neat
        public virtual void Draw(GameTime gameTime)
        {
            var         font     = Game.GetFont(FontName);
            var         solid    = Game.GetTexture("solid");
            var         n        = Messages.First;
            float       y        = Position.Y;
            const float vspacing = 4.0f;
            const float hspacing = 10.0f;
            Effect      crop     = Game.GetEffect("crop");

            while (n != null)
            {
                Vector2 size      = font.MeasureString(n.Value.Text);
                float   rectWidth = (size.X + 2 * hspacing);
                float   coef      = (float)n.Value.Life * 10 / (float)ElegantMessage.TTL;
                rectWidth = Math.Min(rectWidth, rectWidth * coef);
                if (coef < 1.0f && !n.Value.Dead)
                {
                    n.Value.Dead = true;
                    PlayDeathSound();
                }
                Rectangle bounds = new Rectangle(
                    (int)((Align == ElegantMessageAlignModes.Left ? 0 : -size.X) - hspacing + Position.X),
                    (int)(y),
                    (int)(rectWidth),
                    (int)(size.Y + 2.0f * vspacing));

                Game.SpriteBatch.Draw(solid,
                                      bounds, BackColor);
                y += vspacing;

                Game.SpriteBatch.End();
                Game.PushTarget(target);
                Game.GraphicsDevice.Clear(Color.Transparent);
                Game.SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
                Game.SpriteBatch.DrawString(font, n.Value.Text,
                                            new Vector2((Align == ElegantMessageAlignModes.Left ? 0 : -size.X) + Position.X,
                                                        y),
                                            ForeColor);
                Game.SpriteBatch.End();
                Game.PopTarget();
                Game.SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend,
                                       null, DepthStencilState.None, RasterizerState.CullNone, crop);
                crop.Parameters["top"].SetValue((float)bounds.Top / (float)Game.GameHeight);
                crop.Parameters["down"].SetValue((float)bounds.Bottom / (float)Game.GameHeight);
                crop.Parameters["left"].SetValue((float)bounds.Left / (float)Game.GameWidth);
                crop.Parameters["right"].SetValue((float)bounds.Right / (float)Game.GameWidth);
                Game.SpriteBatch.Draw(target, Vector2.Zero, ForeColor);

                /*Game.SpriteBatch.DrawString(font, n.Value.Text,
                 *  new Vector2((Align == ElegantMessageAlignModes.Left ? 0 : -size.X) + Position.X,
                 *      y),
                 *  ForeColor);*/
                Game.RestartBatch();
                y += vspacing + size.Y;
                n  = n.Next;
            }
        }