View Full Version : notifying animation stop

04-12-2011, 05:50 PM
I want to know exactly when the animation stop(ON_FINISH_STOP), not using polling.
Proton has built-in?

04-12-2011, 11:27 PM
The "simple" animation method we've been using doesn't send anything to signal the anim is over.

However, Proton's messaging system makes this pretty easy to do: keep in mind YOU know the exact ending time of the anim, so just have a function get called when it's over.

Here is an example of that added to the animation system example I did earlier for you:

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)));



LogMsg("This whole anim will last %d ms. So let's get a function called at that time to reset the anim", ms);

//call a function on this entity and send in the entity as a parm. If the entity is destroyed this call is destroyed as well
GetMessageManager()->CallEntityFunction(pEnt, ms, "OnAnimFinished", &VarianList(pEnt));


Ok, now "OnAnimFinished" will get called when the anim is done. But now you need to hook into that to make it do something. I'll just link it to a global static function as an example:

//set it up so if OnAnimFinished is hooked into a real function, this should only happen once when you're initting the entity

//And the RestartAnim function would look like this:

void RestartAnim(VariantList *pVList)
Entity *pEnt = pVList->Get(1).GetEntity(); //get the entity parm we called it with

You don't really have to do it the "proton way" though, you could just write your own animation system that just uses a SurfaceAnim object to blit frames as well.