Hello Guest

Author Topic: tk2dAnimatedSprite.getFrame() function  (Read 8194 times)

LBandy

  • Newbie
  • *
  • Posts: 2
    • View Profile
tk2dAnimatedSprite.getFrame() function
« on: June 29, 2012, 03:03:11 pm »
Hi there!

Thank you very much for this great plugin. However, I would like to know if there is a possibility to get the frame id which is currently playing? We need to synchronize multiple animation together, and knowing the actual frame in the animation is essential for this. I hope there would be a simple workaround for this.

Thank you for your help!

mike2d

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 63
    • View Profile
Re: tk2dAnimatedSprite.getFrame() function
« Reply #1 on: June 29, 2012, 06:25:00 pm »
yup, i'd be interested in this one too :)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dAnimatedSprite.getFrame() function
« Reply #2 on: June 29, 2012, 08:55:11 pm »
frame = (int)(anim.ClipTimeSeconds * anim.CurrentClip.fps);

That should do it.

mike2d

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 63
    • View Profile
Re: tk2dAnimatedSprite.getFrame() function
« Reply #3 on: July 03, 2012, 07:59:06 pm »
 ;D

nice, i'll test that.

LBandy

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: tk2dAnimatedSprite.getFrame() function
« Reply #4 on: July 04, 2012, 12:37:32 pm »
frame = (int)(anim.ClipTimeSeconds * anim.CurrentClip.fps);

That should do it.

Thanks for the advice. Is there a way to be able to sync the animation in a more precise way? Because if I use this solution, at a given 24 fps framerate the delay is noticable.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dAnimatedSprite.getFrame() function
« Reply #5 on: July 04, 2012, 12:54:06 pm »
If you want to sync animations, you'll be better off syncing clipTimes, as frameIds are rounded down integers.

Get the ClipTimeSeconds from the source sprite, and then when calling Play on the second clip, use Play(id, otherClipTimeSeconds);

DannyB

  • 2D Toolkit
  • Hero Member
  • *
  • Posts: 609
    • View Profile
    • Chicks Ahead
Re: tk2dAnimatedSprite.getFrame() function
« Reply #6 on: September 10, 2012, 05:24:03 pm »
Thanks for this. The time sync works perffectly.