View Full Version : question about sprite animation

04-11-2011, 11:26 AM
How Could I ainmate multiple line sprite like this?
I found a function(AnimateEntity) that support only one line sprites.

And one more question.
AnimateEntity has animSpeedMS arg.
Are There any method to set up the every single frame time?

Thanks in advance.

04-11-2011, 01:24 PM
Hmm, you're right. AnimateEntity assumes the anim is a single line, either horizontal or vertical.

Here is a way to play the whole grid, and also get per-frame ms timing. It schedules every frame to play in advance.

//untested code...

void AnimateOneLoop(Entity *pEnt)
EntityComponent *pComp = pEnt->GetComponentByName("OverlayRender");

int framesX = pComp->GetVar("totalFramesX")->GetUINT32();
int framesY = pComp->GetVar("totalFramesX")->GetUINT32();

int delayMS = 100; //100 ms per frame
int ms = 0;

for (int y=0; y < framesY; y++)
for (int x=0; x <framesX; x++)
ms += delayMS; //speed can change to anything here, so you have per frame control
GetMessageManager()->SetComponentVariable(pComp, ms, "frameX", Variant(uint32(x)));
GetMessageManager()->SetComponentVariable(pComp, ms, "frameY", Variant(uint32(y)));




//load the image in a RenderOverlayComponent
Entity *pEnt = CreateOverlayEntity(pParent, "myEnt", "media/donut.png");

//tell the component about the grid dimensions so it will draw frames
SetupAnimEntity(pEntity, 5, 6); //because the image is 5 X 6
AnimateOneLoop(pEntity); //play through the anim once

So that would play the anim once. You could schedule it to run another AnimateOneLoop at the end to keep looping.

If you need more fancy controls or want to have hundreds of these like, for a game, I'd probably just try to use a SurfaceAnim directly. (could throw it in a Component or just use it raw from something else)

PS: I totally recognize that image from waaaay back when I was learning DirectX 5 for Dink.. haha.