A piece of code:
ctx.clearRect(0, 0, canvas.width, canvas.height); ctx.drawImage(level1, 0, 0); ctx.save(); ctx.fillRect(0,0,mask.width,mask.height); ctx.globalCompositeOperation="source-in"; ctx.drawImage(hero,0,0); ctx.restore(); Trying to make a mask for the hero. But it turns out such a glitch.
The structure is as follows:
1) Layer backgorund written in css (we see it).
2) Backgorund level in html5 canvas there forests, grass underfoot (not displayed).
3) Mask for Hero.
4) Hero itself.
Waiting: grass with background and cut out hero.
Reality: the mask works, but cuts backgorund of canvas.
It looks like ctx.globalCompositeOperation = "source-in"; applies to the whole context, not to the added layers. Can you please tell me how to fix it? Maybe you need to draw it all in a separate context?
