Skip to content

Commit c69ec99

Browse files
committed
Put a limit of animation timer delta time in example code
1 parent 6d54802 commit c69ec99

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

js/example-frontend-js/src/main/kotlin/ExampleMain.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private fun HTMLElement.setPosition(x: Double, y: Double) {
4747
}
4848

4949
@Suppress("DEPRECATION")
50-
fun random() = kotlin.js.Math.random()
50+
private fun random() = kotlin.js.Math.random()
5151

5252
class Application {
5353
private val body get() = document.body!!
@@ -140,7 +140,6 @@ class Application {
140140
println("Delayed #$index for a while at ${timer.time}, resumed and turned")
141141
}
142142
}
143-
144143
}
145144
}
146145

@@ -190,7 +189,7 @@ class AnimationTimer {
190189
val newTime = window.awaitAnimationFrame()
191190
val dt = newTime - time
192191
time = newTime
193-
return dt
192+
return dt.coerceAtMost(500.0) // at most half a second
194193
}
195194

196195
fun reset(): Double {

0 commit comments

Comments
 (0)