Skip to content

Commit

Permalink
Add precise animation loop
Browse files Browse the repository at this point in the history
  • Loading branch information
koenbok committed Sep 30, 2014
1 parent e81fc33 commit de60b1b
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions framer/AnimationLoop.coffee
Expand Up @@ -5,25 +5,34 @@ Utils = require "./Utils"
{Config} = require "./Config"
{EventEmitter} = require "./EventEmitter"

if window.performance
getTime = -> window.performance.now()
else
getTime = -> Date.now()


class exports.AnimationLoop extends EventEmitter

constructor: ->
@_delta = 1/60

start: =>

animationLoop = @

_timestamp = null
_timestamp = getTime()


tick = (timestamp) ->

window.requestAnimationFrame(tick)

# if _timestamp
# delta = (timestamp - _timestamp) / 1000
# else
# delta = 1/60

delta = 1/60
if animationLoop._delta
delta = animationLoop._delta
else
timestamp = getTime()
delta = (timestamp - _timestamp) / 1000
_timestamp = timestamp

animationLoop.emit("update", delta)
animationLoop.emit("render", delta)
Expand Down

0 comments on commit de60b1b

Please sign in to comment.