Created
April 17, 2013 00:47
-
-
Save mohayonao/5400895 to your computer and use it in GitHub Desktop.
アニメーション処理の便利なやつ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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