canvas html5 drawing into context -


Can I attract everything in one context and then add canvas later? For example, I want to create 10 references and then I want to draw them one by one in the canvas

It's an interesting idea, but no, you can not do this, you can not create a new context independent of a canvas, nor can you assign any reference to a canvas.

What you can do dynamically create 10 canvas (you do not need to add them to the document, so they will not be visible) and then swap a canvas for another when you need it . For example:

  var canvas = document.getElementsByTagName ('canvas') [0]; Var frame = []; {Var c = frames [i] = document.createElement ('canvas') for (Var i = 0; i & lt; 10; ++ i); C.width = canvas.width; C.height = canvas.height; Var ctx = c.getContext ('2d'); // draw what you want here} var frame = 0; Through the canvas 15 fps set interval (function () {var c = frames [++ frame% frames.length]; canvas.parentNode.replaceChild (c, canvas); canvas = c;}, 1000/15);    

Comments