【发布时间】:2020-08-31 06:17:02
【问题描述】:
我在补间我的 camera.position 时遇到问题。我用最少的代码创建了一个 codepen,只是为了重现我的问题,并注释了我的所有代码。我还放了很多 console.log() 用于调试目的。
起点是我的camera.postion
camera.position.z = 30;
还有我的 tween001
var tween001 = gsap.to(camera.position,{ delay:2,duration:5,z:60,onUpdate:function(){
camera.updateProjectionMatrix();
console.log("play");
},onComplete:function(){console.log("complete");},ease:"elastic"});
所以补间即将把我的相机从 Z = 30 移动到 Z = 60
它工作得很好但是......当用户移动/移动/单击3d时移动相机时,它的火和事件监听器暂停“tween001.pause()”我希望tween001使用“实际”相机.postion 而不是当补间 001 着火时使用的 camera.postion 。
因为当 tween001 再次播放或从暂停中恢复时,使用的起点是默认的 x=0 y=0 z=30 。
一个空闲函数再次播放 tween001
window.setInterval(checkTime, 1000);// every 1 second launch checktime()
function checkTime() { //idleCounter get 1 every second and at 5 second coz timeout is 5 checktime relaunch the tween001
if (idlecounter < timeout) {
idlecounter++;
//console.log("++ ");
} else if (idlecounter == timeout) {
tween001.play();
console.log('timeout');
}
}
【问题讨论】:
-
对不起我的英语(顺便说一句我是法国人^^)
-
我能看到的最简单的解决方案是每次你想触发它时创建一个新的补间,而不是在开始时创建一个补间并播放它。
-
GreenSock 论坛上的相同问题:greensock.com/forums/topic/25358-threejs-and-gsap-tween-update
标签: javascript three.js gsap tween