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;
}
}
{
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