1
I was trying to understand the workings of the methods save
and restore
of canvas
and I looked on the page of MDN.
I still don’t understand what the difference is between using them or not.
According to the documentation, the save
"saves a default state" and the restore
"restores this state later".
But I still can’t understand what the use of them did in this example given there in the documentation:
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
ctx.save(); // save the default state
ctx.fillStyle = 'green';
ctx.fillRect(10, 10, 100, 100);
ctx.restore(); // restore to the default state
ctx.fillRect(150, 75, 100, 100);
<canvas id="canvas"></canvas>
What is the purpose of the method restore
and save
?
How this state works?
Back to the previous state, "black pen".
– Bacco
@Bacco nooooooooooooooooooooooooooooooosa, I didn’t even touch, man! kkkkkkkk
– Wallace Maxters