/// <summary>
 /// Sets all parameters + scaling, except the SpriteEffects used.
 /// </summary>
 /// <param name="rectSrc">
 /// The source rectangle (for spritesheets).
 /// </param>
 /// <param name="rectDest">
 /// The destination rectangle (for position and stretching). Scaled
 /// by default.
 /// </param>
 /// <param name="color">The Color object to be used.</param>
 /// <param name="angle">
 /// The angle of rotation, moving clockwise with right = 0, in radians.
 /// </param>
 /// <param name="depth">
 /// The order in which sprites are drawn. 0 is drawn first.
 /// </param>
 /// <param name="origin">
 /// Where (0,0) is located on the sprite in local coordinates.
 /// </param>
 public Sprite(
     Texture2D tex,
     SmoothRect rectSrc,
     SmoothRect rectDest,
     Vector2 origin,
     float angle,
     int depth,
     Color color,
     float alpha,
     float scaleX,
     float scaleY
     )
 {
     this.rectSrc         = rectSrc;
     this.rectDest.X      = rectDest.X;
     this.rectDest.Y      = rectDest.Y;
     this.rectDest.Width  = (int)(rectDest.Width * scaleX);
     this.rectDest.Height = (int)(rectDest.Height * scaleY);
     SetTexture(false, texture);
     this.origin   = origin;
     this.angle    = angle;
     this.depth    = depth;
     this.color    = Color.White;
     this.alpha    = alpha;
     spriteEffects = SpriteEffects.None;
     this.scaleX   = scaleX;
     this.scaleY   = scaleY;
 }
        public SpriteDraw drawBehavior = SpriteDraw.basic; //Image drawing.

        /// <summary>
        /// Initializes an empty sprite. The texture must be set before drawing
        /// to avoid throwing an exception.
        /// </summary>
        public Sprite()
        {
            rectSrc       = new SmoothRect(0, 0, 0, 0);
            rectDest      = new SmoothRect(0, 0, 0, 0);
            origin        = new Vector2(0, 0);
            color         = Color.White;
            spriteEffects = SpriteEffects.None;
        }
 /// <summary>Initializes a new Sprite to control drawing.</summary>
 /// <param name="doSetDimensions">Whether or not to set the width
 /// and height based on the texture.</param>
 /// <param name="tex">The 2D texture to use.</param>
 public Sprite(
     bool doSetDimensions,
     Texture2D tex)
 {
     rectSrc  = new SmoothRect(0, 0, 0, 0);
     rectDest = new SmoothRect(0, 0, 0, 0);
     SetTexture(doSetDimensions, tex);
     origin        = new Vector2(0, 0);
     color         = Color.White;
     alpha         = 1;
     spriteEffects = SpriteEffects.None;
 }
 /// <summary>Includes source/dest rectangles.</summary>
 /// <param name="doSetDimensions">Whether or not to set the width and height based on the texture.</param>
 /// <param name="tex">The 2D texture to use.</param>
 /// <param name="rectSrc">The source rectangle (for spritesheets).</param>
 /// <param name="rectDest">The destination rectangle (for position and stretching). Scaled by default.</param>
 public Sprite(
     Texture2D tex,
     SmoothRect rectSrc,
     SmoothRect rectDest)
 {
     this.rectSrc         = rectSrc;
     this.rectDest.X      = rectDest.X;
     this.rectDest.Y      = rectDest.Y;
     this.rectDest.Width  = (int)(rectDest.Width * scaleX);
     this.rectDest.Height = (int)(rectDest.Height * scaleY);
     SetTexture(false, texture);
     origin        = new Vector2(0, 0);
     color         = Color.White;
     alpha         = 1;
     spriteEffects = SpriteEffects.None;
 }
 /// <summary>
 /// Initializes a new sprite from an existing one. The texture is
 /// referenced.
 /// </summary>
 public Sprite(Sprite sprite)
 {
     texture       = sprite.texture;
     rectSrc       = new SmoothRect(sprite.rectSrc);
     rectDest      = new SmoothRect(sprite.rectDest);
     origin        = new Vector2(sprite.origin.X, sprite.origin.Y);
     originOffset  = sprite.originOffset;
     angle         = sprite.angle;
     depth         = sprite.depth;
     color         = sprite.color;
     alpha         = sprite.alpha;
     spriteEffects = sprite.spriteEffects;
     scaleX        = sprite.scaleX;
     scaleY        = sprite.scaleY;
     drawBehavior  = sprite.drawBehavior;
 }
        /// <summary>
        /// Checks for a bounding box intersection of two sprites. Takes
        /// scaling and origin into account. Ignores rotation.
        /// </summary>
        public static bool isIntersecting(Sprite spr1, Sprite spr2)
        {
            //Creates smooth rects from the sprite destinations, which
            //already take scaling into account.
            SmoothRect tempRect1 = new SmoothRect(spr1.rectDest);
            SmoothRect tempRect2 = new SmoothRect(spr2.rectDest);

            //Adjusts the rectangles based on the origin.
            tempRect1.X -= spr1.origin.X;
            tempRect1.Y -= spr1.origin.Y;
            tempRect2.X -= spr2.origin.X;
            tempRect2.Y -= spr2.origin.Y;

            if (SmoothRect.IsIntersecting(tempRect1, tempRect2))
            {
                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Checks for a bounding box intersection of two sprites. Takes
        /// scaling and origin into account. Ignores rotation.
        /// </summary>
        public static bool isIntersecting(Sprite spr1, SmoothRect rect2)
        {
            //Creates smooth rects from the sprite and another rectangle,
            //which already take scaling into account.
            SmoothRect tempRect1 = new SmoothRect(spr1.rectDest);
            SmoothRect tempRect2 = new SmoothRect(rect2);

            //Adjusts the rectangles based on the origin.
            if (!spr1.originOffset)
            {
                tempRect1.X -= spr1.origin.X;
                tempRect1.Y -= spr1.origin.Y;
            }

            if (SmoothRect.IsIntersecting(tempRect1, tempRect2))
            {
                return(true);
            }

            return(false);
        }