Discord
Login
Community
DARK THEME

how to implement "xor" for a canvas drawing

I am working on a 2d top-down project where a character has limited vision because the scene is dark. This character has a light that lets them see a certain radius around him. To create this effect, I was thinking of attaching two drawings (a rectangle to fill the screen and a circle over the player) to the character to create a xor that would become an "opaque fog-of war" or "candlelight" effect.

This option (xor) exists in microScript:
(Under "Documentation" -> "Quick Reference" -> "API Cheatsheet" -> "blending modes")
but I haven't worked with the "blending modes" options yet so don't know how to implement xor or the other blending into the code. How can this be done? If there is a better way of creating this effect, I'd love to hear that too.

https://microstudio.io/i/Loginus/mask/

Keys A - changes graphic mode.

The D key changes the drawing order, from mask first, then image, to image first, then mask.

I recommend two modes for you called "multiply" and "darken". Identical end results, except that you have to switch the drawing order to the opposite of the second mode.

In multiplication mode, you need to set a black tile in TileMap in the places where you want the background to be black, otherwise a light field will appear in that place.

https://microstudio.dev/i/JimB007/spritefunctions2/

Thank you Loginus, this helped a bunch!

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community