Пример #1
0
 /// <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 = rectDest;
     SetTexture(false, texture);
     this.origin   = origin;
     this.angle    = angle;
     this.depth    = depth;
     this.color    = color;
     this.alpha    = alpha;
     spriteEffects = SpriteEffects.None;
     this.scaleX   = scaleX;
     this.scaleY   = scaleY;
 }
Пример #2
0
 /// <summary>
 /// Initializes an empty sprite. The texture must be set before drawing
 /// to avoid throwing an exception.
 /// </summary>
 public Sprite()
 {
     texture       = null;
     rectSrc       = new SmoothRect(0, 0, 0, 0);
     rectDest      = new SmoothRect(0, 0, 0, 0);
     origin        = new Vector2(0, 0);
     spriteEffects = SpriteEffects.None;
 }
Пример #3
0
 /// <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);
     spriteEffects = SpriteEffects.None;
 }
Пример #4
0
 /// <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 = rectDest;
     SetTexture(false, texture);
     origin        = new Vector2(0, 0);
     spriteEffects = SpriteEffects.None;
 }
Пример #5
0
        /// <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;

            return(SmoothRect.IsIntersecting(tempRect1, tempRect2));
        }
Пример #6
0
 /// <summary>
 /// Initializes a new sprite from an existing one. The texture is
 /// referenced.
 /// </summary>
 public Sprite(Sprite sprite)
 {
     rectSrc       = new SmoothRect(sprite.rectSrc);
     rectDest      = new SmoothRect(sprite.rectDest);
     texture       = sprite.texture;
     origin        = new Vector2(sprite.origin.X, sprite.origin.Y);
     doDrawOffset  = sprite.doDrawOffset;
     angle         = sprite.angle;
     depth         = sprite.depth;
     color         = sprite.color;
     alpha         = sprite.alpha;
     spriteEffects = sprite.spriteEffects;
     scaleX        = sprite.scaleX;
     scaleY        = sprite.scaleY;
     drawBehavior  = sprite.drawBehavior;
 }
Пример #7
0
        /// <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.doDrawOffset)
            {
                tempRect1.X -= spr1.origin.X;
                tempRect1.Y -= spr1.origin.Y;
            }

            return(SmoothRect.IsIntersecting(tempRect1, tempRect2));
        }