I'm working on some particle animations for my game engine, and I want to know if is possible to change the hue, gamma and other image properties of a ImageElement object of the canvas, keeping the shape of the image.
What I've tried so far is this:
_ctx.save();
_ctx.setStrokeColorHsl(240, 100, 50);
_ctx.fillRect(c.x, c.y, width, height);
_ctx.globalAlpha = nAlpha; //Modify the transparency
_ctx.drawImageScaled(p, c.x, c.y, width, height);
_ctx.restore();
Which works but it is applying the tone to the entire piece of image, which means if the image is a PNG with transparent edges it'll paint even the transparent parts because it uses a "fillRect()" (which paints rectangles only) to apply the transformation and the image object.
The result is this: (the red particles are semi-transparent circles)
Is there any other way to tint the an image shape only or to modify the object directly so the transformation only apply to the visible part of the image?