How do I make a transparent canvas in html5?

前端 未结 6 1539
执笔经年
执笔经年 2020-11-27 13:35

How can I make a canvas transparent? I need to because I want to put two canvases on top of one another.

6条回答
  •  时光说笑
    2020-11-27 13:55

    I believe you are trying to do exactly what I just tried to do: I want two stacked canvases... the bottom one has a static image and the top one contains animated sprites. Because of the animation, you need to clear the background of the top layer to transparent at the start of rendering every new frame. I finally found the answer: it's not using globalAlpha, and it's not using a rgba() color. The simple, effective answer is:

    context.clearRect(0,0,width,height);
    

提交回复
热议问题