Exemple #1
0
        public override void Draw(SpriteBatch batch, Rectangle bounds, Matrix transform, float alpha)
        {
            if (alpha > 0)
            {
                GraphicsDevice.ScissorRectangle = ScreenHelper.CheckScissorRect(bounds);
                batch.Begin(
                    SpriteSortMode.Deferred,
                    alpha == 1 ? BlendState.AlphaBlend : BlendState.AlphaBlend,
                    SamplerState.LinearClamp,
                    DepthStencilState.None,
                    scissorEnabled,
                    null,
                    transform);

                var cx = (int)Math.Ceiling(
                    (float)bounds.Width / (float)Texture.Width);

                var cy = (int)Math.Ceiling(
                    (float)bounds.Height / (float)Texture.Height);

                for (var y = 0; y < Math.Max(1, cy); y++)
                {
                    for (var x = 0; x < Math.Max(1, cx); x++)
                    {
                        batch.Draw(
                            Texture,
                            new Microsoft.Xna.Framework.Rectangle(
                                bounds.X + x * Texture.Width,
                                bounds.Y + y * Texture.Height,
                                Texture.Width,
                                Texture.Height),
                            null,
                            Microsoft.Xna.Framework.Color.White * alpha,
                            0,
                            new Vector2(),
                            SpriteEffects.None,
                            0);
                    }
                }
                batch.End();
            }
        }