Hello Guest

Author Topic: tk2dSpriteAnimator.CurrentFrame lag  (Read 3686 times)

Trigve

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 30
    • View Profile
tk2dSpriteAnimator.CurrentFrame lag
« on: November 04, 2014, 10:39:24 pm »
Hi,
I'm trying to move the sprite on each frame change using coroutines. I'm comparing the current and the last frame of the tk2dSpriteAnimator. But the "CurrentFrame" property is lagging the 1 frame after the actual sprite has been already changed (that is, I can see that the sprite has been changed, either visually or in game object inspector, but the value in the code is still the old one). Is this known behaviour or am I doing something wrong?

Thanks

Trigve

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: tk2dSpriteAnimator.CurrentFrame lag
« Reply #1 on: November 04, 2014, 10:49:10 pm »
Ahh Nevermind, using the WaitForEndOfFrame in coroutine yield solved it. But then I'm animating the 1 frame late. I think I could solve it partially with the script execution order. But it would be great if I could connect to some frame-changed event (edit: but this would only work if the animation would be updated in the Update() method (?)).

edit: Anyway, why the tk2dSpriteAnimator is updated in LateUpdate() and not in Update()?
« Last Edit: November 05, 2014, 07:23:34 am by Trigve »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dSpriteAnimator.CurrentFrame lag
« Reply #2 on: November 05, 2014, 11:51:42 am »
tk2dSpriteAnimator is in LateUpdate because the likelihood is you're gonna be updating based on input input in FixedUpdate / Update.
You have source, you can change it to whatever you like there.

There is a SpriteChanged event in tk2dBaseSprite you can subscribe to, that will be called immediately when a sprite is changed.