As of Elm 0.17, this package has been replaced with elm-lang/animation-frame, which provides an animation frame subscription in place of this package's animation frame signal.
This library provides time Signals that are synchronized to the monitor's frame rate, by binding javascript's requestAnimationFrame. Using AnimationFrame.frame
or AnimationFrame.frameWhen
instead of (Time.fps 60)
or (Time.fpsWhen 60)
makes it possible (but not guaranteed...) to achieve 60 fps animation without stutter in Elm.
import AnimationFrame
import Graphics.Element
import Signal
main = Signal.map Graphics.Element.show (Signal.foldp (+) 0 AnimationFrame.frame)
See examples/counter.elm
for a minimal working example that uses both AnimationFrame.frame
and AnimationFrame.frameWhen
. You can see this example in action here. The top counter uses AnimationFrame.frame
to count continuously. The bottom counter uses AnimationFrame.frameWhen
to count only when the mouse is down.
The following simple animation demonstrates the performance difference between using core's Time.fps
, and AnimationFrame.frame