mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Prevent delta from becoming infinity or nan when duration is 0
This commit is contained in:
parent
f9711b9043
commit
0ba987159f
1 changed files with 10 additions and 0 deletions
|
@ -31,6 +31,13 @@ public class Lerp {
|
|||
if (MathHelper.approximatelyEquals(end, newTarget)) {
|
||||
return false;
|
||||
}
|
||||
if (changeDuration == 0) {
|
||||
start = newTarget;
|
||||
end = newTarget;
|
||||
finished = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
start = getValue();
|
||||
startTime = Util.getMeasuringTimeMs();
|
||||
end = newTarget;
|
||||
|
@ -66,6 +73,9 @@ public class Lerp {
|
|||
}
|
||||
|
||||
private float getDelta() {
|
||||
if (duration == 0) {
|
||||
return 1;
|
||||
}
|
||||
return MathHelper.clamp((float)(Util.getMeasuringTimeMs() - startTime) / (float)duration, 0, 1);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue