jeremyckahn/shifty

Delay

Closed this issue · 6 comments

Hi, is there a possibility to define a delay in ms before starting a tween?
I'm aware that it's easy to make it with a timer, but a native shifty feature would be more smart.

Kris

Hi Kris,

Thanks for your suggestion. There currently is no delay API, but I agree that it would be a good addition. Is this something you would like to put together a Pull Request for? I'd be happy to work with you on it.

After a quick review of your code, maybe the delay could be implemented in the tween() function?
This would certainly anwser my simple needs...
And what about pause/resume: should this be possible during the delay duration?
I need some help for the implementation... ;-)

Yes, I think that tween is the right place to set up the delay. You raise a great point about pause/resume affecting the delay, and accounting for that would add a fair amount of complexity to the code. I'd be fine with a simple implementation that doesn't take pause/resume into account just to get you going. I'll need some time to review the code and figure out how the rest of this might be implemented — perhaps I can get to it this weekend?

In the meantime, if you want to take a stab at a basic implementation, you can make a PR and we can leave this open until pause/resume is handled. Just leave a TODO to manage playback control and it'll get addressed once I have some time.

Okie dokie, I've implemented a delay API. @Kris-B, can you pull down my feature/delay branch and give it a try to see if it works for you? All you need to do is pass a number as a delay config parameter to tween:

var tweenable = new Tweenable();
tweenable.tween({
  from: { x: 0 },
  10: { x: 10 },
  delay: 5000,
  duration: 1000
});

Hi Jeremy, and sorry for this very late reply.
You were faster than me for the implementation... ;-)
I made some tests with the feature/delay branch, and it works like a charm.
Many thanks!

Thanks for checking it out! I've merge feature/delay to master and tagged it as 1.4.0.