Game Development Community

Animation frame getting/setting inconsistency?

by Eero Karvonen · in Torque 2D Beginner · 01/20/2014 (10:10 am) · 8 replies

Hi,

I get this error message,
ImageFrameProviderCore::setAnimationFrame() - Animation Frame-Index Invalid (frame#31 of 9 in a:Animation)
because the gotten frame index is apparently out of range. My asset file picks these frames from a spritesheet:
AnimationFrames="22 23 24 25 26 27 28 29 30 31"

I got it with this,
%frame = %sprite.getAnimationFrame();
And tried to set it with this,
%sprite.setAnimationFrame(%frame);

Can someone explain why this inconsistency; getting apparently picks the absolute frame id on the spritesheet, but setting expects a relative frame id? And how is it possible to convert the absolute id to relative id?

#1
01/20/2014 (10:59 am)
Yeah, this is probably not the expected behavior. Normally I'd get frames, get a count and index them manually to avoid this issue - but it really should be fixed in the engine....
#2
01/20/2014 (1:44 pm)
Now I did that. I don't like the way, but it serves the purpose for now. :)
#3
01/20/2014 (2:23 pm)
I'm working on getting the named image cell/frame feature ported from the spine branch - I can see if there's an obvious error in the code regarding numerical animation frames since I have been fighting in this section of the engine for a few days now. Particles keep crashing the engine and unfortunately I'm a poor C++ debugger. :-/
#4
01/21/2014 (4:56 am)
@Mike - I bet I know why the particles are crashing, since I ran into the same problem while implementing the named cells. I just shot you an e-mail. If it's in one of your forks, I can help debug and resolve it tonight after work.

While I'm there, I can resolve the bug in the original post.
#5
01/21/2014 (10:01 am)
Thanks Mich.

In regards to the original post, I looked at this and yeah, getAnimationFrame is returning the image frame number and not the animation frame number. It's an important difference because you can have animation frames like this:

<AnimationAsset
    AnimationName="FireAnimation"
    Image="EffectsModule:FireImage"
    AnimationFrames="0 1 2 3 4 5 4 3 2 1"
/>
where you can have multiple images frames numbers specified. How is the engine to know which image frame #1 to go to, the one at the beginning of the animation sequence or the one at the end? This is why getAnimationFrame needs to return the relative animation frame.
#6
04/22/2014 (4:08 am)
%currAniFrame = %this.getAnimationFrame();
%this.setAnimationFrame(%currAniFrame);

i also have this problem
ImageFrameProviderCore::setAnimationFrame() - Animation Frame-Index Invalid (frame#2 of 1 in slot1:numAnim2)


#7
04/22/2014 (7:49 am)
See reply #1 until the fix makes it into general circulation....
#8
04/22/2014 (8:28 am)
This has been fixed already in the development branch (which you can use now) and will appear in T2D 3.0.

/*! Gets current frame index used in the animation. IMPORTANT: this is not the image frame number!
    @return The current numerical animation frame
*/
ConsoleMethodWithDocs(SpriteBase, getAnimationFrame, ConsoleInt, 2, 2, ())

....

/*! Gets current numerical image frame used in the animation.
    @return The current numerical animation frame
*/
ConsoleMethodWithDocs(SpriteBase, getAnimationImageFrame, ConsoleInt, 2, 2, ())

....

/*! Gets current named image frame used in the animation.
    @return The current named animation frame
*/
ConsoleMethodWithDocs(SpriteBase, getAnimationNamedImageFrame, ConsoleString, 2, 2, ())