Start animations from random or specific frame.

jimjim
edited September 2013 in Help request
I am afraid there is no easy way to this is orx or am I missing something ? I have seen sausages twin animation post, and I think its possible but not as easy, just as setting SetCurrentAnimaFrame(...) or StartAnimFromFrame(...)

So, basically I am looking for a way to start an animation from a particular frame. Without messing with keyduration.Because not all frame should have same keyDuration.

This is handy because if you have some animations of common objects, like rotating coin animations, it seems odd if they all start from same frame.

Comments

  • edited September 2013
    Usually this is achieved by starting the animation itself at different times.

    Other than that, you should be able to do what you want with orxAnimPointer_SetTime() when your animation starts (by listening to the corresponding event for example).
  • jimjim
    edited September 2013
    Okay, I think I am getting something, so if I want to implement start frame or something like that I need to know some extra information so that I can calculate exact time to start animation from a particular frame. It would be done only once, its some sort of book keeping I guess.

    For that I need to traverse through all the animation list and their key data. How do I do it ?
  • edited September 2013
    You can access all the values for all the keys via the orxAnim API, but not their timestamps.

    What is it you'd like to achieve by doing so? If you need to start an animation to a given frame, why don't you cut that animation into parts instead?
  • jimjim
    edited September 2013
    I have used a few animations tools, and they have options to start an animation from a particular frame, also setting current animation frame, slowing or speeding up animation. So I was wondering how trivial it would be integrate their features in orx.
  • edited September 2013
    I could add accessors for specifying a start frame, but only if there's a real advantage for a common use. :)

    As for changing the animation speed, you can play with the Frequency attribute. Or link a clock to an object but in that case it won't affect only animations but everything (sound, dynamics, ...).
  • jimjim
    edited September 2013
    Common use could be when we have many animated objects in our scene, they could be shiny animated stone or birds. If they all start from same frame it would look bad.
    Other than this, I don't see much usage of slowing or speeding up only animations.

    If one could manually change their animations frames to nextFrame() or previousFrame(), then slowing down or speeding up wont be difficult to achieve.

    But I could access keyduration of animations from config, and if they have same keyduration, this would be then easier to do, right ? I have little idea on what things affect animations in orx.
  • edited September 2013
    jim wrote:
    Common use could be when we have many animated objects in our scene, they could be shiny animated stone or birds. If they all start from same frame it would look bad.

    But we already solved that issue in my first answer! You don't need to know which frames are played at which timestamp to do that.
    All you have to do is called orxAnimPointer_SetTime() with a random value comprised between 0 and orxAnim_GetLength(). So basically:
    // Gets animpointer
    orxANIMPOINTER *pstAnimPointer = orxOBJECT_GET_STRUCTURE(pstObject, ANIMPOINTER);
    
    // Gets animset
    orxANIMSET *pstAnimSet = orxAnimPointer_GetAnimSet(pstAnimPointer);
    
    // Gets random start time
    orxFLOAT fStartTime = orxMath_GetRandomFloat(orxFLOAT_0, orxAnim_GetLength(orxAnimSet_GetAnim(pstAnimSet, orxAnimPointer_GetCurrentAnim(pstAnimPointer)));
    
    // Applies it
    orxAnimPointer_SetTime(pstAnimPointer, fStartTime);
    
    If one could manually change their animations frames to nextFrame() or previousFrame(), then slowing down or speeding up wont be difficult to achieve.

    It's actually even easier as you can simply call orxAnimPointer_SetFrequency() to change the actual speed.
    But I could access keyduration of animations from config, and if they have same keyduration, this would be then easier to do, right ? I have little idea on what things affect animations in orx.

    Yes you can do that, it's a bit cumbersome though and my point is that for what you actually want to achieve you don't need those information at all. :)
  • jimjim
    edited September 2013
    Oh, haha, yeah its actually simpler than I thought.
    One more thing, for example I have an animation with total duration of 1 sec, and it has 10 frames, so .1 for each, if I set .15 as start time, which frame would it play first ? at .1, 2nd frame would start, at .2 ,3rd frame would start. So, what about .15 ?
  • edited September 2013
    Well, I do think you already answered your own question. ;)
    [0 ... 0.1 ... 0.2 ... 0.3 ... 0.4 ....
     ^      ^       ^       ^       ^
     |      |   |   |       |       |
    1st    2nd  |  3rd     4th     5th ....
                |
                V
    
    At 0.15, still on 2nd frame for 0.05s before switching to the 3rd one.
  • jimjim
    edited September 2013
    Hehe, yeah you are right, how could I miss that one :p
Sign In or Register to comment.