class MakeCanvas
constructor : (elemId,width,height,@slideTimeThrottled) ->
@ctx = document.getElementById(elemId).getContext '2d'
@ctx.canvas.width = width
@ctx.canvas.height = height
@ctx.canvas.style.marginTop = (((height / 2) * -1)+(43 / 2))+'px'
@aniInterval = null
clearInterval @aniInterval
@frameNum = 0
drawFrame : ->
console.log 'drawFrame not overwritten'
animate : ->
clearInterval @aniInterval
@frameNum = 0
@aniInterval = setInterval (=>
@ctx.clearRect 0, 0, @ctx.canvas.width, @ctx.canvas.height
@drawFrame()
@frameNum++
@stop() if @frameNum > @slideTimeThrottled
), frameRate
stop : ->
clearInterval @aniInterval
I’m using a coffeescript class to try and automate some basic functions of the canvas. The above code works just fine for the most part, but I would really like to start using requestanimationframe instead of setInterval.
I would like to use the polyfill posted here: https://gist.github.com/1579671
Unfortunately I am just not getting it. How could this class be re-written to function the same and use requestanimationframe instead?
1 Answer