Mia
Mia

Reputation: 6531

Canvas - Multiple Compositing Operations

Is it possible to use multiple compositing for different "things" when they're being drawn?

For instance I want to use lighter for specific kinds of fillRect's, but for the rest i want to keep everything as usual.

Upvotes: 1

Views: 147

Answers (1)

user1693593
user1693593

Reputation:

Sure, composition mode can be changed on the fly before each drawing so you can change to "lighter" for some draw operations, "source-over" for others.

Just be aware of that some comp modes may clear what is already drawn so choose wisely.

ctx.globalCompositeOperation = "lighter";      // lighter mode (blend mode)
ctx.fillRect(x, y, w, h);

ctx.globalCompositeOperation = "source-over";  // normal mode (comp mode)
ctx.fillRect(x, y, w, h);

Upvotes: 2

Related Questions