Skip to content
Permalink
Browse files

Add precise animation loop

  • Loading branch information...
koenbok committed Sep 30, 2014
1 parent e81fc33 commit de60b1b9b37c0abdd2c6c60488c3afc40e3ef263
Showing with 16 additions and 7 deletions.
  1. +16 −7 framer/AnimationLoop.coffee
@@ -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)

0 comments on commit de60b1b

Please sign in to comment.
You can’t perform that action at this time.