Hello Guest

Author Topic: Change Anim Framerate dynamically  (Read 3885 times)

fryza

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 22
    • View Profile
Change Anim Framerate dynamically
« on: May 06, 2013, 09:33:15 pm »
How do I change the frame rate of an anim programmatically?

I am currently using this code - but it is producing undesirable results (playing way faster than it should):

Code: [Select]
Track.CurrentClip.fps = 50;
Track.Play();

What I am trying to do is increase the speed for each level. It is a light that spins around and you try and stop it on the jackpot.

What I want it to do is increase: 38,39,40, etc

The speed DOES increase, but the results aren't steady and it plays much too fast. I have compared the speeds that play when I set this through the editor vs at runtime and the two speeds are not the same. Thoughts?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Change Anim Framerate dynamically
« Reply #1 on: May 06, 2013, 10:35:54 pm »
You can set the fps by doing this:
Track.Play( clip, 0, 30 ); // third parameter is override fps
and clip is the tk2dSpriteAnimationClip your're dealing with.

If you increase by a number that doesn't divide properly by your framerate, you are undoubtedly going to end up with jerky frames. You should enable vsync, and only ever change by a multiple that works with your framerate.

Eg. if your game framerate = 50 and your animation is 51fps, it will HAVE to drop a frame somewhere for it to play properly.