所以,我有一个可爱的小画布背景:
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);
但我不希望最后一个有阴影。当然,上下文的阴影样式属性从未重置,因此阴影应用于所有其他图形。