javascript - Drawing with request animation framemaximum callstack exceeded? -


i making own little canvas library because have time kill , trying animate canvas objects, method looks so;

proto.update = function () {       (var = 0; < this.objects.length; ++i) {          this.objects[i].draw(this.context);     }      var self = this;      requestanimationframe(self.update()); }; 

i have not use requestanimationframe before , error saying maximum callstack exceeded.

i followed tutorial http://creativejs.com/resources/requestanimationframe/ , quite sure have made no mistakes.

what did wrong?

the callback parameter passed requestanimationframe should reference function call when it's time next repaint (see documentation here). error have included parenthesis after function name means executes causing recursive loop.

try updating code follows:

proto.update = function () {       (var = 0; < this.objects.length; ++i) {          this.objects[i].draw(this.context);     }      var self = this;      // pass function reference don't call     requestanimationframe(self.update); }; 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -