Help with 2D animation

harry's picture

Here is the Class am using for the 2D animation:

public class AnimatedTexture
{
  private int framecount;
  private Texture2D myTexture;
  private float TimePerFrame;
  private int Frame;
  private float TotalElapsed;private bool Paused;
  public virtual void Load(
    GraphicsDevice device, ContentManager content,
    string asset, int FrameCount, int FramesPerSec
  )
  {
    framecount = FrameCount;
    //myTexture = Texture2D.FromFile( device, filename );
    myTexture = content.Load(asset);TimePerFrame = (float)1 / FramesPerSec;
    Frame = 0;
    TotalElapsed = 0;
    Paused = false;
  }
  // class AnimatedTexture
  public void UpdateFrame(float elapsed)
  {
    System.Timers.Timer timer = new System.Timers.Timer();
    timer.Start();
    if (Paused)return;
    TotalElapsed += elapsed;
    if (TotalElapsed > TimePerFrame)
    {
      Frame++;
      // Keep the Frame between 0 and the total frames, minus one
      Frame = Frame % (framecount - 1);
      TotalElapsed -= TimePerFrame;
    }
  }
  // class AnimatedTexture
  public virtual void DrawFrame(SpriteBatch Batch, Vector2 screenpos)
  {
    DrawFrame(Batch, Frame, screenpos);
  }
  public void DrawFrame(SpriteBatch Batch, int Frame, Vector2 screenpos)
  {
    int FrameWidth = myTexture.Width / framecount;Rectangle sourcerect =
      new Rectangle(FrameWidth * Frame, 0, FrameWidth, myTexture.Height);
    Batch.Draw(myTexture, screenpos, sourcerect, Color.White);
  }
  public bool IsPaused
  {
    get { return Paused; }
  }
  public void Reset()
  {
    Frame = 0;
    TotalElapsed = 0f;
  }
  public void Stop()
  {
    Pause();
    Reset();
  }
  public void Play()
  {
    Paused = false;
  }
  public void Pause()
  {
    Paused = true;
  }
}

This work fine. But What I need is Block or Shape class that will display two block of animation
side by side. Could some one help me with this?

Cygon: Edited to use the <blockcode> tag for better readability

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Lines and paragraphs break automatically.
  • Allowed HTML tags: <br> <a> <em> <strong> <u> <i> <b> <cite> <blockcode> <code> <ul> <ol> <li> <dl> <dt> <dd> <p> <pre> <span>
  • You can highlight code with any of the following tags: <blockcode>

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.