在 Lua 中补间一个值
这件事我该怎么办? 我想在 x 时间内将一个值从一个值补间为另一个值。 同时还要考虑到在开始和结束时有一个“轻松”的感觉会很好。
我知道,我真的不应该问,但我自己试过了,但我被困住了。 请假设要引起延迟,您需要调用函数 wait(time)。
How'd I go about this one? I want to tween a value from one to another in x time. While also taking into account that it'd be nice to have an 'ease' at the start and end.
I know, I shouldn't ask really, but I've tried myself, and I'm stuck.
Please assume that to cause a delay, you need to call function wait(time).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种可能适合您的简单方法是沿着单位圆进行插值:
为此,您只需评估沿圆的点,这确保了相当平滑的运动以及缓入和缓出。 您可以通过更改改变角度的速度来控制插值的速度。
假设您正在进行一维插值(即简单的标量插值,例如从 3.5 到 6.9 或其他),使用从 -π/2 到 π/2 的 Y 值可能会很方便。 这些是由正弦函数给出的,你需要做的就是应用合适的缩放:
我不能 100% 确定这是否是合法的 Lua,没有测试它。 如果没有,转换可能很简单。
One simple approach that might work for you is to interpolate along the unit circle:
To do this, you simply evaluate points along the circle, which ensures a fairly smooth movement, and ease-in as well as ease-out. You can control the speed of the interpolation by changing how quickly you alter the angle.
Assuming you're doing 1-dimensional interpolation (i.e. a simple scalar interpolation, like from 3.5 to 6.9 or whatever), it might be handy to use Y-values from -π/2 to π/2. These are given by the sine function, all you need to do is apply suitable scaling:
I'm not 100% sure if this is legal Lua, didn't test it. If not, it's probably trivial to convert.
您可以查看Tweener ActionScript 库来获取灵感。
例如,您可以借用必要的方程 从这里开始。
如果您需要进一步的帮助,请询问。
You may look at Tweener ActionScript library for inspiration.
For instance, you may borrow necessary equations from here.
If you need further help, please ask.