I'm trying to edit union draw
I want to store the state of the canvas, so if a new visitor comes in, he will see the state of the last drawn stuff. currently the canvas clears everything for the new visitor.
what do I have to do with union draw to store the state of the canvas?
Is it possible with something like this? If yes, how?
var states = [];
function saveState(ctx){
var c = document.createElement('canvas');
c.width = ctx.canvas.width;
c.height = ctx.canvas.height;
c.getContext('2d').drawImage(ctx.canvas,0,0);
states.push(c);
return c;
}
function restoreState(ctx,idx){
var off = idx==null ? states.pop() : states[idx];
ctx.drawImage(off,0,0);
}