All pastes #589897 Raw Edit

Anonymous

public text v1 · immutable
#589897 ·published 2007-06-26 08:06 UTC
rendered paste body
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace Tiles
{
    class AnimatedSprite
    {
        public AnimatedSprite(int frameCount, GraphicsDeviceManager graphics)
        {
            frames = frameCount;
            Graphics = graphics;
        }
        private int delayTime = 30;
        private int currentTime = 1;
        private int currentFrame = 0;
        private GraphicsDeviceManager Graphics;
        private Texture2D texture;
        private Color color;
        public List<Texture2D> textures = new List<Texture2D>();
        private Vector2 position;

        private float layer;
        private int frames;

        #region Properties

        public Texture2D Texture
        {
            get { return texture; }
            set { texture = value; }
        }

        public Vector2 Position
        {
            get { return position; }
            set { position = value; }
        }

        public Color Color
        {
            get { return color; }
            set { color = value; }
        }

        public float Layer
        {
            get { return layer; }
            set { layer = value; }
        }
        #endregion

        public void Draw(SpriteBatch spriteBatch)
        { 
            Rectangle sourceRectangle = new Rectangle(0, 0, 320, 240);

            if (currentTime == delayTime)
            {
                Graphics.GraphicsDevice.Clear(Color.Black);
                spriteBatch.Draw(textures[currentFrame],
                 new Vector2(50, 50),
                sourceRectangle,
                color,
                0.0f,
                new Vector2(0, 0),
                1.0f,
                SpriteEffects.None,
                layer);
                if (currentFrame < textures.Count - 1)
                {
                    currentFrame++;
                }
                else
                {
                    currentFrame = 0;
                }
            }
            else
            {
                currentTime++;
            }
        }

    }
}