Beispiel #1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="spriteSheet"></param>
        public Sprite(SpriteSheet spriteSheet)
        {
            if (spriteSheet == null)
                throw new ArgumentNullException("spriteSheet");

            this.Sheet = spriteSheet;

            this.Color = Color.White;

            this.children = new List<Sprite>();
            this.readOnlyChildren = new ReadOnlyCollection<Sprite>(this.children);
        }
 /// <summary>
 /// Determines if there is overlap in the non-transparent pixels between two SpriteSheets.
 /// </summary>
 /// <param name="spriteSheetA">The first SpriteSheet.</param>
 /// <param name="destA">The destination rectangle for SpriteSheet A.</param>
 /// <param name="currentFrameA">The current frame for SpriteSheet A.</param>
 /// <param name="spriteSheetB">The second SpriteSheet.</param>
 /// <param name="destB">The destination rectangle for SpriteSheet B.</param>
 /// <param name="currentFrameB">The current frame for SpriteSheet B.</param>
 /// <returns></returns>
 public static bool PerPixelIntersect(SpriteSheet spriteSheetA, Rectangle destA, int currentFrameA,
     SpriteSheet spriteSheetB, Rectangle destB, int currentFrameB)
 {
     return PerPixelIntersect(spriteSheetA.GetColorData(), destA, spriteSheetA[currentFrameA], spriteSheetA.Texture.Width,
                              spriteSheetB.GetColorData(), destB, spriteSheetB[currentFrameB], spriteSheetB.Texture.Width);
 }
Beispiel #3
0
        public void DrawSprite(SpriteSheet spriteSheet, int frame, Matrix transform, Color color)
        {
            if (spriteSheet == null)
                throw new ArgumentNullException("spriteSheet");

            this.SetTexture(spriteSheet.Texture.InternalTexture, spriteSheet.Texture.InternalWidth, spriteSheet.Texture.InternalHeight);

            Rectangle source = spriteSheet[frame];

            Vector2 v1 = Vector2.Transform(new Vector2(0, 0), transform);
            Vector2 v2 = Vector2.Transform(new Vector2(source.Width, 0), transform);
            Vector2 v3 = Vector2.Transform(new Vector2(source.Width, source.Height), transform);
            Vector2 v4 = Vector2.Transform(new Vector2(0, source.Height), transform);

            this.AddQuad(v1, color, v2, color, v3, color, v4, color, source);
        }
        /// <summary>
        /// Determines if there is overlap in the non-transparent pixels between two SpriteSheets.
        /// </summary>
        /// <param name="spriteSheetA">The first SpriteSheet.</param>
        /// <param name="positionA">The position of SpriteSheet A.</param>
        /// <param name="currentFrameA">The current frame for SpriteSheet A.</param>
        /// <param name="spriteSheetB">The second SpriteSheet.</param>
        /// <param name="positionB">The position of SpriteSheet B.</param>
        /// <param name="currentFrameB">The current frame for SpriteSheet B.</param>
        /// <returns></returns>
        public static bool PerPixelIntersect(SpriteSheet spriteSheetA, Vector2 positionA, int currentFrameA,
            SpriteSheet spriteSheetB, Vector2 positionB, int currentFrameB)
        {
            Rectangle srcA = spriteSheetA[currentFrameA];
            Rectangle srcB = spriteSheetB[currentFrameB];

            return PerPixelIntersect(spriteSheetA, new Rectangle((int)positionA.X, (int)positionA.Y, srcA.Width, srcA.Height), currentFrameA,
                                     spriteSheetB, new Rectangle((int)positionB.X, (int)positionB.Y, srcB.Width, srcB.Height), currentFrameB);
        }
Beispiel #5
0
        public void DrawSprite(SpriteSheet spriteSheet, int frame, Vector2 position, Color color)
        {
            if (spriteSheet == null)
                throw new ArgumentNullException("spriteSheet");

            this.SetTexture(spriteSheet.Texture.InternalTexture, spriteSheet.Texture.InternalWidth, spriteSheet.Texture.InternalHeight);

            Rectangle frameRect = spriteSheet[frame];

            this.AddQuad(
                new Vector2(position.X, position.Y),
                color,
                new Vector2(position.X + frameRect.Width, position.Y),
                color,
                new Vector2(position.X + frameRect.Width, position.Y + frameRect.Height),
                color,
                new Vector2(position.X, position.Y + frameRect.Height),
                color,
                frameRect);
        }