Advertisement
Serafim

Untitled

Feb 24th, 2014
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Canvas
  2.   constructor: (w, h) ->
  3.     @cnv = document.createElement 'canvas'
  4.     @cnv.width  = w
  5.     @cnv.height = h
  6.     @ctx = @cnv.getContext '2d'
  7.    
  8.     @drawLayers = []
  9.     @running    = false
  10.  
  11.  
  12.   start: ->
  13.     @running = true
  14.     render = =>
  15.       if @running
  16.         requestAnimationFrame =>
  17.           i(@cnv) for i in @drawLayers
  18.           @render()
  19.  
  20.   stop: -> @running = false
  21.  
  22.  
  23.   addLayer: (cb) ->
  24.     @drawLayers.push cb
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement