-
Animation
This is an area where I really need some help. Really really.
For animated map tiles (water etc) I was thinking about having one image file per frame, loading them in at load time then cycling through them during the render loop. Does this sound about right?
The biggy is character animation. Big in that I have absolutely no idea how to make a start with it.
Vital info:
OpenGL, using orthographic mode.
-
Depending on what you're animating for the tiles, you may be able to get away with UV scrolling. If not, cycling through different images is probably your best option. The only other option would be to animate them procedurally, which means creating the texture based on some coded algorithm.
Character animation can be done the same way. It might be worth it to look into setting up characters in tree like structure, so you only have to animate certain areas. However, the overhead of managing the tree and the headaches of writing it could make it completely not worth the time.
-
Yeah I am looking for something relatively simple - tis my first game after all. I've taken oath with myself to actually finish this one too :eek:
EDIT: I mean first game using a graphics API.
-
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.
-
Thanks Bubba :)
I'll have a fiddle with this and if I have any problems, I'll post them here (oh happy happy joy joy joy).