[LayaAir 2.0]关于Laya.Tween 在3d上的应用与缓动的优化
Laya.Tween.to()可应用于引用对象中的数值变化,废话不多说直接上代码
//这里以origin为例,将origin的值变化为target的值,可以对应成3d对象中的vector3
let origin: any = {x:1,y:2,z:3};
let target: any = {x:5,y:8,z:8};
Laya.Tween.to(origin,target,500).update = new Laya.Handler(null,()=>{
console.log(origin);
//如果想对3d对象缓动,可以在此对3d对象进行赋值
// 如下
/**
sp3d.transform.localPosition = origin;
sp3d.transform.localRotationEuler = origin;
sp3d.transform.localScale = origin;
*/
})
同样利用update可以将多个tween转换成一个tween
例如同时tween 对象sp1,sp2
Laya.Tween.to(sp1,{x:100,y:200},500);
Laya.Tween.to(sp2,{x:300,y:400,alpha:0.5},500);
与下面的效果是一样的
let origin: any = {x1:sp1.x,y1:sp1.y,x2:sp2.x,y2:sp2.y,alpha2:sp2.alpha};
let target: any = {x1:100,y1:200,x2:300,y2:400,alpha2:0.5};
Laya.Tween.to(origin,target,500).update = new Laya.Handler(null,()=>{
sp1.x = origin.x1;
sp1.y = origin.y1;
sp2.x = origin.x2;
sp2.y = origin.y2;
sp2.alpha = origin.alpha2
})
//这里以origin为例,将origin的值变化为target的值,可以对应成3d对象中的vector3
let origin: any = {x:1,y:2,z:3};
let target: any = {x:5,y:8,z:8};
Laya.Tween.to(origin,target,500).update = new Laya.Handler(null,()=>{
console.log(origin);
//如果想对3d对象缓动,可以在此对3d对象进行赋值
// 如下
/**
sp3d.transform.localPosition = origin;
sp3d.transform.localRotationEuler = origin;
sp3d.transform.localScale = origin;
*/
})
同样利用update可以将多个tween转换成一个tween
例如同时tween 对象sp1,sp2
Laya.Tween.to(sp1,{x:100,y:200},500);
Laya.Tween.to(sp2,{x:300,y:400,alpha:0.5},500);
与下面的效果是一样的
let origin: any = {x1:sp1.x,y1:sp1.y,x2:sp2.x,y2:sp2.y,alpha2:sp2.alpha};
let target: any = {x1:100,y1:200,x2:300,y2:400,alpha2:0.5};
Laya.Tween.to(origin,target,500).update = new Laya.Handler(null,()=>{
sp1.x = origin.x1;
sp1.y = origin.y1;
sp2.x = origin.x2;
sp2.y = origin.y2;
sp2.alpha = origin.alpha2
})
没有找到相关结果
已邀请:
要回复问题请先登录
1 个回复
kshell
赞同来自: 1661135030用户