libgdx actions 和Interpolation分析

来源:互联网 发布:浙江水利工程造价软件 编辑:程序博客网 时间:2024/05/20 18:55
这节来分析actions和Interpolation,这两个基本算是并存的去辅助actor来完成复杂的轨迹。actions来作用actor来实现actor的动作,比如向左移动,旋转360度或者平移且旋转。
Interpolation的作用是操作actions,是加在动作之上的,比如一个动作为1s从0.0坐标移动到100.100坐标。那么动作执行会是一个匀速轨迹,但是有时我们需要的是加速运动或者减速或者更复杂的运动方式,此时我们就需要Interpolation来对匀速进行影响,实现快速奔跑,缓冲轨迹或者其他行为。
之间的关系为:
actor.addaction
action.setInterpolation


我们从MoveToAction动作里面来看看Interpolation如何影响动作的:
继承TemporalAction,查看act接口:
if (!began) {
begin();
began = true;
}
time += delta;
complete = time >= duration;
float percent;
if (complete)
percent = 1;
else {
percent = time / duration;
if (interpolation != null) percent = interpolation.apply(percent);
}
update(reverse ? 1 - percent : percent);
if (complete) end();
return complete;


我们看到时间计算为percent = time / duration;算出时间百分比,然后如果有interpolation,则对计算值重新计算percent = interpolation.apply(percent),然后更新位置。
interpolation 叫什么呢?叫插值,因此便是两点间进行对默认的线性轨迹进行作用,来影响最终的actor的运动速率,这个就是这三个的关系。
Interpolation.java里面有一些常用的插值算法,我们可以直接使用,再者gdx的测试代码里面,是实现了这里的这些效果的,可以去看看。
这节算是分析完了,我也是用着看着,瞎写着,希望能帮到一些人吧。
0 0
原创粉丝点击