Skip to content

Instantly share code, notes, and snippets.

@mohayonao
Created April 17, 2013 00:47
Show Gist options
  • Save mohayonao/5400895 to your computer and use it in GitHub Desktop.
Save mohayonao/5400895 to your computer and use it in GitHub Desktop.
アニメーション処理の便利なやつ
animate = (opts)->
func = arguments[arguments.length-1]
ifps = 1000 / (opts.fps ? 60)
prev = 0
_animate = (now)->
dt = now - prev
if dt > ifps
result = func now, dt
prev = now
if result != false
requestAnimationFrame _animate
requestAnimationFrame _animate
animate fps:40, (now, dt)->
# fps が指定できる。省略すると 60
# dt には前回からの経過時間が入っている
# return false で終了
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment