You can do animation several ways as skorman has said.
It depends on how you are managing your resources. Using the u,v method is extremely fast, yet requires you to have the texture set to the texture that contains these images. If you are only storing one sprite sequence per image, you won't gain any performance over switching images to do animation.
UV based
Code:
class CAnimSeq;
class CAnimFrame
{
friend class CAnimSeq;
float m_fU,m_fV;
float m_fFrameTime;
float m_fOffsetX,m_fOffsetY;
....
};
class CAnimSeq
{
CAnimFrame *m_pFrames;
DWORD m_dwCurFrame;
DWORD m_dwNumFrames;
DWORD m_dwTexID;
bool m_bActive;
float m_fElapsedTime;
float m_fPosX,m_fPosY
public:
CAnimSeq(void):m_pFrames(NULL),m_dwCurFrame(0),m_fElapsedTime(0.0f),m_fPosX(0.0f),m_fPosY(0.0f),m_dwTexID(0) {}
void Create(DWORD dwNumFrames)
{
m_pFrames=new CAnimFrame[dwNumFrames];
m_bActive=true;
}
....
void Update(float fTimeDelta)
{
m_fElapsedTime+=fTimeDelta;
if (m_fElapsedTime>m_pFrames[m_dwCurFrame])
{
m_fElapsedTime=0.0f;
m_dwCurFrame++;
if (m_dwCurFrame>m_dwNumFrames) m_bActive=false;
}
}
....
};
class CAnimSeqContainer
{
CAnimSeq *m_pSeqs;
....
};
To render, render the current frame image at m_fPosX+m_pFrames[dwCurFrame]->m_fOffsetX,m_fPosY+m_pFrames[dwCurFrame]->m_fOffsetY.
Set the texture to CAnimSeq::m_dwTexID prior to rendering.
You will need more functions to get this working, but it should help.