Laya3D动画倒放后会循环播放的问题
问题详情:在animator.speed设置为负数(即反向播放时),动画会循环播放
类库版本:2.6.1
解决方法:修改bin/laya.d3.js文件,找到_updatePlayer方法
_updatePlayer(animatorState, playState, elapsedTime, islooping) {
var clipDuration = animatorState._clip._duration * (animatorState.clipEnd - animatorState.clipStart);
var lastElapsedTime = playState._elapsedTime;
var elapsedPlaybackTime = lastElapsedTime + elapsedTime;
playState._lastElapsedTime = lastElapsedTime;
playState._elapsedTime = elapsedPlaybackTime;
var normalizedTime = elapsedPlaybackTime / clipDuration;
playState._normalizedTime = normalizedTime;
var playTime = normalizedTime % 1.0;
playState._normalizedPlayTime = playTime < 0 ? playTime + 1.0 : playTime;
playState._duration = clipDuration;
var scripts = animatorState._scripts;
// 修改后代码 [修复动画倒放后会循环播放的bug 2021年3月11日14:05:02]
if(!islooping){
if(elapsedPlaybackTime>0){
if(elapsedPlaybackTime >= clipDuration){
playState._elapsedTime = clipDuration;
playState._normalizedPlayTime = 1.0;
}
}else{
playState._elapsedTime = 0;
playState._normalizedPlayTime = 0.0;
}
if (scripts) {
for (var i = 0, n = scripts.length; i < n; i++)
scripts[i].onStateExit();
}
return;
}
//以下是原代码
/* if ((!islooping && elapsedPlaybackTime >= clipDuration)) {
playState._finish = true;
playState._elapsedTime = clipDuration;
playState._normalizedPlayTime = 1.0;
if (scripts) {
for (var i = 0, n = scripts.length; i < n; i++)
scripts[i].onStateExit();
}
return;
} */
if (scripts) {
for (i = 0, n = scripts.length; i < n; i++)
scripts[i].onStateUpdate();
}
}