示例#1
0
        /// <summary>
        /// Adds a sprite to the batch of sprites to be rendered, specifying the texture, destination, and source rectangles,
        /// color tint, rotation, origin, effects, and sort depth.
        /// </summary>
        /// <param name="texture">The sprite texture.</param>
        /// <param name="destinationRectangle">A rectangle specifying, in screen coordinates, where the sprite will be drawn.
        /// If this rectangle is not the same size as sourceRectangle, the sprite is scaled to fit.</param>
        /// <param name="sourceRectangle">A rectangle specifying, in texels, which section of the rectangle to draw.
        /// Use null to draw the entire texture.</param>
        /// <param name="color">The color channel modulation to use. Use <see cref="Color.White"/> for full color with
        /// no tinting.</param>
        /// <param name="rotation">The angle, in radians, to rotate the sprite around the origin.</param>
        /// <param name="origin">The origin of the sprite. Specify (0,0) for the upper-left corner.</param>
        /// <param name="effects">Rotations to apply prior to rendering.</param>
        /// <param name="shader">The shader to use on the text being drawn.</param>
        public virtual void Draw(Image texture, Rectangle destinationRectangle, Rectangle?sourceRectangle, Color color,
                                 float rotation, Vector2 origin, SpriteEffects effects = SpriteEffects.None, Shader shader = null)
        {
            if (!IsAssetValid(texture))
            {
                return;
            }

            _sprite.Image    = texture;
            _sprite.Position = new Vector2(destinationRectangle.X, destinationRectangle.Y);
            _sprite.SubRect  = sourceRectangle.HasValue
                                  ? (IntRect)sourceRectangle
                                  : new IntRect(0, 0, (int)_sprite.Image.Width, (int)_sprite.Image.Height);
            _sprite.Color    = color;
            _sprite.Rotation = -MathHelper.ToDegrees(rotation);
            _sprite.Origin   = origin;
            _sprite.FlipX((effects & SpriteEffects.FlipHorizontally) != 0);
            _sprite.FlipY((effects & SpriteEffects.FlipVertically) != 0);
            _sprite.Scale = new Vector2((float)destinationRectangle.Width / _sprite.SubRect.Width,
                                        (float)destinationRectangle.Height / _sprite.SubRect.Height);

            _rt.Draw(_sprite, shader);
        }