HTML5 Canvas 2D Context - 如何重置下一个绘图操作的样式?

时间:2014-08-07 20:53:06

标签: javascript html5 canvas

所以,我有一个可爱的小画布背景:

var canvas    = document.createElement('canvas');
canvas.width  = 800;
canvas.height = 400;

var context = canvas.getContext('2d');

我画了一行文字,带有阴影:

context.textAlign = "center";
context.font      = "bold 20px sans-serif";
context.fillStyle = "#F90";

context.shadowColor   = "black";
context.shadowBlur    = 2;
context.shadowOffsetX = 2;
context.shadowOffsetY = 2;

context.fillText("Chivalry", canvas.width/2, 124);

稍后,我继续画其他内容:

context.textAlign = "center";
context.font      = "bold 16px sans-serif";
context.fillStyle = "white";

context.fillText("Medieval Warfare", canvas.width/2, 144);

但我不希望最后一个有阴影。当然,上下文的阴影样式属性从未重置,因此阴影应用于所有其他图形。

我应该如何恢复上下文的默认值?

0 个答案:

没有答案