有引用問題和更新問題。 我對你的代碼做了一些修改。這不是一個解決方案,你可以單獨使用每個更改。 最好的解決方案是將每個補間製作爲一個函數內的var,在補間對象中進行計數並使用onUpdate(function(){if(this.counter> 1000){tween.stop}})(INTERSECTED.material.color)因爲你創建了很多未引用的定時器和補間,這將是一個性能問題。
function animate() {
//
TWEEN.update();
//
}
if (intersects.length > 0) {
if (INTERSECTED != intersects[0].object) {
if (INTERSECTED) INTERSECTED.material.color.setHex(INTERSECTED.currentHex);
INTERSECTED = intersects[0].object;
INTERSECTED.currentHex = INTERSECTED.material.color.getHex();
//INTERSECTED.material.emissive.setHex(0xff0000);
TWEEN.remove(tween);
tween = new TWEEN.Tween(INTERSECTED.material.color).onStart(function(){
setTimeout(function(){ tween.stop() }, 1000); ///not good
}).start();
.to({r: 0, g: 25, b: 155}, 10000) /// here set correct time
.easing(TWEEN.Easing.Quartic.In)
.start();
setTimeout(function(){ tween.stop() }, 1000);/// will not work if you create anoter it that one second
}
else {
if(tween) tween.update(time); // bad
}
}
你是否開始你的補間?我在animate()中看不到補間更新函數。 您也可以在控制檯中調用TWEEN.getAll()來檢查您的補間是否正常工作。 – Martin
在我的項目中,animate()函數中有'tween.update(time)'。在jsfiddle中它顯然是在第144行。我嘗試使用'console.log(TWEEN.getAll())'。在我調用'tween.stop()'後,我的控制檯輸出'[]',所以我猜停止了補間,但動畫(=改變顏色)繼續。 – binoculars
動畫可能是除補間之外的其他動作的結果嗎? – Martin