javascript - About canvas rotation
女神的闺蜜爱上我
女神的闺蜜爱上我 2017-06-28 09:28:14
0
1
718
$("#bt-lottery").one("click",function(){ var reg=1; setInterval(function(){ ctx.save(); ctx.translate(249.5,249.5);//将原点移动到画布中心 ctx.rotate(reg*Math.PI/180); ctx.clearRect(-pin.width/2,-pin.height/2,pin.width,pin.height); ctx.drawImage(pin,-pin.width/2,-pin.height/2); ctx.restore(); reg++; },5); });

I want to realize the function of the pointer (pin.png) rotating on the turntable (pan.png), but if ctx.clearRect(); will appearAs shown in the figure; The result I want is, how to achieve it? ? Ask for advice

女神的闺蜜爱上我
女神的闺蜜爱上我

reply all (1)
Ty80

Due to insufficient information, I can only give my judgment.

  1. png is not transparent, the probability is very small

  2. You are divided into two canvases, but the canvas with the pointer has a background color, the probability is also very small

  3. Code problem:

setInterval(function(){ ctx.clearRect(0,0,canvas.width,canvas.height); //这里你需要绘制背景图片(转盘),或者将转盘作为离屏canvas分离出去(因为转盘不会变动),只绘制指针。 ---我猜你缺少了这一步。。 ctx.save(); ctx.translate(249.5,249.5);//将原点移动到画布中心 //ctx.clearRect(-pin.width/2,-pin.height/2,pin.width,pin.height);至于为什么清理出来的区域是个圆形跟你代码执行的顺序有关,先旋转后清理和先清理后旋转是不一样的。 ctx.rotate(reg*Math.PI/180); ctx.drawImage(pin,-pin.width/2,-pin.height/2); ctx.restore(); reg++; },5);
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!