问答详情
源自:8-3 clip和剪辑区域

为什么再画圆形路径的时候不用加save和store,在画星星的时候要加呢

画圆代码:

cxt.beginPath();
cxt.arc(searchlight.x,searchlight.y,searchlight.radius,0,Math.PI*2);
cxt.fillStyle='#fff';
cxt.fill();
cxt.clip();

画星星代码

cxt.save();    
cxt.translate(searchlight.x,searchlight.y);    
cxt.rotate(rot/180*Math.PI);    
cxt.scale(searchlight.radius,searchlight.radius);    
starPath(cxt);    
cxt.fillStyle='#fff';    
cxt.fill();    
cxt.restore();
cxt.clip();

而且,画星星的时候beginPath语句也没了

提问者:dl_嘛哩嘛哩哄 2016-05-18 10:20

个回答

  • 王小仙
    2016-05-21 10:32:06

    因为,,画星星的时候用了translate, rotate 等转换函数,所以要把画布状态保存一下,,避免影响到其他的绘制,,画星星的beginPath在startPath()函数里面,,