I am trying to create a platform in Canvas. I have a main character and some enemies. When a player touches an enemy, he will lose some HP, and he will be untouchable for about 3 seconds. Now I have one problem. After losing HP, I want to set the opacity of the character image to 0.5 (to show this untouchable thing).
var mainchar = new Image(); mainchar.src = 'mainch.png';
I do not want to use ctx.globalCompositeOperation = "lighter" or ctx.globalAlpha = 0.5 , because both of them change the opacity of all elements (this is global). Is there a way to change the transparency of the image? For example, "mainchar.changeopacity"?
source share