从 tween.js 中提取补间值
如果我有一个运行时间为 2000 毫秒的补间,并且我想在 1000 毫秒时提取补间值,我将如何执行此操作? 正在使用 Tween.js @ http://github.com/sole/tween.js
var position = {y: 0};
t = new TWEEN.Tween(position)
.to({ y: 300 })
.onUpdate( function() {
console.log(position.y);
});
t.start(); // correctly runs the tween and logs tweened position.y values
我现在 据我所知,我应该能够 .update(tValue) 并让它在给定的 tValue onUpdate 处记录正确的补间值。相反,position.y 仅输出起始位置值。
Github 页面的第一个常见问题解答问题暗示了这种能力,但我似乎无法让它发挥作用。
谢谢!
If i had a tween with a running duration of 2000ms and i wanted to extract the tweened value at 1000ms, how would i go about doing this? I am using Tween.js @ http://github.com/sole/tween.js
var position = {y: 0};
t = new TWEEN.Tween(position)
.to({ y: 300 })
.onUpdate( function() {
console.log(position.y);
});
t.start(); // correctly runs the tween and logs tweened position.y values
now, from what i can gather, i should be able to to .update(tValue) and have it log the correct tweened value at the given tValue onUpdate. Instead, position.y only outputs the starting position value.
The first FAQ question of the Github page hints of this ability, but i can't seem to get it to work.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
快速浏览一下 tween.js 源就会发现它保留了所有的 补间
Tween.Easing
“命名空间”中的函数,默认缓动函数为TWEEN.Easing.Linear.EaseNone
。它的缓动函数与我的预期略有不同,但一旦您知道自己想要做什么,就可以独立于架构的其余部分轻松使用。
类似的东西应该有效。
我只记得不久前我也有一个相关的答案,更多地讨论了 easing 的“理论” /补间函数(如果您有兴趣)。
A quick look at the tween.js source reveals that it keeps all of its tweening functions in a
Tween.Easing
"namespace", and the default easing function isTWEEN.Easing.Linear.EaseNone
.Its easing functions are a little different than what I was expecting, but are pretty easy to use independent of the rest of the architecture, once you know what you want to do.
Something like that should work.
I just remembered I also had a related answer a while ago that talks more about the "theory" of easing/tweening functions if you are interested.
只需使用
setTimeout()
并让计时器在1000 毫秒
后运行:Just use
setTimeout()
and make a timer run after1000 ms
: