Beispiel #1
0
        /// <summary>
        /// Initializes a new SpriteSheet.
        /// </summary>
        /// <param name="texture"></param>
        /// <param name="frameWidth"></param>
        /// <param name="frameHeight"></param>
        /// <param name="framePaddingX"></param>
        /// <param name="framePaddingY"></param>
        public SpriteSheet(Texture texture, int frameWidth, int frameHeight, int framePaddingX, int framePaddingY)
        {
            if (texture == null)
                throw new ArgumentNullException("texture");

            EnsureConstructorArgs(frameWidth, frameHeight, framePaddingX, framePaddingY);

            this.Texture = texture;

            this.rectangles = new List<Rectangle>();

            for (int y = framePaddingY; y < texture.Height; y += frameHeight + framePaddingY)
            {
                for (int x = framePaddingX; x < texture.Width; x += frameWidth + framePaddingX)
                {
                    this.rectangles.Add(new Rectangle(x, y, frameWidth, frameHeight));
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new SpriteSheet.
        /// </summary>
        /// <param name="texture"></param>
        /// <param name="rectangles"></param>
        public SpriteSheet(Texture texture, IList<Rectangle> rectangles)
        {
            if (texture == null)
                throw new ArgumentNullException("texture");

            if (rectangles == null)
                throw new ArgumentNullException("rectangles");

            this.Texture = texture;
            this.rectangles = rectangles;

            for (int i = 0; i < this.rectangles.Count; i++)
            {
                if (this.rectangles[i].Left < 0 ||
                    this.rectangles[i].Top < 0 ||
                    this.rectangles[i].Right > this.Width ||
                    this.rectangles[i].Bottom > this.Height)
                {
                    throw new InvalidOperationException(string.Format("Rectangle {0} is outside of the bounds of the sprite texture.", this.rectangles[i]));
                }
            }
        }
Beispiel #3
0
 /// <summary>
 /// Initializes a new SpriteSheet.
 /// </summary>
 /// <param name="texture"></param>
 /// <param name="frameWidth"></param>
 /// <param name="frameHeight"></param>
 public SpriteSheet(Texture texture, int frameWidth, int frameHeight)
     : this(texture, frameWidth, frameHeight, 0, 0)
 {
 }
        protected override void Initialize()
        {
            this.graphicsDevice.CreateDevice(800, 600);

            // Renderer must be created after the graphics device is created.
            this.graphics = new GraphicsBatch(this.graphicsDevice);

            this.effect = this.contentLoader.Load<Effect>(new LoadEffectArgs()
            {
                FileName = "WavingFlag.fx"
            });

            this.texture = this.contentLoader.Load<Texture>(new LoadTextureArgs()
            {
                FileName = "Flag.png"
            });
        }